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:
1 parent
ffb270c140
commit
24909cf8ab
27 files changed
+147
-1150
No files matched your search
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user