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,
|
|
|
|
|
Github,
|
|
|
|
|
Key,
|
|
|
|
|
LogOut,
|
|
|
|
|
User as LucideUser,
|
2023-09-19 19:45:21 +05:30
|
|
|
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,
|
2023-09-08 09:16:31 +03:00
|
|
|
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';
|
2023-06-09 18:21:18 +10:00
|
|
|
|
2023-09-12 12:33:04 +10:00
|
|
|
import { recipientInitials } from '@documenso/lib/utils/recipient-formatter';
|
2023-06-09 18:21:18 +10:00
|
|
|
import { User } from '@documenso/prisma/client';
|
|
|
|
|
import { Avatar, AvatarFallback } from '@documenso/ui/primitives/avatar';
|
|
|
|
|
import { Button } from '@documenso/ui/primitives/button';
|
|
|
|
|
import {
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuItem,
|
|
|
|
|
DropdownMenuLabel,
|
2023-09-19 13:38:37 +05:30
|
|
|
DropdownMenuPortal,
|
|
|
|
|
DropdownMenuRadioGroup,
|
|
|
|
|
DropdownMenuRadioItem,
|
2023-06-09 18:21:18 +10:00
|
|
|
DropdownMenuSeparator,
|
2023-09-19 13:38:37 +05:30
|
|
|
DropdownMenuSub,
|
|
|
|
|
DropdownMenuSubContent,
|
|
|
|
|
DropdownMenuSubTrigger,
|
2023-06-09 18:21:18 +10:00
|
|
|
DropdownMenuTrigger,
|
|
|
|
|
} from '@documenso/ui/primitives/dropdown-menu';
|
|
|
|
|
|
2023-08-18 20:05:14 +10:00
|
|
|
import { useFeatureFlags } from '~/providers/feature-flag';
|
|
|
|
|
|
2023-06-09 18:21:18 +10:00
|
|
|
export type ProfileDropdownProps = {
|
|
|
|
|
user: User;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const ProfileDropdown = ({ user }: ProfileDropdownProps) => {
|
2023-08-18 20:05:14 +10:00
|
|
|
const { getFlag } = useFeatureFlags();
|
2023-09-19 13:38:37 +05:30
|
|
|
const { theme, setTheme } = useTheme();
|
2023-09-08 11:28:50 +03:00
|
|
|
const isUserAdmin = isAdmin(user);
|
2023-08-18 20:05:14 +10:00
|
|
|
|
2023-08-21 11:44:56 +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" className="relative h-10 w-10 rounded-full">
|
|
|
|
|
<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/password" className="cursor-pointer">
|
|
|
|
|
<Key className="mr-2 h-4 w-4" />
|
|
|
|
|
Password
|
|
|
|
|
</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>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<DropdownMenuSeparator />
|
|
|
|
|
|
2023-09-19 13:38:37 +05:30
|
|
|
<DropdownMenuSub>
|
2023-09-20 06:56:40 +05:30
|
|
|
<DropdownMenuSubTrigger>
|
|
|
|
|
<Palette className="mr-2 h-4 w-4" />
|
|
|
|
|
Themes
|
|
|
|
|
</DropdownMenuSubTrigger>
|
2023-09-19 13:38:37 +05:30
|
|
|
<DropdownMenuPortal>
|
|
|
|
|
<DropdownMenuSubContent>
|
|
|
|
|
<DropdownMenuRadioGroup value={theme} onValueChange={setTheme}>
|
2023-09-19 19:45:21 +05:30
|
|
|
<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>
|
2023-09-19 13:38:37 +05:30
|
|
|
</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">
|
|
|
|
|
<Github className="mr-2 h-4 w-4" />
|
|
|
|
|
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>
|
|
|
|
|
);
|
|
|
|
|
};
|