diff --git a/src/components/Navbar/index.tsx b/src/components/Navbar/index.tsx index ca9ac0e5..121f8373 100644 --- a/src/components/Navbar/index.tsx +++ b/src/components/Navbar/index.tsx @@ -1,4 +1,5 @@ import { useContext } from 'react'; +import { useNavigate } from 'react-router-dom'; import { gql, useMutation, @@ -40,6 +41,7 @@ interface Props { className?: string; } function Navbar(props: Props) { + const navigate = useNavigate(); const { className } = props; const strings = useTranslation(i18n); const { isAuthenticated } = useAuth(); @@ -58,8 +60,9 @@ function Navbar(props: Props) { onCompleted: (logoutResponse) => { const response = logoutResponse?.private?.logout; if (response.ok) { - window.location.reload(); removeUser(); + navigate('/login'); + window.location.reload(); } else { alert.show( strings.logoutFailure, diff --git a/src/views/HistoricalAlerts/index.tsx b/src/views/HistoricalAlerts/index.tsx index b0d798fd..44902521 100644 --- a/src/views/HistoricalAlerts/index.tsx +++ b/src/views/HistoricalAlerts/index.tsx @@ -30,6 +30,7 @@ import { resolveToString, } from '@ifrc-go/ui/utils'; import { + doesObjectHaveNoData, isDefined, isNotDefined, } from '@togglecorp/fujs'; @@ -197,40 +198,55 @@ export function Component() { const variables = useMemo<{ filters: AlertFilter | undefined, pagination: OffsetPaginationInput, - }>(() => ({ - pagination: { - offset, - limit, - }, - filters: finalFilter ? { - DISTINCT: true, - infos: { - urgency: finalFilter?.urgency, - severity: finalFilter?.severity, - certainty: finalFilter?.certainty, - category: finalFilter?.category, + }>(() => { + const sentFilter = finalFilter?.startDateBefore || finalFilter?.startDateAfter ? { + range: { + ...(finalFilter?.startDateBefore && { end: finalFilter.startDateBefore }), + ...(finalFilter?.startDateAfter && { start: finalFilter.startDateAfter }), }, - country: isDefined(finalFilter?.country?.pk) - ? { pk: finalFilter.country.pk } : undefined, - admin1: finalFilter?.admin1, - sent: { - range: { - end: finalFilter?.startDateBefore, - start: finalFilter?.startDateAfter, - }, + } : undefined; + return { + pagination: { + offset, + limit, }, - } : undefined, - }), [ + filters: finalFilter ? { + DISTINCT: true, + infos: { + urgency: finalFilter?.urgency, + severity: finalFilter?.severity, + certainty: finalFilter?.certainty, + category: finalFilter?.category, + }, + country: isDefined(finalFilter?.country?.pk) + ? { pk: finalFilter.country.pk } : undefined, + admin1: finalFilter?.admin1, + sent: sentFilter, + } : undefined, + }; + }, [ limit, offset, finalFilter, ]); const handleApplyFilters = useCallback(() => { - setFinalFilter(rawFilter); - }, [ - rawFilter, - ]); + if (doesObjectHaveNoData(rawFilter)) { + setFinalFilter(undefined); + } else { + const updatedFilter = { + ...rawFilter, + sent: rawFilter.startDateBefore || rawFilter.startDateAfter ? { + range: { + ...(rawFilter.startDateBefore && { end: rawFilter.startDateBefore }), + ...(rawFilter.startDateAfter && { start: rawFilter.startDateAfter }), + }, + } : {}, + }; + setFinalFilter(updatedFilter); + } + setPage(1); + }, [rawFilter, setPage]); const handleResetFilters = useCallback(() => { setFinalFilter(undefined); @@ -401,6 +417,7 @@ export function Component() { errorMessage={alertInfoError?.message} footerActions={isDefined(data) && (