import { client } from '@/ui/api/client' import { Avatar, AvatarFallback, AvatarImage } from '@/ui/components/ui/avatar' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, 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 { Check } from 'lucide-react' import { APP_VERSION } from '../version' import { useTheme } from './theme-provider' import { m } from '@/ui/paraglide/messages.js' const Github = (props: React.SVGProps) => ( ) export function UserMenu() { const { clearAuth } = useAuthStore() const teamId = useTeamId() const localizeRole = (role?: string) => { if (!role) return '' switch (role.toLowerCase()) { case 'owner': return m.owner() case 'editor': return m.editor() case 'reviewer': return m.reviewer() default: return role } } 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}

{localizeRole(me.role)}

)} {m.theme()} setTheme('light')} > {m.light()} {theme === 'light' && } setTheme('dark')} > {m.dark()} {theme === 'dark' && } setTheme('system')} > {m.system()} {theme === 'system' && } navigate({ to: '/teams/$teamId/settings', params: { teamId: teamId! }, }) } disabled={!teamId} > {m.settings()} {m.log_out()} window.open('https://github.com/shumaiOne/shumai', '_blank', 'noopener,noreferrer') } > {m.version({ version: APP_VERSION })}
) }