forked from
joebasser.com/atmosphere-account
this repo has no description
1import { useSignal } from "@preact/signals";
2
3interface Props {
4 did: string;
5 label: string;
6 doneLabel: string;
7 errorPrefix: string;
8}
9
10/**
11 * Compact one-click verifier for existing profiles in the admin roster.
12 * The request queue keeps its richer Grant/Deny row; this is for profiles
13 * that simply have not been verified yet.
14 */
15export default function AdminIconAccessVerifyButton(p: Props) {
16 const status = useSignal<
17 | { kind: "idle" }
18 | { kind: "submitting" }
19 | { kind: "done" }
20 | { kind: "error"; text: string }
21 >({ kind: "idle" });
22
23 const onClick = async () => {
24 status.value = { kind: "submitting" };
25 try {
26 const r = await fetch(
27 `/api/admin/icon-access/${encodeURIComponent(p.did)}/grant`,
28 { method: "POST" },
29 );
30 if (!r.ok) throw new Error(await r.text());
31 status.value = { kind: "done" };
32 } catch (err) {
33 status.value = {
34 kind: "error",
35 text: err instanceof Error ? err.message : String(err),
36 };
37 }
38 };
39
40 if (status.value.kind === "done") {
41 return (
42 <span class="admin-status-badge admin-status-badge--approved">
43 {p.doneLabel}
44 </span>
45 );
46 }
47
48 const submitting = status.value.kind === "submitting";
49
50 return (
51 <>
52 <button
53 type="button"
54 class="profile-form-button-primary"
55 onClick={onClick}
56 disabled={submitting}
57 >
58 {submitting ? "..." : p.label}
59 </button>
60 {status.value.kind === "error" && (
61 <p class="admin-icon-row-error">
62 {p.errorPrefix}: {status.value.text}
63 </p>
64 )}
65 </>
66 );
67}