/* ═══════════════════════════════════════════════════════════════ YOUR PROFILE: /account, a profile account's page (076) Your account who's signed in, sign out (and the admin, for an admin account) Your profile before a record is theirs: ask to claim one (an admin approves it); after: edit its text and photo, and choose what of it shows on the site Discord link it (or unlink), for the gamification to come Signed out, it's the sign-in page's job. Everything is saved through routes/account.js, which only ever writes the account's own person. ═══════════════════════════════════════════════════════════════ */ import { useEffect, useState } from 'react' import { Link, Navigate, useSearchParams } from 'react-router-dom' import { ArrowSquareOut, SignOut } from '@phosphor-icons/react' import PageShell from '../components/PageShell.tsx' import { useAuth } from '../lib/auth.tsx' import { ApiError, del, get, patch, post, upload } from '../lib/api.ts' import { ACCENTS, BRAND } from '../lib/color.ts' import { mediaUrl } from '../lib/media.ts' import { personHref } from '../lib/hrefs.ts' import { ROLE_LABELS, isStaff, type Role } from '../lib/roles.ts' import { HIDE_FIELDS, useMyAccount, type MyAccount, type MyPerson } from '../lib/useAccount.ts' import { fieldClass, primaryButton } from './SignIn.tsx' const quietButton = 'btn border border-brand px-5 py-2.5 text-link transition-colors hover:bg-tint focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand/40 disabled:cursor-not-allowed disabled:opacity-60' /* What ?discord= says after the trip to Discord (routes/account.js). */ const DISCORD_RESULTS: Record = { linked: 'Your Discord account is linked.', canceled: 'Linking Discord was canceled.', expired: 'That took too long. Try again.', taken: 'That Discord account is already linked to another profile.', failed: "Discord didn't link. Try again in a moment.", } const message = (err: unknown) => err instanceof ApiError ? err.message : "Couldn't reach the server. Try again in a moment." function Alert({ children, tone = 'danger' }: { children: React.ReactNode; tone?: 'danger' | 'ok' }) { return (

{children}

) } export default function Account() { const { user, loading, logout } = useAuth() const { data, error, reload } = useMyAccount(Boolean(user)) if (loading) return null if (!user) return const content = (part: React.ReactNode) =>
{part}
return (

{user.name || user.email}

{user.email} · {ROLE_LABELS[user.role as Role] ?? user.role}

{isStaff(user) && ( Admin )}
, ), }, { id: 'profile', title: 'Your profile', blurb: 'Your page on the site, eg. on a team or an event. Ask for yours, then edit it here.', accent: ACCENTS.green, content: content( error ? (

Couldn't load your profile. {error}

) : !data ? (
) : data.person ? ( ) : ( ), ), }, { id: 'discord', title: 'Discord', blurb: 'Link your Discord account so what you do there can count here.', accent: ACCENTS.amber, content: content(data ? : null), }, ]} /> ) } /* ── Claiming a record ───────────────────────────────────────── */ function Claim({ account, onChange }: { account: MyAccount; onChange: () => void }) { const [people, setPeople] = useState<{ id: string; name: string }[] | null>(null) const [personId, setPersonId] = useState('') const [note, setNote] = useState('') const [error, setError] = useState(null) const [busy, setBusy] = useState(false) const pending = account.claim?.status === 'pending' ? account.claim : null useEffect(() => { if (pending) return get('/account/people', { ttl: 0 }) .then((data) => setPeople(data.people)) .catch((err) => setError(message(err))) }, [pending]) async function run(action: () => Promise) { setBusy(true) setError(null) try { await action() onChange() } catch (err) { setError(message(err)) } finally { setBusy(false) } } if (pending) { return (

You asked to be {pending.display_name}. An admin will look at it soon.

{error && {error}}
) } return (
{ e.preventDefault() run(() => post('/account/claim', { person_id: personId, message: note })) }} className="bg-raised p-6 shadow-md" > {account.claim?.status === 'declined' && (

Your request to be {account.claim.display_name} wasn't approved. Pick again, or say more in the note.

)}

Not listed? Ask us through the Request page to add you.