diff --git a/src/app/(main)/App.tsx b/src/app/(main)/App.tsx index ec08838d..33f0e1f3 100644 --- a/src/app/(main)/App.tsx +++ b/src/app/(main)/App.tsx @@ -5,11 +5,22 @@ import { UpdateNotice } from './UpdateNotice'; import { SideNav } from '@/app/(main)/SideNav'; import { useLoginQuery, useConfig, useNavigation } from '@/components/hooks'; import { MobileNav } from '@/app/(main)/MobileNav'; +import { useEffect } from 'react'; +import { removeItem, setItem } from '@/lib/storage'; +import { LAST_TEAM_CONFIG } from '@/lib/constants'; export function App({ children }) { const { user, isLoading, error } = useLoginQuery(); const config = useConfig(); - const { pathname } = useNavigation(); + const { pathname, teamId } = useNavigation(); + + useEffect(() => { + if (teamId) { + setItem(LAST_TEAM_CONFIG, teamId); + } else { + removeItem(LAST_TEAM_CONFIG); + } + }, [teamId]); if (isLoading || !config) { return ; diff --git a/src/app/page.tsx b/src/app/page.tsx index 8249e184..8bf748f9 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,5 +1,21 @@ +'use client'; +import { useEffect } from 'react'; import { redirect } from 'next/navigation'; +import { getItem, removeItem } from '@/lib/storage'; +import { LAST_TEAM_CONFIG } from '@/lib/constants'; export default function RootPage() { - redirect('/websites'); + useEffect(() => { + const lastTeam = getItem(LAST_TEAM_CONFIG); + + if (lastTeam) { + redirect(`/teams/${lastTeam}/websites`); + } else { + removeItem(LAST_TEAM_CONFIG); + + redirect(`/websites`); + } + }, []); + + return null; } diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 195fe1be..e5090c3c 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -5,6 +5,7 @@ export const TIMEZONE_CONFIG = 'umami.timezone'; export const DATE_RANGE_CONFIG = 'umami.date-range'; export const THEME_CONFIG = 'umami.theme'; export const DASHBOARD_CONFIG = 'umami.dashboard'; +export const LAST_TEAM_CONFIG = 'umami.last-team'; export const VERSION_CHECK = 'umami.version-check'; export const SHARE_TOKEN_HEADER = 'x-umami-share-token'; export const HOMEPAGE_URL = 'https://umami.is';