/* ═══════════════════════════════════════════════════════════════ ADMIN: PROFILE ACCOUNTS (Data → Profile accounts, admins and up) Profile accounts (076) are by invite: an email added here gets an account with no password and a link to set one (or to sign in with Google under that email). The link is shown once, to copy; Email invite sends a fresh one through Gmail and shows it too (the one before stops working). For an account already set up, the same link is a way back in when a password is forgotten. Then: the claims waiting (someone asking to be a People record), and each account's record, Discord and whether it's on. Server side: server/src/routes/profiles.js. Admin accounts (viewer and up) are the Panel's, not this page's. ═══════════════════════════════════════════════════════════════ */ import { useCallback, useEffect, useId, useState, type FormEvent } from "react"; import { ApiError, del, get, patch, post } from "../../lib/api.ts"; import { preview } from "../../lib/text.ts"; const MUTED = "var(--color-muted)"; const button = "btn border border-brand px-3 py-1.5 text-sm text-link transition-colors hover:bg-tint disabled:cursor-default disabled:opacity-50"; const primary = "btn bg-action px-5 py-2.5 text-white transition-colors hover:bg-action-hover disabled:bg-muted/25"; const danger = "btn border border-danger/40 px-3 py-1.5 text-sm text-danger transition-colors hover:bg-danger-tint disabled:opacity-50"; const input = "w-full border border-muted/25 bg-surface px-3 py-2 text-sm text-body outline-none focus:border-brand focus:ring-2 focus:ring-brand/25"; type Account = { id: number; email: string; name: string | null; is_active: number; created_at: string; last_login_at: string | null; invited_at: string | null; invite_expires_at: string | null; invite_open: number; signed_up: number; person_id: string | null; person_name: string | null; discord_id: string | null; discord_name: string | null; }; type Claim = { id: number; account_id: number; email: string; name: string | null; person_id: string; person_name: string; message: string | null; created_at: string; }; const message = (err: unknown) => (err instanceof ApiError ? err.message : "Couldn't reach the server."); const day = (value: string | null) => (value ? value.slice(0, 10) : "-"); /* A link to copy, shown once. */ function LinkBox({ link, note }: { link: string; note: string }) { const [copied, setCopied] = useState(false); return (

{note}

{link}
); } export default function AdminProfiles() { const [data, setData] = useState<{ accounts: Account[]; claims: Claim[]; mail: boolean } | null>(null); const [people, setPeople] = useState<{ id: string; label: string }[]>([]); const [error, setError] = useState(null); const load = useCallback(() => { get("/admin/profiles", { ttl: 0 }) .then(setData) .catch((err) => setError(message(err))); }, []); useEffect(() => { load(); get("/admin/options?only=people", { ttl: 0 }) .then((body) => setPeople(body.options.people)) .catch(() => setPeople([])); }, [load]); return (

Profile accounts

People with an account on the site for their own profile. By invite only.

{error &&

{error}

}

Claims waiting

{!data ? null : data.claims.length === 0 ? (

Nobody is waiting.

) : (
    {data.claims.map((claim) => ( ))}
)}

Accounts

{!data ? (
) : data.accounts.length === 0 ? (

No profile accounts yet. Invite someone above.

) : (
    {data.accounts.map((account) => ( ))}
)}
); } function Invite({ mail, onDone }: { mail: boolean; onDone: () => void }) { const emailId = useId(); const nameId = useId(); const [email, setEmail] = useState(""); const [name, setName] = useState(""); const [made, setMade] = useState<{ id: number; email: string; link: string } | null>(null); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); async function submit(event: FormEvent) { event.preventDefault(); setBusy(true); setError(null); try { const result = await post("/admin/profiles", { email, name }); setMade({ id: result.id, email: email.trim().toLowerCase(), link: result.link }); setEmail(""); setName(""); onDone(); } catch (err) { setError(message(err)); } finally { setBusy(false); } } return (

Invite someone

setEmail(e.target.value)} className={`mt-1 ${input}`} />
setName(e.target.value)} className={`mt-1 ${input}`} />

They can sign in with a password from the link, or with Google under this email (any Google account).

{error &&

{error}

} {made && ( <> {mail && setMade({ ...made, link })} />} )}
); } /* Email a fresh link (the last one stops working). */ function EmailInvite({ id, label, onDone }: { id: number; label: string; onDone: (link: string) => void }) { const [state, setState] = useState<"idle" | "busy" | "sent" | string>("idle"); return (
{state === "sent" && Sent. The link above is the one in the email.} {!["idle", "busy", "sent"].includes(state) && {state}}
); } function ClaimRow({ claim, onDone }: { claim: Claim; onDone: () => void }) { const [error, setError] = useState(null); const [busy, setBusy] = useState(false); async function decide(answer: "approve" | "decline") { setBusy(true); setError(null); try { await post(`/admin/profiles/claims/${claim.id}/${answer}`, {}); onDone(); } catch (err) { setError(message(err)); setBusy(false); } } return (
  • {claim.name || claim.email} {claim.name && ({claim.email})} asks to be{" "} {claim.person_name} {" "} · {day(claim.created_at)}

    {claim.message &&

    “{preview(claim.message, 300)}”

    } {error &&

    {error}

    }
  • ); } function AccountRow({ account, people, mail, onDone, }: { account: Account; people: { id: string; label: string }[]; mail: boolean; onDone: () => void; }) { const personId = useId(); const discordId = useId(); const discordName = useId(); const [person, setPerson] = useState(account.person_id ?? ""); const [discord, setDiscord] = useState(account.discord_id ?? ""); const [discordLabel, setDiscordLabel] = useState(account.discord_name ?? ""); const [link, setLink] = useState(null); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); async function run(action: () => Promise) { setBusy(true); setError(null); try { await action(); onDone(); } catch (err) { setError(message(err)); } finally { setBusy(false); } } const status = !account.is_active ? "Turned off" : account.signed_up ? `Signed up · last in ${day(account.last_login_at)}` : account.invite_open ? `Invited · link works until ${day(account.invite_expires_at)}` : "Invited · link expired"; return (
  • {account.name || account.email} {account.name && {account.email}} {status} Profile: {account.person_name ?? "-"} Discord: {account.discord_name ?? account.discord_id ?? "-"}
    setDiscord(e.target.value)} className={`mt-1 ${input}`} />
    setDiscordLabel(e.target.value)} className={`mt-1 ${input}`} />

    They link it themselves from their profile; this overrides it. The ID is the long number from Discord (Developer Mode, then Copy User ID), eg. 80351110224678912. Blank unlinks it.

    {mail && ( )}
    {link && ( )} {error &&

    {error}

    }
  • ); }