The Link component is modified to be nested within the Button component in various JSX files. This change was made with the aid of the 'asChild' property, it ensures that the link remains operable even when wrapped by the button, improving the site's semantics and accessibility.
95 lines
2.3 KiB
TypeScript
95 lines
2.3 KiB
TypeScript
'use client';
|
|
|
|
import dynamic from 'next/dynamic';
|
|
import Link from 'next/link';
|
|
|
|
import type { User } 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 { useUser } from '@kit/supabase/hooks/use-user';
|
|
import { Button } from '@kit/ui/button';
|
|
import { Trans } from '@kit/ui/trans';
|
|
|
|
import featuresFlagConfig from '~/config/feature-flags.config';
|
|
import pathsConfig from '~/config/paths.config';
|
|
|
|
const ModeToggle = dynamic(
|
|
() => import('@kit/ui/mode-toggle').then((mod) => mod.ModeToggle),
|
|
{
|
|
ssr: false,
|
|
},
|
|
);
|
|
|
|
const paths = {
|
|
home: pathsConfig.app.home,
|
|
};
|
|
|
|
const features = {
|
|
enableThemeToggle: featuresFlagConfig.enableThemeToggle,
|
|
};
|
|
|
|
export function SiteHeaderAccountSection({
|
|
user,
|
|
}: React.PropsWithChildren<{
|
|
user: User | null;
|
|
}>) {
|
|
if (!user) {
|
|
return <AuthButtons />;
|
|
}
|
|
|
|
return <SuspendedPersonalAccountDropdown user={user} />;
|
|
}
|
|
|
|
function SuspendedPersonalAccountDropdown(props: { user: User | null }) {
|
|
const signOut = useSignOut();
|
|
const user = useUser(props.user);
|
|
const userData = user.data ?? props.user ?? null;
|
|
|
|
if (userData) {
|
|
return (
|
|
<PersonalAccountDropdown
|
|
paths={paths}
|
|
features={features}
|
|
user={userData}
|
|
signOutRequested={() => signOut.mutateAsync()}
|
|
/>
|
|
);
|
|
}
|
|
|
|
return <AuthButtons />;
|
|
}
|
|
|
|
function AuthButtons() {
|
|
const textClassName =
|
|
'text-gray-600 hover:text-current dark:text-gray-400 dark:hover:text-white';
|
|
|
|
return (
|
|
<div className={'flex space-x-2'}>
|
|
<div className={'hidden space-x-0.5 md:flex'}>
|
|
<ModeToggle className={textClassName} />
|
|
|
|
<Button asChild variant={'ghost'} className={textClassName}>
|
|
<Link href={pathsConfig.auth.signIn}>
|
|
<Trans i18nKey={'auth:signIn'} />
|
|
</Link>
|
|
</Button>
|
|
</div>
|
|
|
|
<Button asChild className="group" variant={'default'}>
|
|
<Link href={pathsConfig.auth.signUp}>
|
|
<Trans i18nKey={'auth:signUp'} />
|
|
|
|
<ChevronRight
|
|
className={
|
|
'ml-1 h-4 w-4 transition-transform duration-500 group-hover:translate-x-1'
|
|
}
|
|
/>
|
|
</Link>
|
|
</Button>
|
|
</div>
|
|
);
|
|
}
|