Activate realm directly from Realms page

cgen-3ce843d26f7245029ff5ffc74e69adba
This commit is contained in:
Builder.io 2025-10-18 21:30:36 +00:00
parent 94a9c05842
commit cb5512ddd6

View file

@ -4,12 +4,14 @@ import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { REALM_OPTIONS, RealmKey } from "@/components/settings/RealmSwitcher"; import { REALM_OPTIONS, RealmKey } from "@/components/settings/RealmSwitcher";
import { useAuth } from "@/contexts/AuthContext"; import { useAuth } from "@/contexts/AuthContext";
import { useMemo } from "react"; import { useMemo, useState } from "react";
import { Link } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
export default function Realms() { export default function Realms() {
const { profile, roles } = useAuth(); const { profile, roles, updateProfile } = useAuth();
const navigate = useNavigate();
const [activating, setActivating] = useState<string | null>(null);
const lastRealm = (profile as any)?.user_type as RealmKey | undefined; const lastRealm = (profile as any)?.user_type as RealmKey | undefined;
const canSeeStaff = useMemo( const canSeeStaff = useMemo(
() => roles.some((r) => ["owner", "admin", "founder", "staff", "employee"].includes(r.toLowerCase())), () => roles.some((r) => ["owner", "admin", "founder", "staff", "employee"].includes(r.toLowerCase())),
@ -53,10 +55,24 @@ export default function Realms() {
))} ))}
</div> </div>
<div className="pt-2"> <div className="pt-2">
{/* Navigates to dashboard and sets realm via query param */} {active ? (
<Button asChild> <Button disabled variant="outline">Current Realm</Button>
<Link to={`/dashboard?realm=${realm.id}`}>Open Dashboard</Link> ) : (
</Button> <Button
onClick={async () => {
setActivating(realm.id);
try {
await updateProfile({ user_type: realm.id } as any);
navigate("/dashboard", { replace: true });
} finally {
setActivating(null);
}
}}
disabled={activating === realm.id}
>
{activating === realm.id ? "Activating…" : "Activate Realm"}
</Button>
)}
</div> </div>
</CardContent> </CardContent>
{active && ( {active && (