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
This commit is contained in:
1 parent
c7d095aff7
commit
98f65e8665
4 files changed
+196
-65
No files matched your search
@@ -89,6 +89,19 @@ export async function updateContact(
|
|||||||
if (error) throw new ApiError(error.message);
|
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
|
* 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
|
* (syncs the auth password, forces re-login). The token lives on the
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useEffect, useMemo, useState } from 'react';
|
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 type { Contact } from '../lib/types';
|
||||||
import { useToast } from '../context/ToastContext';
|
import { useToast } from '../context/ToastContext';
|
||||||
import { Avatar, Empty, Modal, Spinner, Toggle } from '../components/ui';
|
import { Avatar, Empty, Modal, Spinner, Toggle } from '../components/ui';
|
||||||
@@ -13,6 +13,7 @@ export function Contacts() {
|
|||||||
const [editing, setEditing] = useState<Contact | null>(null);
|
const [editing, setEditing] = useState<Contact | null>(null);
|
||||||
const [creating, setCreating] = useState(false);
|
const [creating, setCreating] = useState(false);
|
||||||
const [pointsFor, setPointsFor] = useState<Contact | null>(null);
|
const [pointsFor, setPointsFor] = useState<Contact | null>(null);
|
||||||
|
const [deleting, setDeleting] = useState<string | null>(null);
|
||||||
|
|
||||||
async function load() {
|
async function load() {
|
||||||
try {
|
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(() => {
|
useEffect(() => {
|
||||||
load();
|
load();
|
||||||
}, []);
|
}, []);
|
||||||
@@ -120,6 +135,13 @@ export function Contacts() {
|
|||||||
<button className="btn small" onClick={() => setPointsFor(c)}>
|
<button className="btn small" onClick={() => setPointsFor(c)}>
|
||||||
Points
|
Points
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
className="btn small danger"
|
||||||
|
disabled={deleting === c.email}
|
||||||
|
onClick={() => remove(c)}
|
||||||
|
>
|
||||||
|
{deleting === c.email ? 'Deleting…' : 'Delete'}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ export function Interfaces() {
|
|||||||
const [pretixRuns, setPretixRuns] = useState<SyncRun[]>([]);
|
const [pretixRuns, setPretixRuns] = useState<SyncRun[]>([]);
|
||||||
const [pretixRunning, setPretixRunning] = useState(false);
|
const [pretixRunning, setPretixRunning] = useState(false);
|
||||||
const [pretixResult, setPretixResult] = useState<PretixSyncResult | null>(null);
|
const [pretixResult, setPretixResult] = useState<PretixSyncResult | null>(null);
|
||||||
|
const [sessionizeLogsOpen, setSessionizeLogsOpen] = useState(false);
|
||||||
|
const [pretixLogsOpen, setPretixLogsOpen] = useState(false);
|
||||||
const fileRef = useRef<HTMLInputElement>(null);
|
const fileRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
const loadableEvents = events.filter((e) => e.sessionize_endpoint);
|
const loadableEvents = events.filter((e) => e.sessionize_endpoint);
|
||||||
@@ -346,54 +348,85 @@ export function Interfaces() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Recent Pretix runs (audit) */}
|
{/* Recent Pretix runs (audit) — collapsible, collapsed by default */}
|
||||||
<div className="card" style={{ marginBottom: 18 }}>
|
<CollapsibleRuns
|
||||||
<h2 className="h2">📜 Recent Pretix runs {selected ? `— ${selected.name}` : ''}</h2>
|
icon="🎟"
|
||||||
{pretixRuns.length === 0 ? (
|
title="Recent Pretix runs"
|
||||||
<Empty icon="🎟" text="No Pretix sync runs recorded for this event yet." />
|
eventName={selected?.name}
|
||||||
) : (
|
open={pretixLogsOpen}
|
||||||
<div className="table-wrap">
|
onToggle={() => setPretixLogsOpen((v) => !v)}
|
||||||
<table className="data">
|
runs={pretixRuns}
|
||||||
<thead>
|
emptyText="No Pretix sync runs recorded for this event yet."
|
||||||
<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 runs (audit) */}
|
{/* Recent Sessionize runs (audit) — collapsible, collapsed by default */}
|
||||||
<div className="card">
|
<CollapsibleRuns
|
||||||
<h2 className="h2">📜 Recent runs {selected ? `— ${selected.name}` : ''}</h2>
|
icon="📜"
|
||||||
{runs.length === 0 ? (
|
title="Recent runs"
|
||||||
<Empty icon="📜" text="No sync runs recorded for this event yet." />
|
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">
|
<table className="data">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -425,13 +458,9 @@ export function Interfaces() {
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
)}
|
)}
|
||||||
</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 { useEffect, useMemo, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
createRegistration,
|
createRegistration,
|
||||||
|
deleteContacts,
|
||||||
getAllContacts,
|
getAllContacts,
|
||||||
|
getAllEvents,
|
||||||
getActiveEvent,
|
getActiveEvent,
|
||||||
getRegistrations,
|
getRegistrations,
|
||||||
getSponsors,
|
getSponsors,
|
||||||
@@ -17,7 +19,8 @@ const TYPES: RegistrationType[] = ['attendee', 'speaker', 'staff', 'sponsor'];
|
|||||||
|
|
||||||
export function Registrations() {
|
export function Registrations() {
|
||||||
const { push } = useToast();
|
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 [loaded, setLoaded] = useState(false);
|
||||||
const [contacts, setContacts] = useState<Contact[]>([]);
|
const [contacts, setContacts] = useState<Contact[]>([]);
|
||||||
const [registrations, setRegistrations] = useState<Registration[]>([]);
|
const [registrations, setRegistrations] = useState<Registration[]>([]);
|
||||||
@@ -27,16 +30,17 @@ export function Registrations() {
|
|||||||
const [qrFor, setQrFor] = useState<Registration | null>(null);
|
const [qrFor, setQrFor] = useState<Registration | null>(null);
|
||||||
const [sponsorFor, setSponsorFor] = useState<Registration | null>(null);
|
const [sponsorFor, setSponsorFor] = useState<Registration | null>(null);
|
||||||
const [busy, setBusy] = useState(false);
|
const [busy, setBusy] = useState(false);
|
||||||
|
const [deletingAll, setDeletingAll] = useState(false);
|
||||||
|
|
||||||
|
const event = events.find((e) => e.id === selectedId) ?? null;
|
||||||
|
|
||||||
async function load() {
|
async function load() {
|
||||||
try {
|
try {
|
||||||
const ev = await getActiveEvent();
|
const [evs, active] = await Promise.all([getAllEvents(), getActiveEvent()]);
|
||||||
setEvent(ev);
|
setEvents(evs);
|
||||||
if (ev) {
|
// Default to the active event; otherwise the first event.
|
||||||
const [c, r] = await Promise.all([getAllContacts(), getRegistrations(ev.id)]);
|
const def = active?.id ?? evs[0]?.id ?? '';
|
||||||
setContacts(c);
|
setSelectedId((cur) => cur || def);
|
||||||
setRegistrations(r);
|
|
||||||
}
|
|
||||||
setLoaded(true);
|
setLoaded(true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setError(e instanceof Error ? e.message : 'Failed to load');
|
setError(e instanceof Error ? e.message : 'Failed to load');
|
||||||
@@ -47,6 +51,51 @@ export function Registrations() {
|
|||||||
load();
|
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 byEmail = useMemo(() => new Map(contacts.map((c) => [c.email, c])), [contacts]);
|
||||||
|
|
||||||
const filtered = useMemo(() => {
|
const filtered = useMemo(() => {
|
||||||
@@ -109,11 +158,11 @@ export function Registrations() {
|
|||||||
<div className="page-head">
|
<div className="page-head">
|
||||||
<div>
|
<div>
|
||||||
<h1>Registrations</h1>
|
<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>
|
</div>
|
||||||
<div className="card">
|
<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>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -125,20 +174,38 @@ export function Registrations() {
|
|||||||
<div>
|
<div>
|
||||||
<h1>Registrations</h1>
|
<h1>Registrations</h1>
|
||||||
<div className="sub">
|
<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>
|
</div>
|
||||||
<div className="row" style={{ gap: 10 }}>
|
<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
|
<input
|
||||||
className="input"
|
className="input"
|
||||||
style={{ maxWidth: 240 }}
|
style={{ maxWidth: 220 }}
|
||||||
placeholder="Search name, email, type…"
|
placeholder="Search name, email, type…"
|
||||||
value={query}
|
value={query}
|
||||||
onChange={(e) => setQuery(e.target.value)}
|
onChange={(e) => setQuery(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<button className="btn primary" onClick={() => setAdding(true)}>
|
<button className="btn" onClick={() => setAdding(true)}>
|
||||||
+ Register
|
+ Register
|
||||||
</button>
|
</button>
|
||||||
|
<button className="btn danger" disabled={deletingAll} onClick={deleteAllContactsForEvent}>
|
||||||
|
{deletingAll ? 'Deleting…' : '🗑 Delete all contacts for this event'}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user