import { useNavigate } from 'react-router-dom' import { LogOut } from 'lucide-react' import { Avatar, AvatarFallback } from '@/components/ui/avatar' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu' import { useToast } from '@/components/ui/use-toast' import { useAuthStore } from '@/stores/auth-store' export const UserMenu = () => { const navigate = useNavigate() const logout = useAuthStore((state) => state.logout) const user = useAuthStore((state) => state.user) const { toast } = useToast() const initials = user?.name ?.split(' ') .map((part) => part[0]) .join('') .slice(0, 2) .toUpperCase() const handleLogout = () => { logout() toast({ title: 'Вы вышли из системы' }) navigate('/login', { replace: true }) } return ( {initials || (user?.email ?? '?')[0]?.toUpperCase() || 'U'}
{user?.name ?? 'Сотрудник'} {user?.email}
Выйти
) }