Make Realms page auth-aware actions

cgen-c5fe0daa914041348af9840fdd302532
This commit is contained in:
Builder.io 2025-10-18 21:40:21 +00:00
parent 567393bfcb
commit 0777188c1a

View file

@ -9,7 +9,7 @@ import { useNavigate } from "react-router-dom";
import { cn } from "@/lib/utils";
export default function Realms() {
const { profile, roles, updateProfile } = useAuth();
const { user, profile, roles, updateProfile } = useAuth();
const navigate = useNavigate();
const [activating, setActivating] = useState<string | null>(null);
const [selectedRealm, setSelectedRealm] = useState<RealmKey | null>((profile as any)?.user_type ?? null);
@ -44,9 +44,14 @@ export default function Realms() {
hasChanges={selectedRealm !== ((profile as any)?.user_type ?? null) || experience !== ((profile as any)?.experience_level || "beginner")}
onSave={async () => {
if (!selectedRealm) return;
if (!user) {
navigate("/onboarding");
return;
}
setSaving(true);
try {
await updateProfile({ user_type: selectedRealm, experience_level: experience } as any);
navigate("/dashboard", { replace: true });
} finally {
setSaving(false);
}
@ -56,7 +61,7 @@ export default function Realms() {
</div>
<div className="mt-6 flex justify-end">
<Button onClick={() => navigate("/dashboard")}>Open Dashboard</Button>
<Button onClick={() => navigate(user ? "/dashboard" : "/onboarding")}>{user ? "Open Dashboard" : "Start Onboarding"}</Button>
</div>
</div>
</Layout>