Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Remember last team.

Mike Caoef3f7274e3d4
diff --git a/src/app/(main)/App.tsx b/src/app/(main)/App.tsx
index ec08838d1..33f0e1f36 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 <Loading placement="absolute" />;
diff --git a/src/app/page.tsx b/src/app/page.tsx
index 8249e1849..8bf748f9b 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 195fe1be8..e5090c3c0 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';