From 451078524d740b92d66175124ba5781bded0fae7 Mon Sep 17 00:00:00 2001 From: majakomel Date: Wed, 18 Oct 2023 11:54:55 +0200 Subject: [PATCH] Fix redirection from incident dashboard --- hooks/useUser.js | 1 - pages/incidents/dashboard.js | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/hooks/useUser.js b/hooks/useUser.js index 81900982..27d265c4 100644 --- a/hooks/useUser.js +++ b/hooks/useUser.js @@ -14,7 +14,6 @@ export const UserProvider = ({ children }) => { const [user, setUser] = useState() const [error, setError] = useState() const [loading, setLoading] = useState(true) - // const [loadingInitial, setLoadingInitial] = useState(true) const getUser = () => { return getAPI(apiEndpoints.ACCOUNT_METADATA) diff --git a/pages/incidents/dashboard.js b/pages/incidents/dashboard.js index 405e4acc..a45233de 100644 --- a/pages/incidents/dashboard.js +++ b/pages/incidents/dashboard.js @@ -34,7 +34,7 @@ const StyledRow = styled.tr` const IncidentsDashboard = () => { const intl = useIntl() - const { user } = useUser() + const { user, loading } = useUser() const router = useRouter() const { data, error } = useSWR(apiEndpoints.SEARCH_INCIDENTS, fetcher) @@ -45,8 +45,8 @@ const IncidentsDashboard = () => { // redirect non-admin users useEffect(() => { - if (user && user?.role !== 'admin') router.replace('/incidents') - }, [user, router]) + if (!loading && user?.role !== 'admin') router.replace('/incidents') + }, [user, loading, router]) const columns = useMemo( () => [