Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirects to last selected team on login #3043

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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