Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Commit

Permalink
Update date filter format to datetime (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotbonneville authored Apr 27, 2022
1 parent 0215a09 commit 723067f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
16 changes: 5 additions & 11 deletions clients/admin-ui/src/features/privacy-requests/RequestFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,15 @@ const useRequestFilters = () => {
const token = useSelector(selectUserToken);
const dispatch = useDispatch();
const toast = useToast();
const handleSearchChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const handleSearchChange = (event: React.ChangeEvent<HTMLInputElement>) =>
dispatch(setRequestId(event.target.value));
};
const handleStatusChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
const handleStatusChange = (event: React.ChangeEvent<HTMLSelectElement>) =>
dispatch(setRequestStatus(event.target.value as PrivacyRequestStatus));
};
const handleFromChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const handleFromChange = (event: React.ChangeEvent<HTMLInputElement>) =>
dispatch(setRequestFrom(event?.target.value));
};
const handleToChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const handleToChange = (event: React.ChangeEvent<HTMLInputElement>) =>
dispatch(setRequestTo(event?.target.value));
};
const handleClearAllFilters = () => {
dispatch(clearAllFilters());
};
const handleClearAllFilters = () => dispatch(clearAllFilters());
const handleDownloadClick = async () => {
let message;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,29 @@ export const mapFiltersToSearchParams = ({
to,
page,
size,
}: Partial<PrivacyRequestParams>) => ({
include_identities: 'true',
...(status ? { status } : {}),
...(id ? { id } : {}),
...(from ? { created_gt: from } : {}),
...(to ? { created_lt: to } : {}),
...(page ? { page: `${page}` } : {}),
...(typeof size !== 'undefined' ? { size: `${size}` } : {}),
});
}: Partial<PrivacyRequestParams>) => {
let fromISO;
if (from) {
fromISO = new Date(from);
fromISO.setUTCHours(0, 0, 0);
}

let toISO;
if (to) {
toISO = new Date(to);
toISO.setUTCHours(23, 59, 59);
}

return {
include_identities: 'true',
...(status ? { status } : {}),
...(id ? { id } : {}),
...(fromISO ? { created_gt: fromISO.toISOString() } : {}),
...(toISO ? { created_lt: toISO.toISOString() } : {}),
...(page ? { page: `${page}` } : {}),
...(typeof size !== 'undefined' ? { size: `${size}` } : {}),
};
};

// Subject requests API
export const privacyRequestApi = createApi({
Expand Down

0 comments on commit 723067f

Please sign in to comment.