Skip to content

Commit

Permalink
Merge pull request #3043 from chelsey-g/team-cookie
Browse files Browse the repository at this point in the history
redirects to last selected team on login
  • Loading branch information
mikecao authored Nov 18, 2024
2 parents 327b2c8 + c50b0c9 commit 0d561eb
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/app/(main)/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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}>
Expand Down

0 comments on commit 0d561eb

Please sign in to comment.