Refactor authentication and internationalize metadata

This commit simplifies the authentication mechanism by directly comparing user ID and primary owner ID while refactoring the Team Account container. Simultaneously, it internationalizes the metadata of several pages by creating server I18n instances for title translations, ensuring better support for varied languages.
This commit is contained in:
giancarlo
2024-03-28 22:14:54 +08:00
parent efd2a757ff
commit 260f7b3295
11 changed files with 88 additions and 16 deletions

View File

@@ -6,6 +6,7 @@ import { zodResolver } from '@hookform/resolvers/zod';
import { useForm } from 'react-hook-form';
import { z } from 'zod';
import { useUser } from '@kit/supabase/hooks/use-user';
import { Alert, AlertDescription, AlertTitle } from '@kit/ui/alert';
import {
AlertDialog,
@@ -29,6 +30,7 @@ import {
FormMessage,
} from '@kit/ui/form';
import { Input } from '@kit/ui/input';
import { LoadingOverlay } from '@kit/ui/loading-overlay';
import { Trans } from '@kit/ui/trans';
import { deleteTeamAccountAction } from '../../server/actions/delete-team-account-server-actions';
@@ -36,15 +38,23 @@ import { leaveTeamAccountAction } from '../../server/actions/leave-team-account-
export function TeamAccountDangerZone({
account,
userIsPrimaryOwner,
primaryOwnerUserId,
}: React.PropsWithChildren<{
account: {
name: string;
id: string;
};
userIsPrimaryOwner: boolean;
primaryOwnerUserId: string;
}>) {
const { data: user, isLoading } = useUser();
if (isLoading) {
return <LoadingOverlay fullPage={false} />;
}
const userIsPrimaryOwner = user?.id === primaryOwnerUserId;
if (userIsPrimaryOwner) {
return <DeleteTeamContainer account={account} />;
}

View File

@@ -22,8 +22,6 @@ export function TeamAccountSettingsContainer(props: {
primaryOwnerUserId: string;
};
userId: string;
paths: {
teamAccountSettings: string;
};
@@ -78,9 +76,7 @@ export function TeamAccountSettingsContainer(props: {
<CardContent>
<TeamAccountDangerZone
userIsPrimaryOwner={
props.userId === props.account.primaryOwnerUserId
}
primaryOwnerUserId={props.account.primaryOwnerUserId}
account={props.account}
/>
</CardContent>