import * as DropdownMenu from '@radix-ui/react-dropdown-menu'; import classNames from 'classnames'; import { motion } from 'framer-motion'; import { useMemo, useState } from 'react'; import { ChatUsageDialog } from '~/components/chat/usage/ChatUsageDialog'; import { DeploymentRecordsDialog } from '~/components/chat/usage/DeploymentRecordsDialog'; import { Button } from '~/components/ui/Button'; import { ConfirmationDialog } from '~/components/ui/Dialog'; import { useAuth } from '~/lib/hooks/useAuth'; import { useChatUsage } from '~/lib/hooks/useChatUsage'; interface MinimalAvatarDropdownProps {} export const MinimalAvatarDropdown = ({}: MinimalAvatarDropdownProps) => { const { userInfo, isAuthenticated, signOut, signIn } = useAuth(); const { usageStats } = useChatUsage(); if (!isAuthenticated) { return ( ); } const displayName = useMemo(() => { if (!isAuthenticated || !userInfo) { return 'Guest User'; } return userInfo.name || userInfo.username; }, [userInfo]); const contactInfo = useMemo(() => { if (!isAuthenticated || !userInfo) { return null; } if (userInfo.phone_number) { return `+${userInfo.phone_number}`; } return userInfo.email; }, [userInfo]); const avatarUrl = isAuthenticated && userInfo?.picture ? userInfo.picture : ''; const [showLogoutConfirm, setShowLogoutConfirm] = useState(false); const [showUsageDialog, setShowUsageDialog] = useState(false); const [showDeploymentRecordsDialog, setShowDeploymentRecordsDialog] = useState(false); return ( <> setShowUsageDialog(false)} /> setShowDeploymentRecordsDialog(false)} /> setShowLogoutConfirm(false)} title="退出登录?" description="退出登录后,您需要重新登录才能继续使用。" confirmLabel="退出登录" cancelLabel="取消" variant="destructive" onConfirm={() => signOut()} /> {avatarUrl ? ( {displayName} ) : (
)}
{Boolean(avatarUrl) ? ( {displayName} ) : (
)}
{displayName}
{!!userInfo?.email && (
{contactInfo}
)}
setShowUsageDialog(true)} >
API 使用量
{usageStats && (
{usageStats.total._count}
)} setShowDeploymentRecordsDialog(true)} >
部署记录
setShowLogoutConfirm(true)} >
退出登录 ); };