From 723067fdc67bd7b0868cffc025edfbc7d3320bf0 Mon Sep 17 00:00:00 2001 From: Elliot Bonneville Date: Wed, 27 Apr 2022 18:33:59 -0400 Subject: [PATCH] Update date filter format to datetime (#406) --- .../privacy-requests/RequestFilters.tsx | 16 +++------- .../privacy-requests.slice.ts | 32 +++++++++++++------ 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/clients/admin-ui/src/features/privacy-requests/RequestFilters.tsx b/clients/admin-ui/src/features/privacy-requests/RequestFilters.tsx index 596fa342f..7a44a91c7 100644 --- a/clients/admin-ui/src/features/privacy-requests/RequestFilters.tsx +++ b/clients/admin-ui/src/features/privacy-requests/RequestFilters.tsx @@ -38,21 +38,15 @@ const useRequestFilters = () => { const token = useSelector(selectUserToken); const dispatch = useDispatch(); const toast = useToast(); - const handleSearchChange = (event: React.ChangeEvent) => { + const handleSearchChange = (event: React.ChangeEvent) => dispatch(setRequestId(event.target.value)); - }; - const handleStatusChange = (event: React.ChangeEvent) => { + const handleStatusChange = (event: React.ChangeEvent) => dispatch(setRequestStatus(event.target.value as PrivacyRequestStatus)); - }; - const handleFromChange = (event: React.ChangeEvent) => { + const handleFromChange = (event: React.ChangeEvent) => dispatch(setRequestFrom(event?.target.value)); - }; - const handleToChange = (event: React.ChangeEvent) => { + const handleToChange = (event: React.ChangeEvent) => dispatch(setRequestTo(event?.target.value)); - }; - const handleClearAllFilters = () => { - dispatch(clearAllFilters()); - }; + const handleClearAllFilters = () => dispatch(clearAllFilters()); const handleDownloadClick = async () => { let message; try { diff --git a/clients/admin-ui/src/features/privacy-requests/privacy-requests.slice.ts b/clients/admin-ui/src/features/privacy-requests/privacy-requests.slice.ts index 879eaeafd..e920e572f 100644 --- a/clients/admin-ui/src/features/privacy-requests/privacy-requests.slice.ts +++ b/clients/admin-ui/src/features/privacy-requests/privacy-requests.slice.ts @@ -18,15 +18,29 @@ export const mapFiltersToSearchParams = ({ to, page, size, -}: Partial) => ({ - include_identities: 'true', - ...(status ? { status } : {}), - ...(id ? { id } : {}), - ...(from ? { created_gt: from } : {}), - ...(to ? { created_lt: to } : {}), - ...(page ? { page: `${page}` } : {}), - ...(typeof size !== 'undefined' ? { size: `${size}` } : {}), -}); +}: Partial) => { + 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({