Merge pull request #3043 from chelsey-g/team-cookie
redirects to last selected team on login
This commit is contained in:
@@ -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}>
|
||||
|
||||
Reference in New Issue
Block a user