1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-04 00:18:01 +01:00

feat: redirect to personal dashboard when no last project (#8318)

This commit is contained in:
Mateusz Kwasniewski 2024-10-01 13:11:29 +02:00 committed by GitHub
parent a6ab5326a0
commit bf787b6deb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,11 +1,13 @@
import { useCallback, useEffect } from 'react'; import { useCallback, useEffect } from 'react';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import useProjects from '../hooks/api/getters/useProjects/useProjects'; import useProjects from 'hooks/api/getters/useProjects/useProjects';
import { useLastViewedProject } from '../hooks/useLastViewedProject'; import { useLastViewedProject } from 'hooks/useLastViewedProject';
import Loader from './common/Loader/Loader'; 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 = () => { export const InitialRedirect = () => {
const personalDashboardUiEnabled = useUiFlag('personalDashboardUI');
const { lastViewed } = useLastViewedProject(); const { lastViewed } = useLastViewedProject();
const { projects, loading } = useProjects(); const { projects, loading } = useProjects();
const navigate = useNavigate(); const navigate = useNavigate();
@ -17,12 +19,16 @@ export const InitialRedirect = () => {
return `/projects/${lastViewed}`; return `/projects/${lastViewed}`;
} }
if (personalDashboardUiEnabled) {
return '/personal';
}
if (projects && !lastViewed && projects.length === 1) { if (projects && !lastViewed && projects.length === 1) {
return `/projects/${projects[0].id}`; return `/projects/${projects[0].id}`;
} }
return '/projects'; return '/projects';
}, [lastViewed, projects]); }, [lastViewed, projects, personalDashboardUiEnabled]);
const redirect = () => { const redirect = () => {
navigate(sessionRedirect ?? getRedirect(), { replace: true }); navigate(sessionRedirect ?? getRedirect(), { replace: true });