refactor(auth): unify current user state usage across UI

This commit is contained in:
zetaloop
2026-02-22 08:03:09 +08:00
parent 7bcb73f139
commit 312061330c
8 changed files with 47 additions and 44 deletions
+6 -7
View File
@@ -11,12 +11,11 @@ import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
import { Separator } from "@/components/ui/separator"
import { Switch } from "@/components/ui/switch"
import { Textarea } from "@/components/ui/textarea"
import { currentUser } from "@/lib/mock"
import type { UserRole } from "@/lib/types"
import { useAuthStore } from "@/store/auth"
export default function SettingsPage() {
const { currentRole, verifiedRoles, switchRole } = useAuthStore()
const { currentRole, verifiedRoles, switchRole, user } = useAuthStore()
const isRoleVerified = (role: UserRole) => verifiedRoles.includes(role)
@@ -31,8 +30,8 @@ export default function SettingsPage() {
<CardContent className="flex items-center gap-4">
<div className="relative">
<Avatar className="h-20 w-20">
<AvatarImage src={currentUser.avatar} />
<AvatarFallback className="text-lg">{currentUser.nickname[0]}</AvatarFallback>
<AvatarImage src={user?.avatar} />
<AvatarFallback className="text-lg">{user?.nickname?.[0] ?? "?"}</AvatarFallback>
</Avatar>
<button
type="button"
@@ -52,15 +51,15 @@ export default function SettingsPage() {
<CardContent className="space-y-4">
<div className="space-y-2">
<Label htmlFor="nickname"></Label>
<Input id="nickname" defaultValue={currentUser.nickname} />
<Input id="nickname" defaultValue={user?.nickname ?? ""} />
</div>
<div className="space-y-2">
<Label htmlFor="bio"></Label>
<Textarea id="bio" defaultValue={currentUser.bio} rows={3} />
<Textarea id="bio" defaultValue={user?.bio ?? ""} rows={3} />
</div>
<div className="space-y-2">
<Label htmlFor="phone"></Label>
<Input id="phone" defaultValue={currentUser.phone} disabled />
<Input id="phone" defaultValue={user?.phone ?? ""} disabled />
<p className="text-xs text-muted-foreground"></p>
</div>
<Button></Button>