import { client } from '@/ui/api/client' import { Avatar, AvatarFallback } from '@/ui/components/ui/avatar' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } 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' 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 } = 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 ( {getInitials(me?.name)} {me && ( <>

{me.name}

{me.role}

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