diff --git a/apps/admin/src/lib/api.ts b/apps/admin/src/lib/api.ts index d67b3cf..e8a17c2 100644 --- a/apps/admin/src/lib/api.ts +++ b/apps/admin/src/lib/api.ts @@ -89,6 +89,19 @@ export async function updateContact( if (error) throw new ApiError(error.message); } +/** Delete a single contact (admin-only RLS). Cascades to their registrations. */ +export async function deleteContact(email: string): Promise { + const { error } = await supabase.from('contacts').delete().eq('email', email); + if (error) throw new ApiError(error.message); +} + +/** Delete many contacts at once (admin-only RLS). */ +export async function deleteContacts(emails: string[]): Promise { + if (emails.length === 0) return; + const { error } = await supabase.from('contacts').delete().in('email', emails); + if (error) throw new ApiError(error.message); +} + /** * Regenerate the QR token of a contact's registration for the active event * (syncs the auth password, forces re-login). The token lives on the diff --git a/apps/admin/src/views/Contacts.tsx b/apps/admin/src/views/Contacts.tsx index ef79133..ac1d54c 100644 --- a/apps/admin/src/views/Contacts.tsx +++ b/apps/admin/src/views/Contacts.tsx @@ -1,5 +1,5 @@ import { useEffect, useMemo, useState } from 'react'; -import { adjustPoints, getAllContacts, updateContact, upsertContact } from '../lib/api'; +import { adjustPoints, deleteContact, getAllContacts, updateContact, upsertContact } from '../lib/api'; import type { Contact } from '../lib/types'; import { useToast } from '../context/ToastContext'; import { Avatar, Empty, Modal, Spinner, Toggle } from '../components/ui'; @@ -13,6 +13,7 @@ export function Contacts() { const [editing, setEditing] = useState(null); const [creating, setCreating] = useState(false); const [pointsFor, setPointsFor] = useState(null); + const [deleting, setDeleting] = useState(null); async function load() { try { @@ -22,6 +23,20 @@ export function Contacts() { } } + async function remove(c: Contact) { + if (!confirm(`Delete ${c.full_name} (${c.email})? This also removes their registrations.`)) return; + setDeleting(c.email); + try { + await deleteContact(c.email); + await load(); + push('success', `Deleted ${c.full_name}`); + } catch (e) { + push('error', e instanceof Error ? e.message : 'Delete failed'); + } finally { + setDeleting(null); + } + } + useEffect(() => { load(); }, []); @@ -120,6 +135,13 @@ export function Contacts() { + diff --git a/apps/admin/src/views/Interfaces.tsx b/apps/admin/src/views/Interfaces.tsx index f47d1e6..807f2d9 100644 --- a/apps/admin/src/views/Interfaces.tsx +++ b/apps/admin/src/views/Interfaces.tsx @@ -37,6 +37,8 @@ export function Interfaces() { const [pretixRuns, setPretixRuns] = useState([]); const [pretixRunning, setPretixRunning] = useState(false); const [pretixResult, setPretixResult] = useState(null); + const [sessionizeLogsOpen, setSessionizeLogsOpen] = useState(false); + const [pretixLogsOpen, setPretixLogsOpen] = useState(false); const fileRef = useRef(null); const loadableEvents = events.filter((e) => e.sessionize_endpoint); @@ -346,54 +348,85 @@ export function Interfaces() { - {/* Recent Pretix runs (audit) */} -
-

📜 Recent Pretix runs {selected ? `— ${selected.name}` : ''}

- {pretixRuns.length === 0 ? ( - - ) : ( -
- - - - - - - - - - - - {pretixRuns.map((r) => ( - - - - - - - - ))} - -
StartedFinishedCreatedUpdatedStatus
{fmtTime(r.started_at)}{r.finished_at ? fmtTime(r.finished_at) : '—'}{r.created}{r.updated} - {r.error ? ( - - error - - ) : ( - ok - )} -
-
- )} -
+ {/* Recent Pretix runs (audit) — collapsible, collapsed by default */} + setPretixLogsOpen((v) => !v)} + runs={pretixRuns} + emptyText="No Pretix sync runs recorded for this event yet." + /> - {/* Recent runs (audit) */} -
-

📜 Recent runs {selected ? `— ${selected.name}` : ''}

