From f01073c46afd8f3a6db21e8f181854937c224a09 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Wed, 14 Feb 2024 22:13:13 -0800 Subject: [PATCH] Update redirects for teams. --- next.config.js | 24 +++++++++++++++++++----- src/app/(main)/NavBar.tsx | 2 +- src/app/(main)/settings/layout.tsx | 4 ++++ src/components/input/TeamsButton.tsx | 3 ++- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/next.config.js b/next.config.js index f353b1f9..dce49100 100644 --- a/next.config.js +++ b/next.config.js @@ -70,7 +70,7 @@ if (trackerScriptName) { const redirects = [ { source: '/settings', - destination: cloudMode ? `${cloudUrl}/settings/websites` : '/settings/websites', + destination: '/settings/websites', permanent: true, }, { @@ -80,17 +80,31 @@ const redirects = [ }, { source: '/teams/:id/settings', - destination: cloudMode ? `${cloudUrl}/teams/:id/settings` : '/teams/:id/settings/team', + destination: '/teams/:id/settings/team', permanent: true, }, ]; -if (cloudMode && cloudUrl && disableLogin) { +if (cloudMode && cloudUrl) { redirects.push({ - source: '/login', - destination: cloudUrl, + source: '/settings/:path*', + destination: `${cloudUrl}/settings/:path*`, permanent: false, }); + + redirects.push({ + source: '/teams/:id/settings/:path*', + destination: `${cloudUrl}/teams/:id/settings/:path*`, + permanent: false, + }); + + if (disableLogin) { + redirects.push({ + source: '/login', + destination: cloudUrl, + permanent: false, + }); + } } /** @type {import('next').NextConfig} */ diff --git a/src/app/(main)/NavBar.tsx b/src/app/(main)/NavBar.tsx index 86d1db71..15b23355 100644 --- a/src/app/(main)/NavBar.tsx +++ b/src/app/(main)/NavBar.tsx @@ -17,7 +17,7 @@ export function NavBar() { const { pathname } = useNavigation(); const { teamId, renderTeamUrl } = useTeamUrl(); - const cloudMode = Boolean(process.env.cloudMode); + const cloudMode = !!process.env.cloudMode; const links = [ { label: formatMessage(labels.dashboard), url: renderTeamUrl('/dashboard') }, diff --git a/src/app/(main)/settings/layout.tsx b/src/app/(main)/settings/layout.tsx index eb382e3b..487a9d59 100644 --- a/src/app/(main)/settings/layout.tsx +++ b/src/app/(main)/settings/layout.tsx @@ -1,5 +1,9 @@ import SettingsLayout from './SettingsLayout'; export default function ({ children }) { + if (process.env.cloudMode) { + return null; + } + return {children}; } diff --git a/src/components/input/TeamsButton.tsx b/src/components/input/TeamsButton.tsx index a91cdb2f..c7fc535a 100644 --- a/src/components/input/TeamsButton.tsx +++ b/src/components/input/TeamsButton.tsx @@ -10,10 +10,11 @@ export function TeamsButton({ teamId }: { teamId: string }) { const { formatMessage, labels } = useMessages(); const { router } = useNavigation(); const team = user?.teams?.find(({ id }) => id === teamId); + const cloudMode = !!process.env.cloudMode; const handleSelect = (close: () => void, id: Key) => { if (id !== user.id) { - router.push(`/teams/${id}`); + router.push(cloudMode ? `${process.env.cloudUrl}/teams/${id}` : `/teams/${id}`); } else { router.push('/'); }