From c1f7aaadc135c893537ca8e8aa63fd9a7331d915 Mon Sep 17 00:00:00 2001 From: arcoraven Date: Thu, 22 May 2025 06:42:40 +0000 Subject: [PATCH] chore: redirect /team to /team/~ to select a team (#7124) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## [Dashboard] Fix: Simplify team redirection logic ## Notes for the reviewer This PR modifies the team redirection logic by: 1. Renaming `getLastVisitedTeamOrDefaultTeam()` to `getLastVisitedTeam()` 2. Removing the fallback to `getDefaultTeam()` when no last visited team is found 3. Updating the team root page to redirect to `/team/~` when no team is found instead of showing a 404 ## How to test Verify that users are properly redirected to their last visited team when available, and to `/team/~` when no team history exists. ## Summary by CodeRabbit - **Bug Fixes** - Improved handling when no last visited team is found by redirecting users to a fallback page instead of showing a not found error. - **Refactor** - Updated team selection logic to remove fallback to a default team and streamline user redirection. --- ## PR-Codex overview This PR refactors the `getLastVisitedTeamOrDefaultTeam` function to `getLastVisitedTeam`, changing its behavior to return `null` instead of a default team. It updates the `TeamRootPage` to handle the absence of a team by redirecting to a fallback URL. ### Detailed summary - Renamed function `getLastVisitedTeamOrDefaultTeam` to `getLastVisitedTeam`. - Changed return value of `getLastVisitedTeam` from `getDefaultTeam()` to `null`. - Updated `TeamRootPage` to redirect to `/team/~` if no team is found, instead of calling `notFound()`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` --- apps/dashboard/src/@/api/team.ts | 4 ++-- apps/dashboard/src/app/(app)/team/page.tsx | 11 ++++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/apps/dashboard/src/@/api/team.ts b/apps/dashboard/src/@/api/team.ts index ccc5b7cad63..798e9de2d6e 100644 --- a/apps/dashboard/src/@/api/team.ts +++ b/apps/dashboard/src/@/api/team.ts @@ -84,7 +84,7 @@ export async function getDefaultTeam() { return null; } -export async function getLastVisitedTeamOrDefaultTeam() { +export async function getLastVisitedTeam() { const token = await getAuthToken(); if (!token) { return null; @@ -100,5 +100,5 @@ export async function getLastVisitedTeamOrDefaultTeam() { } } - return getDefaultTeam(); + return null; } diff --git a/apps/dashboard/src/app/(app)/team/page.tsx b/apps/dashboard/src/app/(app)/team/page.tsx index 5b25b665b1e..e3d8f8ceb9b 100644 --- a/apps/dashboard/src/app/(app)/team/page.tsx +++ b/apps/dashboard/src/app/(app)/team/page.tsx @@ -1,10 +1,7 @@ -import { getLastVisitedTeamOrDefaultTeam } from "@/api/team"; -import { notFound, redirect } from "next/navigation"; +import { getLastVisitedTeam } from "@/api/team"; +import { redirect } from "next/navigation"; export default async function TeamRootPage() { - const team = await getLastVisitedTeamOrDefaultTeam(); - if (!team) { - notFound(); - } - redirect(`/team/${team.slug}`); + const team = await getLastVisitedTeam(); + redirect(team ? `/team/${team.slug}` : "/team/~"); }