Skip to content

Commit

Permalink
feat: redirect to personal dashboard when no last project (#8318)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew authored Oct 1, 2024
1 parent a6ab532 commit bf787b6
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions frontend/src/component/InitialRedirect.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useCallback, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import useProjects from '../hooks/api/getters/useProjects/useProjects';
import { useLastViewedProject } from '../hooks/useLastViewedProject';
import useProjects from 'hooks/api/getters/useProjects/useProjects';
import { useLastViewedProject } from 'hooks/useLastViewedProject';
import Loader from './common/Loader/Loader';
import { getSessionStorageItem, setSessionStorageItem } from '../utils/storage';
import { getSessionStorageItem, setSessionStorageItem } from 'utils/storage';
import { useUiFlag } from 'hooks/useUiFlag';

export const InitialRedirect = () => {
const personalDashboardUiEnabled = useUiFlag('personalDashboardUI');
const { lastViewed } = useLastViewedProject();
const { projects, loading } = useProjects();
const navigate = useNavigate();
Expand All @@ -17,12 +19,16 @@ export const InitialRedirect = () => {
return `/projects/${lastViewed}`;
}

if (personalDashboardUiEnabled) {
return '/personal';
}

if (projects && !lastViewed && projects.length === 1) {
return `/projects/${projects[0].id}`;
}

return '/projects';
}, [lastViewed, projects]);
}, [lastViewed, projects, personalDashboardUiEnabled]);

const redirect = () => {
navigate(sessionRedirect ?? getRedirect(), { replace: true });
Expand Down

0 comments on commit bf787b6

Please sign in to comment.