Skip to content

Commit 9f90b87

Browse files
committed
[TOOL-4366] Redirect /team to last visited team (#6938)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR updates the team management functionality in the `TeamRootPage` component by replacing the method for retrieving the team with a new function that checks for the last visited team or defaults to a standard team. This improves user experience by remembering the last team visited. ### Detailed summary - Replaced `getDefaultTeam` with `getLastVisitedTeamOrDefaultTeam` in `TeamRootPage`. - Updated the condition to check if a team is available. - Changed the redirect URL to use the slug of the newly retrieved `team`. - Added `getLastVisitedTeamOrDefaultTeam` function in `team.ts` to handle team retrieval logic using cookies. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent e9d0b6e commit 9f90b87

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

apps/dashboard/src/@/api/team.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import "server-only";
22
import { API_SERVER_URL, THIRDWEB_API_SECRET } from "@/constants/env";
33
import type { TeamResponse } from "@thirdweb-dev/service-utils";
4+
import { cookies } from "next/headers";
45
import { getAuthToken } from "../../app/(app)/api/lib/getAuthToken";
6+
import { LAST_USED_TEAM_ID } from "../../constants/cookies";
57

68
export type Team = TeamResponse & { stripeCustomerId: string | null };
79

@@ -74,3 +76,22 @@ export async function getDefaultTeam() {
7476
}
7577
return null;
7678
}
79+
80+
export async function getLastVisitedTeamOrDefaultTeam() {
81+
const token = await getAuthToken();
82+
if (!token) {
83+
return null;
84+
}
85+
86+
const cookiesStore = await cookies();
87+
const lastVisitedTeamId = cookiesStore.get(LAST_USED_TEAM_ID)?.value;
88+
89+
if (lastVisitedTeamId) {
90+
const team = await getTeamById(lastVisitedTeamId);
91+
if (team) {
92+
return team;
93+
}
94+
}
95+
96+
return getDefaultTeam();
97+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { getDefaultTeam } from "@/api/team";
1+
import { getLastVisitedTeamOrDefaultTeam } from "@/api/team";
22
import { notFound, redirect } from "next/navigation";
33

44
export default async function TeamRootPage() {
5-
const firstTeam = await getDefaultTeam();
6-
if (!firstTeam) {
5+
const team = await getLastVisitedTeamOrDefaultTeam();
6+
if (!team) {
77
notFound();
88
}
9-
redirect(`/team/${firstTeam.slug}`);
9+
redirect(`/team/${team.slug}`);
1010
}

0 commit comments

Comments
 (0)