Admin: per-event registrations view, contact deletion, collapsible interface logs
- Registrations: event selector dropdown (default = active event), event name shown prominently in header with active badge, 'Delete all contacts for this event' action (deletes the contacts registered for the selected event) - Contacts: per-row Delete button (with confirm; cascades to registrations) - Interfaces: Sessionize + Pretix 'Recent runs' tables now in per-interface collapsibles, collapsed by default - api: deleteContact + deleteContacts helpers Co-authored-by: Stephan Charles <[email protected]> Co-authored-by: Amelia Hernandez <[email protected]> Co-authored-by: Markus Franz <[email protected]> Co-authored-by: Sabrina Hota <[email protected]> Co-authored-by: Nilüfer Doğan <[email protected]>
This commit is contained in:
1 parent
509e342204
commit
a1fd108e4c
4 files changed
+197
-66
No files matched your search
@@ -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<void> {
|
||||
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<void> {
|
||||
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
|
||||
|
||||
@@ -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<Contact | null>(null);
|
||||
const [creating, setCreating] = useState(false);
|
||||
const [pointsFor, setPointsFor] = useState<Contact | null>(null);
|
||||
const [deleting, setDeleting] = useState<string | null>(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() {
|
||||
<button className="btn small" onClick={() => setPointsFor(c)}>
|
||||
Points
|
||||
</button>
|
||||
<button
|
||||
className="btn small danger"
|
||||
disabled={deleting === c.email}
|
||||
onClick={() => remove(c)}
|
||||
>
|
||||
{deleting === c.email ? 'Deleting…' : 'Delete'}
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -37,6 +37,8 @@ export function Interfaces() {
|
||||
const [pretixRuns, setPretixRuns] = useState<SyncRun[]>([]);
|
||||
const [pretixRunning, setPretixRunning] = useState(false);
|
||||
const [pretixResult, setPretixResult] = useState<PretixSyncResult | null>(null);
|
||||
const [sessionizeLogsOpen, setSessionizeLogsOpen] = useState(false);
|
||||
const [pretixLogsOpen, setPretixLogsOpen] = useState(false);
|
||||
const fileRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const loadableEvents = events.filter((e) => e.sessionize_endpoint);
|
||||
@@ -346,54 +348,85 @@ export function Interfaces() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Recent Pretix runs (audit) */}
|
||||
<div className="card" style={{ marginBottom: 18 }}>
|
||||
<h2 className="h2">📜 Recent Pretix runs {selected ? `— ${selected.name}` : ''}</h2>
|
||||
{pretixRuns.length === 0 ? (
|
||||
<Empty icon="🎟" text="No Pretix sync runs recorded for this event yet." />
|
||||
) : (
|
||||
<div className="table-wrap">
|
||||
<table className="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Started</th>
|
||||
<th>Finished</th>
|
||||
<th>Created</th>
|
||||
<th>Updated</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{pretixRuns.map((r) => (
|
||||
<tr key={r.id}>
|
||||
<td className="muted">{fmtTime(r.started_at)}</td>
|
||||
<td className="muted">{r.finished_at ? fmtTime(r.finished_at) : '—'}</td>
|
||||
<td className="muted">{r.created}</td>
|
||||
<td className="muted">{r.updated}</td>
|
||||
<td>
|
||||
{r.error ? (
|
||||
<span className="pill red" title={r.error}>
|
||||
error
|
||||
</span>
|
||||
) : (
|
||||
<span className="pill green">ok</span>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{/* Recent Pretix runs (audit) — collapsible, collapsed by default */}
|
||||
<CollapsibleRuns
|
||||
icon="🎟"
|
||||
title="Recent Pretix runs"
|
||||
eventName={selected?.name}
|
||||
open={pretixLogsOpen}
|
||||
onToggle={() => setPretixLogsOpen((v) => !v)}
|
||||
runs={pretixRuns}
|
||||
emptyText="No Pretix sync runs recorded for this event yet."
|
||||
/>
|
||||
|
||||
{/* Recent runs (audit) */}
|
||||
<div className="card">
|
||||
<h2 className="h2">📜 Recent runs {selected ? `— ${selected.name}` : ''}</h2>
|
||||
{runs.length === 0 ? (
|
||||
<Empty icon="📜" text="No sync runs recorded for this event yet." />
|
||||
{/* Recent Sessionize runs (audit) — collapsible, collapsed by default */}
|
||||
<CollapsibleRuns
|
||||
icon="📜"
|
||||
title="Recent runs"
|
||||
eventName={selected?.name}
|
||||
open={sessionizeLogsOpen}
|
||||
onToggle={() => setSessionizeLogsOpen((v) => !v)}
|
||||
runs={runs}
|
||||
emptyText="No sync runs recorded for this event yet."
|
||||
/>
|
||||
|
||||
{result && <SyncResultModal result={result} onClose={() => setResult(null)} />}
|
||||
{excelResult && <ExcelResultModal result={excelResult} onClose={() => setExcelResult(null)} />}
|
||||
{pretixResult && <PretixResultModal result={pretixResult} onClose={() => setPretixResult(null)} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** 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 (
|
||||
<div className="card" style={{ marginBottom: 18 }}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onToggle}
|
||||
style={{
|
||||
display: 'flex',
|
||||
width: '100%',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
gap: 10,
|
||||
background: 'none',
|
||||
border: 'none',
|
||||
cursor: 'pointer',
|
||||
padding: 0,
|
||||
textAlign: 'left',
|
||||
}}
|
||||
aria-expanded={open}
|
||||
>
|
||||
<h2 className="h2" style={{ margin: 0 }}>
|
||||
{icon} {title}
|
||||
{eventName ? ` — ${eventName}` : ''}
|
||||
</h2>
|
||||
<span className="muted small" style={{ whiteSpace: 'nowrap' }}>
|
||||
{runs.length} run{runs.length === 1 ? '' : 's'} {open ? '▾' : '▸'}
|
||||
</span>
|
||||
</button>
|
||||
{open && (
|
||||
runs.length === 0 ? (
|
||||
<Empty icon={icon} text={emptyText} />
|
||||
) : (
|
||||
<div className="table-wrap">
|
||||
<div className="table-wrap" style={{ marginTop: 12 }}>
|
||||
<table className="data">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -425,12 +458,8 @@ export function Interfaces() {
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{result && <SyncResultModal result={result} onClose={() => setResult(null)} />}
|
||||
{excelResult && <ExcelResultModal result={excelResult} onClose={() => setExcelResult(null)} />}
|
||||
{pretixResult && <PretixResultModal result={pretixResult} onClose={() => setPretixResult(null)} />}
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<Event | null>(null);
|
||||
const [events, setEvents] = useState<Event[]>([]);
|
||||
const [selectedId, setSelectedId] = useState('');
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
const [contacts, setContacts] = useState<Contact[]>([]);
|
||||
const [registrations, setRegistrations] = useState<Registration[]>([]);
|
||||
@@ -27,16 +30,17 @@ export function Registrations() {
|
||||
const [qrFor, setQrFor] = useState<Registration | null>(null);
|
||||
const [sponsorFor, setSponsorFor] = useState<Registration | null>(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() {
|
||||
<div className="page-head">
|
||||
<div>
|
||||
<h1>Registrations</h1>
|
||||
<div className="sub">Ticket types and check-ins for the active event.</div>
|
||||
<div className="sub">Ticket types and check-ins per event.</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="card">
|
||||
<Empty icon="📅" text="No active event. Set an event active in the Events view first." />
|
||||
<Empty icon="📅" text="No events yet. Create one in the Events view first." />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -125,20 +174,38 @@ export function Registrations() {
|
||||
<div>
|
||||
<h1>Registrations</h1>
|
||||
<div className="sub">
|
||||
{event.name} · {registrations.length} registrations · {registrations.filter((r) => r.checked_in).length} checked in.
|
||||
<strong>{event.name}</strong>
|
||||
{event.is_active && <span className="pill green" style={{ marginLeft: 8 }}>active</span>} ·{' '}
|
||||
{registrations.length} registrations · {registrations.filter((r) => r.checked_in).length} checked in.
|
||||
</div>
|
||||
</div>
|
||||
<div className="row" style={{ gap: 10 }}>
|
||||
<select
|
||||
className="input"
|
||||
style={{ maxWidth: 280 }}
|
||||
value={selectedId}
|
||||
onChange={(e) => setSelectedId(e.target.value)}
|
||||
>
|
||||
{events.map((e) => (
|
||||
<option key={e.id} value={e.id}>
|
||||
{e.name}
|
||||
{e.is_active ? ' (active)' : ''}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<input
|
||||
className="input"
|
||||
style={{ maxWidth: 240 }}
|
||||
style={{ maxWidth: 220 }}
|
||||
placeholder="Search name, email, type…"
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
/>
|
||||
<button className="btn primary" onClick={() => setAdding(true)}>
|
||||
<button className="btn" onClick={() => setAdding(true)}>
|
||||
+ Register
|
||||
</button>
|
||||
<button className="btn danger" disabled={deletingAll} onClick={deleteAllContactsForEvent}>
|
||||
{deletingAll ? 'Deleting…' : '🗑 Delete all contacts for this event'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in new issue
Block a user