Spaces:
Sleeping
Sleeping
'use client'; | |
import Image from 'next/image'; | |
import { type Session } from 'next-auth'; | |
import { signOut } from 'next-auth/react'; | |
import { Button } from '@/components/ui/Button'; | |
import { | |
DropdownMenu, | |
DropdownMenuContent, | |
DropdownMenuItem, | |
DropdownMenuSeparator, | |
DropdownMenuTrigger, | |
} from '@/components/ui/DropdownMenu'; | |
import { IconExternalLink } from '@/components/ui/Icons'; | |
import Avatar from './Avatar'; | |
export interface UserMenuProps { | |
user: Session['user']; | |
} | |
function getUserInitials(name: string) { | |
const [firstName, lastName] = name.split(' '); | |
return lastName ? `${firstName[0]}${lastName[0]}` : firstName.slice(0, 2); | |
} | |
export function UserMenu({ user }: UserMenuProps) { | |
return ( | |
<div className="flex items-center justify-between"> | |
<DropdownMenu> | |
<DropdownMenuTrigger asChild> | |
<Button variant="ghost"> | |
<Avatar name={user?.name} avatar={user?.image} /> | |
<span className="ml-2">{user?.name}</span> | |
</Button> | |
</DropdownMenuTrigger> | |
<DropdownMenuContent | |
sideOffset={8} | |
align="center" | |
className="w-[160px]" | |
> | |
<DropdownMenuItem className="flex-col items-start"> | |
<div className="text-xs font-medium">{user?.name}</div> | |
<div className="text-xs text-zinc-500">{user?.email}</div> | |
</DropdownMenuItem> | |
<DropdownMenuSeparator /> | |
<DropdownMenuItem | |
onClick={() => | |
signOut({ | |
callbackUrl: '/', | |
}) | |
} | |
className="text-xs" | |
> | |
Log Out | |
</DropdownMenuItem> | |
</DropdownMenuContent> | |
</DropdownMenu> | |
</div> | |
); | |
} | |