Existing-sponsor link + remove Interfaces (Pretix/Sessionize)

- Sponsor lookup popup can now link an existing sponsor (dropdown + pre-fill)
  or create a new one; save upserts the sponsor linked to the contact and sets
  the registration type to sponsor.
- Remove the Interfaces feature end-to-end: admin nav button + Sync view, sync
  API helpers + SyncRun type, sync-trigger Edge Function, mock-api + its
  docker-compose service, and a migration dropping the sync RPCs, helpers, and
  sync_runs table.
- Update docs (architecture, backend, frontend, README, roadmap, next-steps).

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:
committed 2026-08-24 09:11:25 +02:00
1 parent ffb270c140
commit 24909cf8ab
27 files changed
+147 -1150

No files matched your search

+1 -1
View File
@@ -75,7 +75,7 @@ server {
client_max_body_size 50M;
}
# Edge Functions (e.g. sync-trigger for the Pretix/Sessionize interfaces).
# Edge Functions.
location /functions/ {
proxy_pass http://__SUPABASE_PROXY_TARGET__;
proxy_set_header Host $host;
+1 -5
View File
@@ -9,7 +9,6 @@ import { Sponsors } from './views/Sponsors';
import { Schedule } from './views/Schedule';
import { Activity } from './views/Activity';
import { Events } from './views/Events';
import { Sync } from './views/Sync';
import { Spinner } from './components/ui';
export type View =
@@ -19,8 +18,7 @@ export type View =
| 'sponsors'
| 'schedule'
| 'activity'
| 'events'
| 'sync';
| 'events';
const NAV: { id: View; label: string; ico: string }[] = [
{ id: 'dashboard', label: 'Dashboard', ico: '📊' },
@@ -30,7 +28,6 @@ const NAV: { id: View; label: string; ico: string }[] = [
{ id: 'schedule', label: 'Schedule', ico: '🗓️' },
{ id: 'activity', label: 'Activity', ico: '⚡' },
{ id: 'events', label: 'Events', ico: '📅' },
{ id: 'sync', label: 'Interfaces', ico: '🔄' },
];
function Shell() {
@@ -98,7 +95,6 @@ function Shell() {
{view === 'schedule' && <Schedule />}
{view === 'activity' && <Activity />}
{view === 'events' && <Events />}
{view === 'sync' && <Sync />}
</main>
</div>
);
-69
View File
@@ -13,7 +13,6 @@ import type {
SessionSpeaker,
Slot,
Sponsor,
SyncRun,
} from './types';
export class ApiError extends Error {}
@@ -220,71 +219,3 @@ export async function evaluateSessionFeedback(sessionId: string): Promise<Sessio
// evaluate_session_feedback returns a single composite row (a JSON object, not an array).
return await rpc<Session>('evaluate_session_feedback', { p_session_id: sessionId });
}
// ---- Interfaces: Pretix + Sessionize sync (Phase 7 + 8) ---------------------
export interface SyncResult {
ok: boolean;
triggered_by: string;
results: {
pretix?: { created: number; updated: number; skipped: number; errors: string[] };
sessionize?: {
slots_created: number;
sessions_created: number;
sessions_updated: number;
speakers_linked: number;
errors: string[];
};
};
errors: string[];
}
/**
* Trigger a sync from the `sync-trigger` Edge Function. The admin's session
* JWT is passed as the Authorization header; the function verifies it is an
* admin (via the is_admin() RPC) before running.
*/
export async function triggerSync(source: 'pretix' | 'sessionize' | 'both'): Promise<SyncResult> {
const { data } = await supabase.auth.getSession();
const token = data.session?.access_token;
if (!token) throw new ApiError('not signed in');
const res = await fetch('/functions/v1/sync-trigger', {
method: 'POST',
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
body: JSON.stringify({ source }),
});
const body = (await res.json()) as SyncResult & { error?: string };
if (!res.ok) throw new ApiError(body.error ?? `sync failed (${res.status})`);
return body;
}
/** Recent sync runs (audit trail), newest first. */
export const getSyncRuns = (limit = 10) =>
all<SyncRun>('sync_runs', { col: 'started_at', asc: false }).then((rows) => rows.slice(0, limit));
/**
* Build a CSV of lanyard QR codes for the active event's registrations
* (name, email, type, QR token) and trigger a browser download.
*/
export async function exportQrCsv(eventId: string): Promise<number> {
const regs = await getRegistrations(eventId);
const contacts = await getAllContacts();
const byEmail = new Map(contacts.map((c) => [c.email, c]));
const esc = (v: string | null | undefined) => `"${(v ?? '').replace(/"/g, '""')}"`;
const lines = ['name,email,type,qr_token'];
let count = 0;
for (const r of regs) {
const c = byEmail.get(r.contact_email);
if (!r.qr_token) continue;
lines.push([esc(c?.full_name ?? r.contact_email), esc(r.contact_email), esc(r.type), esc(r.qr_token)].join(','));
count++;
}
const blob = new Blob([lines.join('\n')], { type: 'text/csv;charset=utf-8' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `lanyard-qr-codes-${eventId.slice(0, 8)}.csv`;
a.click();
URL.revokeObjectURL(url);
return count;
}
-12
View File
@@ -144,15 +144,3 @@ export interface ResetQrResult {
email: string;
qr_token: string;
}
export interface SyncRun {
id: string;
source: 'pretix' | 'sessionize';
started_at: string;
finished_at: string | null;
created: number;
updated: number;
skipped: number;
error: string | null;
triggered_by: string;
}
-2
View File
@@ -114,8 +114,6 @@ body {
.pill.swag { background: rgba(219,39,119,.12); border-color: rgba(219,39,119,.4); color: #be185d; }
.pill.catering { background: rgba(234,88,12,.13); border-color: rgba(234,88,12,.4); color: #c2410c; }
.pill.diversity { background: rgba(124,58,237,.12); border-color: rgba(124,58,237,.4); color: #6d28d9; }
/* sync result pills (Interfaces view) */
.sync-result { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.avatar { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; font-weight: 800; color: #fff; flex-shrink: 0; }
.input, select.input {
width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
+45 -7
View File
@@ -4,11 +4,12 @@ import {
getAllContacts,
getActiveEvent,
getRegistrations,
getSponsors,
setCheckedIn,
setRegistrationType,
upsertSponsor,
} from '../lib/api';
import type { Contact, Event, Registration, RegistrationType, SponsorType } from '../lib/types';
import type { Contact, Event, Registration, RegistrationType, Sponsor, SponsorType } from '../lib/types';
import { useToast } from '../context/ToastContext';
import { Avatar, Empty, Modal, QrImage, Spinner, Toggle, TypeBadge } from '../components/ui';
@@ -234,7 +235,7 @@ export function Registrations() {
<QrImage value={qrFor.qr_token ?? ''} size={190} />
<div className="token-big">{qrFor.qr_token ?? '—'}</div>
<p className="muted small">
This token is final — it was generated by Pretix and can’t be reset.
This token is final — it was generated for this event and can’t be reset.
</p>
</div>
</Modal>
@@ -350,6 +351,8 @@ function SponsorLookupModal({
onClose: () => void;
onSaved: (msg: string) => void;
}) {
const [sponsors, setSponsors] = useState<Sponsor[]>([]);
const [selectedSponsorId, setSelectedSponsorId] = useState('');
const [type, setType] = useState<SponsorType>('gold');
const [name, setName] = useState('');
const [email, setEmail] = useState('');
@@ -359,12 +362,32 @@ function SponsorLookupModal({
const [busy, setBusy] = useState(false);
const contactEmail = registration.contact_email;
const isExisting = selectedSponsorId !== '';
useEffect(() => {
getSponsors(eventId).then(setSponsors).catch(() => setSponsors([]));
}, [eventId]);
function pickSponsor(id: string) {
setSelectedSponsorId(id);
if (id) {
const s = sponsors.find((x) => x.id === id);
if (s) {
setType(s.type);
setName(s.name);
setEmail(s.email ?? '');
setPhone(s.phone ?? '');
setPaid(s.paid);
setAmount(s.amount_eur != null ? String(s.amount_eur) : '');
}
}
}
async function save() {
if (!name.trim()) return;
setBusy(true);
try {
await upsertSponsor(null, {
await upsertSponsor(selectedSponsorId || null, {
event_id: eventId,
type,
name: name.trim(),
@@ -375,7 +398,11 @@ function SponsorLookupModal({
contact_email: contactEmail,
});
await setRegistrationType(contactEmail, 'sponsor');
onSaved(`Sponsor "${name.trim()}" created — ${contact?.full_name ?? contactEmail} is now a sponsor`);
onSaved(
isExisting
? `Sponsor "${name.trim()}" linked — ${contact?.full_name ?? contactEmail} is now a sponsor`
: `Sponsor "${name.trim()}" created — ${contact?.full_name ?? contactEmail} is now a sponsor`,
);
} catch (e) {
onSaved(e instanceof Error ? e.message : 'Save failed');
} finally {
@@ -394,15 +421,26 @@ function SponsorLookupModal({
Cancel
</button>
<button className="btn primary" disabled={busy || !name.trim()} onClick={save}>
{busy ? 'Saving…' : 'Create sponsor & set type'}
{busy ? 'Saving…' : isExisting ? 'Link sponsor & set type' : 'Create sponsor & set type'}
</button>
</>
}
>
<p className="muted small" style={{ marginBottom: 14 }}>
A sponsor registration needs a sponsor lookup. Create the sponsor below — it will be linked to{' '}
<b>{contact?.full_name ?? contactEmail}</b> and their registration type set to <b>Sponsor</b>.
A sponsor registration needs a sponsor lookup. Link an existing sponsor or create a new one — it will be
linked to <b>{contact?.full_name ?? contactEmail}</b> and their registration type set to <b>Sponsor</b>.
</p>
<div className="field" style={{ marginBottom: 14 }}>
<label>Sponsor</label>
<select className="input" value={selectedSponsorId} onChange={(e) => pickSponsor(e.target.value)}>
<option value="">— Create new —</option>
{sponsors.map((s) => (
<option key={s.id} value={s.id}>
{s.name} ({s.type})
</option>
))}
</select>
</div>
<div className="grid-2">
<div className="field">
<label>Sponsor type</label>
-240
View File
@@ -1,240 +0,0 @@
import { useCallback, useEffect, useState } from 'react';
import {
exportQrCsv,
getActiveEvent,
getSyncRuns,
triggerSync,
type SyncResult,
} from '../lib/api';
import type { Event, SyncRun } from '../lib/types';
import { useToast } from '../context/ToastContext';
import { Empty, Spinner } from '../components/ui';
type Source = 'pretix' | 'sessionize' | 'both';
function fmtTime(iso: string | null): string {
if (!iso) return '—';
const d = new Date(iso);
return d.toLocaleString(undefined, {
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
});
}
function SourcePill({ source }: { source: SyncRun['source'] }) {
return <span className={`pill ${source === 'pretix' ? 'gold' : 'green'}`}>{source}</span>;
}
export function Sync() {
const { push } = useToast();
const [event, setEvent] = useState<Event | null>(null);
const [loaded, setLoaded] = useState(false);
const [error, setError] = useState<string | null>(null);
const [runs, setRuns] = useState<SyncRun[]>([]);
const [busy, setBusy] = useState<Source | null>(null);
const [last, setLast] = useState<SyncResult | null>(null);
const load = useCallback(async () => {
try {
const [ev, r] = await Promise.all([getActiveEvent(), getSyncRuns(8)]);
setEvent(ev);
setRuns(r);
setLoaded(true);
} catch (e) {
setError(e instanceof Error ? e.message : 'Failed to load');
}
}, []);
useEffect(() => {
load();
}, [load]);
async function doSync(source: Source) {
setBusy(source);
setLast(null);
try {
const res = await triggerSync(source);
setLast(res);
const bits: string[] = [];
if (res.results.pretix)
bits.push(`Pretix: ${res.results.pretix.updated} updated`);
if (res.results.sessionize)
bits.push(
`Sessionize: ${res.results.sessionize.sessions_created} new, ${res.results.sessionize.sessions_updated} updated`,
);
push(res.ok ? 'success' : 'error', res.ok ? `Sync complete — ${bits.join(' · ')}` : `Sync finished with errors`);
await load();
} catch (e) {
push('error', e instanceof Error ? e.message : 'Sync failed');
} finally {
setBusy(null);
}
}
async function doExport() {
if (!event) return;
try {
const n = await exportQrCsv(event.id);
push('success', `Exported ${n} lanyard QR code${n === 1 ? '' : 's'} to CSV`);
} catch (e) {
push('error', e instanceof Error ? e.message : 'Export failed');
}
}
if (error) return <Empty icon="⚠️" text={error} />;
if (!loaded)
return (
<div className="loading-screen">
<Spinner />
</div>
);
return (
<div>
<div className="page-head">
<div>
<h1>Interfaces</h1>
<div className="sub">
Sync real data from <strong>Pretix</strong> (tickets → contacts + registrations) and{' '}
<strong>Sessionize</strong> (agenda → slots + sessions + speakers).
</div>
</div>
<div className="row" style={{ gap: 8 }}>
<button className="btn" disabled={busy !== null} onClick={() => doExport()}>
⬇ Export QR CSV
</button>
<button className="btn primary" disabled={busy !== null} onClick={() => doSync('both')}>
{busy === 'both' ? 'Syncing…' : '🔄 Sync all'}
</button>
</div>
</div>
{!event && (
<div className="card" style={{ marginBottom: 16 }}>
<Empty icon="📅" text="No active event. Syncs target the active event — set one in the Events view." />
</div>
)}
<div className="grid-2">
<div className="card">
<div className="row between" style={{ marginBottom: 14 }}>
<h2 className="h2">🎟️ Pretix</h2>
<button
className="btn small"
disabled={busy !== null || !event}
onClick={() => doSync('pretix')}
>
{busy === 'pretix' ? 'Syncing…' : 'Sync now'}
</button>
</div>
<p className="muted small" style={{ marginTop: 0 }}>
Pulls ticket holders and upserts <code>contacts</code> + <code>registrations</code> (QR tokens
generated for new ticket holders). Ticket type maps to registration type
(speaker / staff / sponsor / attendee).
</p>
{last?.results.pretix && (
<div className="sync-result">
<span className="pill green">{last.results.pretix.updated} updated</span>
<span className="pill">{last.results.pretix.skipped} skipped</span>
{last.results.pretix.errors.length > 0 && (
<span className="pill red">{last.results.pretix.errors.length} errors</span>
)}
</div>
)}
</div>
<div className="card">
<div className="row between" style={{ marginBottom: 14 }}>
<h2 className="h2">🗓️ Sessionize</h2>
<button
className="btn small"
disabled={busy !== null || !event}
onClick={() => doSync('sessionize')}
>
{busy === 'sessionize' ? 'Syncing…' : 'Sync now'}
</button>
</div>
<p className="muted small" style={{ marginTop: 0 }}>
Pulls the agenda and upserts <code>slots</code> + <code>sessions</code> + speakers. Slots are
matched by date + time; sessions by their Sessionize id.
</p>
{last?.results.sessionize && (
<div className="sync-result">
<span className="pill green">{last.results.sessionize.sessions_created} new</span>
<span className="pill">{last.results.sessionize.sessions_updated} updated</span>
<span className="pill">{last.results.sessionize.slots_created} slots</span>
<span className="pill">{last.results.sessionize.speakers_linked} speakers</span>
</div>
)}
</div>
</div>
{last && last.errors.length > 0 && (
<div className="card" style={{ marginTop: 16, borderColor: 'var(--red, #d50000)' }}>
<h2 className="h2" style={{ color: 'var(--red, #d50000)' }}>
⚠️ Sync errors
</h2>
<ul className="muted small" style={{ margin: '8px 0 0', paddingLeft: 18 }}>
{last.errors.map((e, i) => (
<li key={i}>{e}</li>
))}
</ul>
</div>
)}
<div className="card" style={{ marginTop: 16 }}>
<div className="row between" style={{ marginBottom: 14 }}>
<h2 className="h2">🕘 Recent sync runs</h2>
<button className="btn small ghost" onClick={load}>
Refresh
</button>
</div>
{runs.length === 0 ? (
<Empty icon="🔄" text="No sync runs yet. Trigger one above." />
) : (
<div className="table-wrap">
<table className="data">
<thead>
<tr>
<th>Source</th>
<th>Started</th>
<th>Created</th>
<th>Updated</th>
<th>Skipped</th>
<th>Triggered by</th>
<th>Status</th>
</tr>
</thead>
<tbody>
{runs.map((r) => (
<tr key={r.id}>
<td>
<SourcePill source={r.source} />
</td>
<td className="muted small">{fmtTime(r.started_at)}</td>
<td>{r.created}</td>
<td>{r.updated}</td>
<td>{r.skipped}</td>
<td className="muted small">{r.triggered_by}</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>
</div>
);
}
+1 -2
View File
@@ -14,8 +14,7 @@ export interface Contact {
}
/** The signed-in contact's registration for the active event.
* The QR token lives here (per event, generated by Pretix) and doubles as
* the login password. */
* The QR token lives here (per event) and doubles as the login password. */
export interface Registration {
id: string;
event_id: string;