Datamodel: - Move qr_token from contacts to registrations (per event); new migration 20260826000000. lanyard_lookup / create_connection_request / checkin_attendee resolve via registrations + active event. - reset_qr_token -> reset_registration_qr_token (fixes ambiguous 'email' col). - upsert_contact drops the token arg; create_registration generates + syncs it. - Pretix sync writes the token to the registration (keeps it on re-sync). Registration types: - Distinct pill colors; red reserved for Staff (both apps). - Roles capitalized everywhere (Attendee/Speaker/Sponsor/Staff); 'Attendee' hidden only at the Home footer. - Reset-token button moved from Contacts to Registrations (per registration). Sessions (APPE Admin): - Slot types capitalized; material submitted/not-submitted state. - Speaker selection = multi-select search dropdown. - Fix 'a session must have a speaker' on edit (diff-based setSessionSpeakers) and the file-upload bug (speaker save no longer aborts first). APPE Admin: - Sponsors contact lookup = search field (filter + pick). Convivo App: - Other people's QR codes hidden; connection detail sheet shows public info + points. - Connect red dot recalculates immediately on accept/decline/send. - 'My picks today' = 2 rows (current + next); 'tap to change' links to Agenda. Docs updated across backend + frontend. 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]>
343 lines
11 KiB
TypeScript
343 lines
11 KiB
TypeScript
import { useEffect, useMemo, useState } from 'react';
|
|
import {
|
|
createRegistration,
|
|
getAllContacts,
|
|
getActiveEvent,
|
|
getRegistrations,
|
|
resetQrToken,
|
|
setCheckedIn,
|
|
setRegistrationType,
|
|
} from '../lib/api';
|
|
import type { Contact, Event, Registration, RegistrationType } from '../lib/types';
|
|
import { useToast } from '../context/ToastContext';
|
|
import { Avatar, Empty, Modal, QrImage, 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 [qrFor, setQrFor] = useState<Registration | null>(null);
|
|
const [newToken, setNewToken] = useState<string | null>(null);
|
|
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);
|
|
}
|
|
}
|
|
|
|
async function doResetQr(r: Registration) {
|
|
setBusy(true);
|
|
try {
|
|
const res = await resetQrToken(r.contact_email);
|
|
setNewToken(res.qr_token);
|
|
setQrFor(r);
|
|
await load();
|
|
push('success', `New QR token issued for ${byEmail.get(r.contact_email)?.full_name ?? r.contact_email}`);
|
|
} catch (e) {
|
|
push('error', e instanceof Error ? e.message : 'Reset 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>QR token</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>
|
|
<div className="row" style={{ gap: 8 }}>
|
|
<span className="mono small">{r.qr_token ?? '—'}</span>
|
|
<button className="btn small" onClick={() => { setNewToken(null); setQrFor(r); }}>
|
|
QR
|
|
</button>
|
|
</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);
|
|
}}
|
|
/>
|
|
)}
|
|
|
|
{qrFor && (
|
|
<Modal
|
|
open
|
|
title={`QR — ${byEmail.get(qrFor.contact_email)?.full_name ?? qrFor.contact_email}`}
|
|
onClose={() => setQrFor(null)}
|
|
footer={
|
|
<>
|
|
<button className="btn danger" disabled={busy} onClick={() => doResetQr(qrFor)}>
|
|
{busy ? 'Resetting…' : 'Reset token'}
|
|
</button>
|
|
<button className="btn primary" onClick={() => setQrFor(null)}>
|
|
Done
|
|
</button>
|
|
</>
|
|
}
|
|
>
|
|
<div className="qr-wrap">
|
|
{newToken ? (
|
|
<>
|
|
<QrImage value={newToken} size={190} />
|
|
<div className="token-big">{newToken}</div>
|
|
<p className="muted small">
|
|
New token issued. The old token no longer works — the person must re-scan.
|
|
</p>
|
|
</>
|
|
) : (
|
|
<>
|
|
<QrImage value={qrFor.qr_token ?? ''} size={190} />
|
|
<div className="token-big">{qrFor.qr_token ?? '—'}</div>
|
|
<p className="muted small">Current token. Reset to issue a new one.</p>
|
|
</>
|
|
)}
|
|
</div>
|
|
</Modal>
|
|
)}
|
|
</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>
|
|
);
|
|
}
|