Files
sign/apps/web/src/components/(dashboard)/layout/profile-dropdown.tsx

166 lines
4.8 KiB
TypeScript
Raw Normal View History

2023-06-09 18:21:18 +10:00
'use client';
import Link from 'next/link';
2023-06-11 01:50:19 -04:00
import {
CreditCard,
2023-10-06 22:54:24 +00:00
FileSpreadsheet,
Lock,
2023-06-11 01:50:19 -04:00
LogOut,
User as LucideUser,
Monitor,
2023-06-11 01:50:19 -04:00
Moon,
2023-09-20 06:56:40 +05:30
Palette,
2023-06-11 01:50:19 -04:00
Sun,
UserCog,
2023-06-11 01:50:19 -04:00
} from 'lucide-react';
2023-06-09 18:21:18 +10:00
import { signOut } from 'next-auth/react';
2023-06-11 01:50:19 -04:00
import { useTheme } from 'next-themes';
import { LuGithub } from 'react-icons/lu';
2023-06-09 18:21:18 +10:00
2023-09-20 13:48:30 +10:00
import { useFeatureFlags } from '@documenso/lib/client-only/providers/feature-flag';
import { isAdmin } from '@documenso/lib/next-auth/guards/is-admin';
2023-09-12 12:33:04 +10:00
import { recipientInitials } from '@documenso/lib/utils/recipient-formatter';
import type { User } from '@documenso/prisma/client';
2023-06-09 18:21:18 +10:00
import { Avatar, AvatarFallback } from '@documenso/ui/primitives/avatar';
import { Button } from '@documenso/ui/primitives/button';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuPortal,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
2023-06-09 18:21:18 +10:00
DropdownMenuSeparator,
DropdownMenuSub,
DropdownMenuSubContent,
DropdownMenuSubTrigger,
2023-06-09 18:21:18 +10:00
DropdownMenuTrigger,
} from '@documenso/ui/primitives/dropdown-menu';
export type ProfileDropdownProps = {
user: User;
};
export const ProfileDropdown = ({ user }: ProfileDropdownProps) => {
2023-08-18 20:05:14 +10:00
const { getFlag } = useFeatureFlags();
const { theme, setTheme } = useTheme();
2023-09-08 11:28:50 +03:00
const isUserAdmin = isAdmin(user);
2023-08-18 20:05:14 +10:00
const isBillingEnabled = getFlag('app_billing');
2023-08-18 20:05:14 +10:00
2023-09-12 12:33:04 +10:00
const avatarFallback = user.name
? recipientInitials(user.name)
: user.email.slice(0, 1).toUpperCase();
2023-06-09 18:21:18 +10:00
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
title="Profile Dropdown"
className="relative h-10 w-10 rounded-full"
>
2023-06-09 18:21:18 +10:00
<Avatar className="h-10 w-10">
2023-09-11 16:58:41 +10:00
<AvatarFallback>{avatarFallback}</AvatarFallback>
2023-06-09 18:21:18 +10:00
</Avatar>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-56" align="end" forceMount>
<DropdownMenuLabel>Account</DropdownMenuLabel>
2023-09-12 07:25:44 +00:00
{isUserAdmin && (
<>
<DropdownMenuItem asChild>
<Link href="/admin" className="cursor-pointer">
<UserCog className="mr-2 h-4 w-4" />
Admin
</Link>
</DropdownMenuItem>
<DropdownMenuSeparator />
</>
)}
2023-06-09 18:21:18 +10:00
<DropdownMenuItem asChild>
<Link href="/settings/profile" className="cursor-pointer">
<LucideUser className="mr-2 h-4 w-4" />
Profile
</Link>
</DropdownMenuItem>
<DropdownMenuItem asChild>
<Link href="/settings/security" className="cursor-pointer">
<Lock className="mr-2 h-4 w-4" />
Security
2023-06-09 18:21:18 +10:00
</Link>
</DropdownMenuItem>
2023-08-18 20:05:14 +10:00
{isBillingEnabled && (
2023-06-09 18:21:18 +10:00
<DropdownMenuItem asChild>
<Link href="/settings/billing" className="cursor-pointer">
<CreditCard className="mr-2 h-4 w-4" />
Billing
</Link>
</DropdownMenuItem>
)}
2023-10-06 22:54:24 +00:00
<DropdownMenuSeparator />
<DropdownMenuItem asChild>
<Link href="/templates" className="cursor-pointer">
<FileSpreadsheet className="mr-2 h-4 w-4" />
Templates
</Link>
</DropdownMenuItem>
2023-06-09 18:21:18 +10:00
<DropdownMenuSeparator />
<DropdownMenuSub>
2023-09-20 06:56:40 +05:30
<DropdownMenuSubTrigger>
<Palette className="mr-2 h-4 w-4" />
Themes
</DropdownMenuSubTrigger>
<DropdownMenuPortal>
<DropdownMenuSubContent>
<DropdownMenuRadioGroup value={theme} onValueChange={setTheme}>
<DropdownMenuRadioItem value="light">
<Sun className="mr-2 h-4 w-4" /> Light
</DropdownMenuRadioItem>
<DropdownMenuRadioItem value="dark">
<Moon className="mr-2 h-4 w-4" />
Dark
</DropdownMenuRadioItem>
<DropdownMenuRadioItem value="system">
<Monitor className="mr-2 h-4 w-4" />
System
</DropdownMenuRadioItem>
</DropdownMenuRadioGroup>
</DropdownMenuSubContent>
</DropdownMenuPortal>
</DropdownMenuSub>
2023-06-11 01:50:19 -04:00
<DropdownMenuSeparator />
2023-06-09 18:21:18 +10:00
<DropdownMenuItem asChild>
<Link href="https://github.com/documenso/documenso" className="cursor-pointer">
<LuGithub className="mr-2 h-4 w-4" />
2023-06-09 18:21:18 +10:00
Star on Github
</Link>
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
onSelect={() =>
2023-08-29 13:01:19 +10:00
void signOut({
2023-06-09 18:21:18 +10:00
callbackUrl: '/',
})
}
>
<LogOut className="mr-2 h-4 w-4" />
Sign Out
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
);
};