From d6f3be5543e4e2036a09fcd97a800198f16913a5 Mon Sep 17 00:00:00 2001 From: Zai Shi Date: Wed, 2 Jul 2025 19:23:53 +0200 Subject: [PATCH 1/7] swithcer (#715) ---- > [!IMPORTANT] > Enhance `SelectedTeamSwitcher` to support nullable teams and add 'personal' team icon in `TeamIcon`, with updated translations. > > - **Behavior**: > - `SelectedTeamSwitcher` in `selected-team-switcher.tsx` now supports nullable teams with `allowNull` prop and `nullLabel` for display. > - `onChange` callback added to `SelectedTeamSwitcher` to handle team changes. > - `TeamIcon` in `team-icon.tsx` now supports a 'personal' team type, displaying a default icon. > - **Translations**: > - Added translation key for "Personal team" in `quetzal-translations.ts`. > - **Misc**: > - Updated `SelectedTeamSwitcherProps` type to handle nullable teams and added `onChange` callback. > - Minor refactoring in `selected-team-switcher.tsx` for better handling of team selection logic. > > This description was created by [Ellipsis](https://www.ellipsis.dev?ref=stack-auth%2Fstack-auth&utm_source=github&utm_medium=referral) for ddb61e962bb1fb25c37f1ba889ce6845eccdb81a. You can [customize](https://app.ellipsis.dev/stack-auth/settings/summaries) this summary. It will automatically update as commits are pushed. --------- Co-authored-by: Konsti Wohlwend --- .../src/app/team/[teamId]/page.tsx | 2 +- .../src/components/selected-team-switcher.tsx | 51 +- .../template/src/components/team-icon.tsx | 10 +- .../src/generated/quetzal-translations.ts | 2878 +++++++++-------- 4 files changed, 1494 insertions(+), 1447 deletions(-) diff --git a/examples/docs-examples/src/app/team/[teamId]/page.tsx b/examples/docs-examples/src/app/team/[teamId]/page.tsx index 143f0ab1d..40cbb1df5 100644 --- a/examples/docs-examples/src/app/team/[teamId]/page.tsx +++ b/examples/docs-examples/src/app/team/[teamId]/page.tsx @@ -1,6 +1,6 @@ "use client"; -import { useUser, SelectedTeamSwitcher } from "@stackframe/stack"; +import { SelectedTeamSwitcher, useUser } from "@stackframe/stack"; export default function TeamPage({ params }: { params: { teamId: string } }) { const user = useUser({ or: 'redirect' }); diff --git a/packages/template/src/components/selected-team-switcher.tsx b/packages/template/src/components/selected-team-switcher.tsx index 6562371d2..18168f79a 100644 --- a/packages/template/src/components/selected-team-switcher.tsx +++ b/packages/template/src/components/selected-team-switcher.tsx @@ -1,4 +1,5 @@ 'use client'; +import { StackAssertionError } from "@stackframe/stack-shared/dist/utils/errors"; import { runAsynchronouslyWithAlert } from "@stackframe/stack-shared/dist/utils/promises"; import { Button, @@ -25,10 +26,13 @@ type MockTeam = { profileImageUrl?: string | null, }; -type SelectedTeamSwitcherProps = { - urlMap?: (team: Team) => string, +type SelectedTeamSwitcherProps = { + urlMap?: (team: AllowNull extends true ? Team | null : Team) => string, selectedTeam?: Team, noUpdateSelectedTeam?: boolean, + allowNull?: AllowNull, + nullLabel?: string, + onChange?: (team: AllowNull extends true ? Team | null : Team) => void, // Mock data props mockUser?: { selectedTeam?: MockTeam, @@ -41,7 +45,7 @@ type SelectedTeamSwitcherProps = { }, }; -export function SelectedTeamSwitcher(props: SelectedTeamSwitcherProps) { +export function SelectedTeamSwitcher(props: SelectedTeamSwitcherProps) { return }> ; @@ -51,7 +55,7 @@ function Fallback() { return ; } -function Inner(props: SelectedTeamSwitcherProps) { +function Inner(props: SelectedTeamSwitcherProps) { const { t } = useTranslation(); const appFromHook = useStackApp(); const userFromHook = useUser(); @@ -83,17 +87,27 @@ function Inner(props: SelectedTeamSwitcherProps) { return (