Files
myeasycms-v2/apps/web/app/(marketing)/_components/site-header-account-section.tsx
giancarlo 6699399864 Remove use-toast.tsx, refactor auth methods, and update UI components
This commit removes the redundant `use-toast.tsx` file and refactors the authentication methods in `personal-accounts-server-actions.ts` to enhance service integration and data handling. UI components like `LanguageDropdownSwitcher` and `site-header-account-section.tsx` have been refined for better readability. Changes in the `config.tsx` file aim to improve the overall code cleanliness. The `schema.sql` file under migrations was updated to cascade delete for 'invited_by' reference.
2024-03-27 01:37:34 +08:00

69 lines
1.7 KiB
TypeScript

'use client';
import { Suspense } from 'react';
import Link from 'next/link';
import type { Session } from '@supabase/supabase-js';
import { ChevronRight } from 'lucide-react';
import { PersonalAccountDropdown } from '@kit/accounts/personal-account-dropdown';
import { useSignOut } from '@kit/supabase/hooks/use-sign-out';
import { useUserSession } from '@kit/supabase/hooks/use-user-session';
import { Button } from '@kit/ui/button';
import { If } from '@kit/ui/if';
import { Trans } from '@kit/ui/trans';
import pathsConfig from '~/config/paths.config';
export function SiteHeaderAccountSection(
props: React.PropsWithChildren<{
session: Session | null;
}>,
) {
if (!props.session) {
return <AuthButtons />;
}
return <SuspendedPersonalAccountDropdown session={props.session} />;
}
function SuspendedPersonalAccountDropdown(props: { session: Session | null }) {
const signOut = useSignOut();
const userSession = useUserSession(props.session);
return (
<If condition={userSession.data} fallback={<AuthButtons />}>
{(session) => (
<PersonalAccountDropdown
paths={{
home: pathsConfig.app.home,
}}
session={session}
signOutRequested={() => signOut.mutateAsync()}
/>
)}
</If>
);
}
function AuthButtons() {
return (
<div className={'hidden space-x-2 lg:flex'}>
<Button variant={'link'}>
<Link href={pathsConfig.auth.signIn}>
<Trans i18nKey={'auth:signIn'} />
</Link>
</Button>
<Link href={pathsConfig.auth.signUp}>
<Button className={'rounded-full'}>
<Trans i18nKey={'auth:signUp'} />
<ChevronRight className={'h-4'} />
</Button>
</Link>
</div>
);
}