fix: require verification before role switch in settings

This commit is contained in:
zetaloop
2026-02-20 20:02:49 +08:00
parent e92657d0dd
commit 104e7c5291
+47 -8
View File
@@ -1,6 +1,7 @@
"use client"
import { Camera } from "lucide-react"
import Link from "next/link"
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
@@ -11,10 +12,13 @@ import { Separator } from "@/components/ui/separator"
import { Switch } from "@/components/ui/switch"
import { Textarea } from "@/components/ui/textarea"
import { currentUser } from "@/lib/mock-data"
import type { UserRole } from "@/lib/types"
import { useAuthStore } from "@/store/auth"
export default function SettingsPage() {
const { currentRole, switchRole } = useAuthStore()
const { currentRole, verifiedRoles, switchRole } = useAuthStore()
const isRoleVerified = (role: UserRole) => verifiedRoles.includes(role)
return (
<div className="max-w-2xl space-y-6">
@@ -68,22 +72,57 @@ export default function SettingsPage() {
<CardTitle className="text-base"></CardTitle>
</CardHeader>
<CardContent className="space-y-3">
<p className="text-sm text-muted-foreground"></p>
<p className="text-sm text-muted-foreground">,</p>
<RadioGroup
value={currentRole}
onValueChange={(v) => switchRole(v as "consumer" | "player" | "owner")}
onValueChange={(v) => {
const role = v as UserRole
if (isRoleVerified(role)) {
switchRole(role)
}
}}
>
<div className="flex items-center justify-between">
<div className="flex items-center space-x-2">
<RadioGroupItem value="consumer" id="role-consumer" />
<Label htmlFor="role-consumer"></Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="player" id="role-player" />
<Label htmlFor="role-player"></Label>
</div>
<div className="flex items-center justify-between">
<div className="flex items-center space-x-2">
<RadioGroupItem value="owner" id="role-owner" />
<Label htmlFor="role-owner"></Label>
<RadioGroupItem
value="player"
id="role-player"
disabled={!isRoleVerified("player")}
/>
<Label
htmlFor="role-player"
className={!isRoleVerified("player") ? "text-muted-foreground" : ""}
>
</Label>
</div>
{!isRoleVerified("player") && (
<Link href="/verify" className="text-sm text-primary hover:underline">
</Link>
)}
</div>
<div className="flex items-center justify-between">
<div className="flex items-center space-x-2">
<RadioGroupItem value="owner" id="role-owner" disabled={!isRoleVerified("owner")} />
<Label
htmlFor="role-owner"
className={!isRoleVerified("owner") ? "text-muted-foreground" : ""}
>
</Label>
</div>
{!isRoleVerified("owner") && (
<Link href="/verify" className="text-sm text-primary hover:underline">
</Link>
)}
</div>
</RadioGroup>
</CardContent>