- Phase 3: new migration 20260824000000_redesign.sql (contacts/events/registrations/sponsors, slot types, session speakers + feedback/material), seed rewrite - Phase 4: APPE Admin rebrand + Contacts/Registrations/Sponsors/Schedule/Activity/Events views - Phase 5: Convivo App (24h login, 5s polling, QR type badge, red dot, speaker material) - Phase 6: APPE favicon + PWA icons for both apps - Docs: schema/rpcs/rls/seed/screens/api-client/admin-app/architecture/next-steps/README/roadmap updated
280 lines
8.4 KiB
TypeScript
280 lines
8.4 KiB
TypeScript
import { useEffect, useMemo, useState } from 'react';
|
|
import {
|
|
createRegistration,
|
|
getAllContacts,
|
|
getActiveEvent,
|
|
getRegistrations,
|
|
setCheckedIn,
|
|
setRegistrationType,
|
|
} from '../lib/api';
|
|
import type { Contact, Event, Registration, RegistrationType } from '../lib/types';
|
|
import { useToast } from '../context/ToastContext';
|
|
import { Avatar, Empty, Modal, Spinner, Toggle, TypeBadge } from '../components/ui';
|
|
|
|
const TYPES: RegistrationType[] = ['attendee', 'speaker', 'staff', 'sponsor'];
|
|
|
|
export function Registrations() {
|
|
const { push } = useToast();
|
|
const [event, setEvent] = useState<Event | null>(null);
|
|
const [loaded, setLoaded] = useState(false);
|
|
const [contacts, setContacts] = useState<Contact[]>([]);
|
|
const [registrations, setRegistrations] = useState<Registration[]>([]);
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [query, setQuery] = useState('');
|
|
const [adding, setAdding] = useState(false);
|
|
const [busy, setBusy] = useState(false);
|
|
|
|
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);
|
|
}
|
|
setLoaded(true);
|
|
} catch (e) {
|
|
setError(e instanceof Error ? e.message : 'Failed to load');
|
|
}
|
|
}
|
|
|
|
useEffect(() => {
|
|
load();
|
|
}, []);
|
|
|
|
const byEmail = useMemo(() => new Map(contacts.map((c) => [c.email, c])), [contacts]);
|
|
|
|
const filtered = useMemo(() => {
|
|
if (!registrations) return [];
|
|
const q = query.trim().toLowerCase();
|
|
if (!q) return registrations;
|
|
return registrations.filter((r) => {
|
|
const c = byEmail.get(r.contact_email);
|
|
return (
|
|
(c?.full_name ?? '').toLowerCase().includes(q) ||
|
|
r.contact_email.toLowerCase().includes(q) ||
|
|
r.type.toLowerCase().includes(q)
|
|
);
|
|
});
|
|
}, [registrations, query, byEmail]);
|
|
|
|
async function changeType(r: Registration, type: RegistrationType) {
|
|
setBusy(true);
|
|
try {
|
|
await setRegistrationType(r.contact_email, type);
|
|
await load();
|
|
push('success', `${byEmail.get(r.contact_email)?.full_name ?? r.contact_email} → ${type}`);
|
|
} catch (e) {
|
|
push('error', e instanceof Error ? e.message : 'Update failed');
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}
|
|
|
|
async function toggleCheckedIn(r: Registration, v: boolean) {
|
|
setBusy(true);
|
|
try {
|
|
await setCheckedIn(r.id, v);
|
|
await load();
|
|
} catch (e) {
|
|
push('error', e instanceof Error ? e.message : 'Update failed');
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}
|
|
|
|
if (error) return <Empty icon="⚠️" text={error} />;
|
|
if (!loaded)
|
|
return (
|
|
<div className="loading-screen">
|
|
<Spinner />
|
|
</div>
|
|
);
|
|
|
|
if (!event) {
|
|
return (
|
|
<div>
|
|
<div className="page-head">
|
|
<div>
|
|
<h1>Registrations</h1>
|
|
<div className="sub">Ticket types and check-ins for the active event.</div>
|
|
</div>
|
|
</div>
|
|
<div className="card">
|
|
<Empty icon="📅" text="No active event. Set an event active in the Events view first." />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div>
|
|
<div className="page-head">
|
|
<div>
|
|
<h1>Registrations</h1>
|
|
<div className="sub">
|
|
{event.name} · {registrations.length} registrations · {registrations.filter((r) => r.checked_in).length} checked in.
|
|
</div>
|
|
</div>
|
|
<div className="row" style={{ gap: 10 }}>
|
|
<input
|
|
className="input"
|
|
style={{ maxWidth: 240 }}
|
|
placeholder="Search name, email, type…"
|
|
value={query}
|
|
onChange={(e) => setQuery(e.target.value)}
|
|
/>
|
|
<button className="btn primary" onClick={() => setAdding(true)}>
|
|
+ Register
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="table-wrap">
|
|
<table className="data">
|
|
<thead>
|
|
<tr>
|
|
<th>Contact</th>
|
|
<th>Type</th>
|
|
<th>Checked in</th>
|
|
<th style={{ textAlign: 'right' }}>Points</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{filtered.map((r) => {
|
|
const c = byEmail.get(r.contact_email);
|
|
return (
|
|
<tr key={r.id}>
|
|
<td>
|
|
<div className="cell-person">
|
|
<Avatar name={c?.full_name ?? r.contact_email} id={r.contact_email} size={38} fs={13} />
|
|
<div>
|
|
<div className="n">{c?.full_name ?? r.contact_email}</div>
|
|
<div className="e">{r.contact_email}</div>
|
|
</div>
|
|
</div>
|
|
</td>
|
|
<td>
|
|
<div className="row" style={{ gap: 8 }}>
|
|
<TypeBadge type={r.type} />
|
|
<select
|
|
className="input"
|
|
style={{ width: 130, padding: '6px 10px', fontSize: 12.5 }}
|
|
value={r.type}
|
|
disabled={busy}
|
|
onChange={(e) => changeType(r, e.target.value as RegistrationType)}
|
|
>
|
|
{TYPES.map((t) => (
|
|
<option key={t} value={t}>
|
|
{t}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</div>
|
|
</td>
|
|
<td>
|
|
<Toggle checked={r.checked_in} onChange={(v) => toggleCheckedIn(r, v)} />
|
|
</td>
|
|
<td style={{ textAlign: 'right' }}>
|
|
<span className="pts">{r.points}</span>
|
|
</td>
|
|
</tr>
|
|
);
|
|
})}
|
|
</tbody>
|
|
</table>
|
|
{filtered.length === 0 && <div style={{ padding: 16 }}><Empty icon="🎟️" text="No registrations yet" /></div>}
|
|
</div>
|
|
|
|
{adding && (
|
|
<AddRegistrationModal
|
|
contacts={contacts}
|
|
existing={new Set(registrations.map((r) => r.contact_email))}
|
|
onClose={() => setAdding(false)}
|
|
onSaved={async (msg) => {
|
|
setAdding(false);
|
|
await load();
|
|
push('success', msg);
|
|
}}
|
|
/>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function AddRegistrationModal({
|
|
contacts,
|
|
existing,
|
|
onClose,
|
|
onSaved,
|
|
}: {
|
|
contacts: Contact[];
|
|
existing: Set<string>;
|
|
onClose: () => void;
|
|
onSaved: (msg: string) => void;
|
|
}) {
|
|
const available = contacts.filter((c) => !existing.has(c.email));
|
|
const [email, setEmail] = useState(available[0]?.email ?? '');
|
|
const [type, setType] = useState<RegistrationType>('attendee');
|
|
const [busy, setBusy] = useState(false);
|
|
|
|
async function save() {
|
|
if (!email) return;
|
|
setBusy(true);
|
|
try {
|
|
await createRegistration(email, type);
|
|
onSaved(`Registered ${email} as ${type}`);
|
|
} catch (e) {
|
|
onSaved(e instanceof Error ? e.message : 'Registration failed');
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Modal
|
|
open
|
|
title="Register contact"
|
|
onClose={onClose}
|
|
footer={
|
|
<>
|
|
<button className="btn" onClick={onClose}>
|
|
Cancel
|
|
</button>
|
|
<button className="btn primary" disabled={busy || !email} onClick={save}>
|
|
{busy ? 'Registering…' : 'Register'}
|
|
</button>
|
|
</>
|
|
}
|
|
>
|
|
<div className="field">
|
|
<label>Contact</label>
|
|
<select className="input" value={email} onChange={(e) => setEmail(e.target.value)}>
|
|
{available.length === 0 && <option value="">All contacts already registered</option>}
|
|
{available.map((c) => (
|
|
<option key={c.email} value={c.email}>
|
|
{c.full_name} — {c.email}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</div>
|
|
<div className="field">
|
|
<label>Type</label>
|
|
<select className="input" value={type} onChange={(e) => setType(e.target.value as RegistrationType)}>
|
|
{TYPES.map((t) => (
|
|
<option key={t} value={t}>
|
|
{t}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</div>
|
|
{type === 'sponsor' && (
|
|
<p className="muted small">
|
|
A sponsor registration requires a sponsor lookup — add the sponsor in the Sponsors view first.
|
|
</p>
|
|
)}
|
|
</Modal>
|
|
);
|
|
}
|