Merge pull request #3043 from chelsey-g/team-cookie

redirects to last selected team on login
This commit is contained in:
Mike Cao 2024-11-18 13:27:28 -08:00 committed by GitHub
commit 0d561eb231
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,6 +10,8 @@ import TeamsButton from 'components/input/TeamsButton';
import Icons from 'components/icons';
import { useMessages, useNavigation, useTeamUrl } from 'components/hooks';
import styles from './NavBar.module.css';
import { useEffect } from 'react';
import { getItem, setItem } from 'next-basics';
export function NavBar() {
const { formatMessage, labels } = useMessages();
@ -74,10 +76,21 @@ export function NavBar() {
const handleTeamChange = (teamId: string) => {
const url = teamId ? `/teams/${teamId}` : '/';
setItem('umami.team', { id: teamId });
router.push(cloudMode ? `${process.env.cloudUrl}${url}` : url);
};
useEffect(() => {
const teamIdLocal = getItem('umami.team')?.id;
if (teamIdLocal && pathname !== '/' && pathname !== '/dashboard') {
const url = '/';
router.push(cloudMode ? `${process.env.cloudUrl}${url}` : url);
} else if (teamIdLocal) {
const url = `/teams/${teamIdLocal}/dashboard`;
router.push(cloudMode ? `${process.env.cloudUrl}${url}` : url);
}
}, []);
return (
<div className={styles.navbar}>
<div className={styles.logo}>