import { client } from '@/ui/api/client' import { Avatar, AvatarFallback, AvatarImage } from '@/ui/components/ui/avatar' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, DropdownMenuSub, DropdownMenuSubTrigger, DropdownMenuSubContent, DropdownMenuPortal, } from '@/ui/components/ui/dropdown-menu' import { useTeamId } from '@/ui/hooks/use-team-id' import { signOut } from '@/ui/lib/auth-client' import { useAuthStore } from '@/ui/stores/auth' import { useQuery } from '@tanstack/react-query' import { useNavigate } from '@tanstack/react-router' import { useTheme } from './theme-provider' import { Check } from 'lucide-react' export function UserMenu() { const { clearAuth } = useAuthStore() const teamId = useTeamId() const { data: me } = useQuery({ queryKey: ['teams', teamId, 'me'], queryFn: async () => { const res = await client.api.teams[':teamId'].me.$get({ param: { teamId: teamId! }, }) if (!res.ok) throw new Error('Failed to fetch me') return await res.json() }, enabled: !!teamId, }) const { setTheme, theme } = useTheme() const navigate = useNavigate() const handleLogout = async () => { await signOut() clearAuth() navigate({ to: '/login' }) } const getInitials = (name?: string) => { if (!name) return 'U' const names = name.split(' ') if (names.length > 1) { return `${names[0][0]}${names[names.length - 1][0]}`.toUpperCase() } return name.substring(0, 2).toUpperCase() } return ( {me?.image && ( )} {getInitials(me?.name)} {me && ( <>

{me.name}

{me.role}

)} Theme setTheme('light')} > Light {theme === 'light' && } setTheme('dark')} > Dark {theme === 'dark' && } setTheme('system')} > System {theme === 'system' && } navigate({ to: '/teams/$teamId/settings', params: { teamId: teamId! }, }) } disabled={!teamId} > Settings Log out
) }