- {runs.length === 0 ? ( - + {/* Recent Sessionize runs (audit) — collapsible, collapsed by default */} + setSessionizeLogsOpen((v) => !v)} + runs={runs} + emptyText="No sync runs recorded for this event yet." + /> + + {result && setResult(null)} />} + {excelResult && setExcelResult(null)} />} + {pretixResult && setPretixResult(null)} />} +
+ ); +} + +/** A collapsible "recent runs" audit card. Collapsed by default. */ +function CollapsibleRuns({ + icon, + title, + eventName, + open, + onToggle, + runs, + emptyText, +}: { + icon: string; + title: string; + eventName?: string; + open: boolean; + onToggle: () => void; + runs: SyncRun[]; + emptyText: string; +}) { + return ( +
+ + {open && ( + runs.length === 0 ? ( + ) : ( -
+
@@ -425,12 +458,8 @@ export function Interfaces() {
- )} -
- - {result && setResult(null)} />} - {excelResult && setExcelResult(null)} />} - {pretixResult && setPretixResult(null)} />} + ) + )}
); } diff --git a/apps/admin/src/views/Registrations.tsx b/apps/admin/src/views/Registrations.tsx index fd2061f..c595267 100644 --- a/apps/admin/src/views/Registrations.tsx +++ b/apps/admin/src/views/Registrations.tsx @@ -1,7 +1,9 @@ import { useEffect, useMemo, useState } from 'react'; import { createRegistration, + deleteContacts, getAllContacts, + getAllEvents, getActiveEvent, getRegistrations, getSponsors, @@ -17,7 +19,8 @@ const TYPES: RegistrationType[] = ['attendee', 'speaker', 'staff', 'sponsor']; export function Registrations() { const { push } = useToast(); - const [event, setEvent] = useState(null); + const [events, setEvents] = useState([]); + const [selectedId, setSelectedId] = useState(''); const [loaded, setLoaded] = useState(false); const [contacts, setContacts] = useState([]); const [registrations, setRegistrations] = useState([]); @@ -27,16 +30,17 @@ export function Registrations() { const [qrFor, setQrFor] = useState(null); const [sponsorFor, setSponsorFor] = useState(null); const [busy, setBusy] = useState(false); + const [deletingAll, setDeletingAll] = useState(false); + + const event = events.find((e) => e.id === selectedId) ?? null; async function load() { try { - const ev = await getActiveEvent(); - setEvent(ev); - if (ev) { - const [c, r] = await Promise.all([getAllContacts(), getRegistrations(ev.id)]); - setContacts(c); - setRegistrations(r); - } + const [evs, active] = await Promise.all([getAllEvents(), getActiveEvent()]); + setEvents(evs); + // Default to the active event; otherwise the first event. + const def = active?.id ?? evs[0]?.id ?? ''; + setSelectedId((cur) => cur || def); setLoaded(true); } catch (e) { setError(e instanceof Error ? e.message : 'Failed to load'); @@ -47,6 +51,51 @@ export function Registrations() { load(); }, []); + // Load the selected event's contacts + registrations whenever it changes. + useEffect(() => { + if (!selectedId) return; + let cancelled = false; + (async () => { + try { + const [c, r] = await Promise.all([getAllContacts(), getRegistrations(selectedId)]); + if (!cancelled) { + setContacts(c); + setRegistrations(r); + } + } catch (e) { + if (!cancelled) setError(e instanceof Error ? e.message : 'Failed to load'); + } + })(); + return () => { + cancelled = true; + }; + }, [selectedId]); + + async function deleteAllContactsForEvent() { + if (!event) return; + const emails = [...new Set(registrations.map((r) => r.contact_email))]; + if (emails.length === 0) { + push('error', 'No registrations for this event to delete.'); + return; + } + if ( + !confirm( + `Delete ${emails.length} contact(s) registered for "${event.name}"? Their registrations for this event are removed (the contact is deleted entirely).`, + ) + ) + return; + setDeletingAll(true); + try { + await deleteContacts(emails); + await load(); + push('success', `Deleted ${emails.length} contact(s) for ${event.name}`); + } catch (e) { + push('error', e instanceof Error ? e.message : 'Delete failed'); + } finally { + setDeletingAll(false); + } + } + const byEmail = useMemo(() => new Map(contacts.map((c) => [c.email, c])), [contacts]); const filtered = useMemo(() => { @@ -109,11 +158,11 @@ export function Registrations() {

Registrations

-
Ticket types and check-ins for the active event.
+
Ticket types and check-ins per event.
- +
); @@ -125,20 +174,38 @@ export function Registrations() {

Registrations

- {event.name} · {registrations.length} registrations · {registrations.filter((r) => r.checked_in).length} checked in. + {event.name} + {event.is_active && active} ·{' '} + {registrations.length} registrations · {registrations.filter((r) => r.checked_in).length} checked in.
+ setQuery(e.target.value)} /> - +