Add Pretix ticketing integration (every-minute sidecar sync)
- docs/backend/pretix.md: Pretix REST API reference (auth, orders/items endpoints, pagination, rate limiting, worked example) - migration 20260909000000_pretix_sync.sql: events.pretix_organizer + pretix_event_slug; _map_ticket_type, _ensure_auth_user (QR token = password), sync_pretix_attendees (service-role-only, idempotent) - sidecar: pretixFetch/fetchPretixOrders/fetchPretixItems/transformPretix, runPretixSync + every-minute runPretixLoop, POST /run-pretix, /status extended with pretix state - admin: Pretix panel + recent runs in Interfaces, per-event Pretix config + Sync button in Events, api/types for Pretix - docker-compose: PRETIX_API_KEY / PRETIX_BASE / PRETIX_SYNC_INTERVAL_MS Verified on VM: 25 paid orders -> 25 attendees, auto-sync every minute, login via QR token works, idempotent (no duplicate registrations). 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
d5ec009cb5
commit
509e342204
8 files changed
+1009
-10
No files matched your search
@@ -1,6 +1,22 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { getAllEvents, getSidecarStatus, getSyncRuns, importSessionizeExcel, runSessionizeSync } from '../lib/api';
|
||||
import type { Event, ExcelSyncResult, SidecarStatus, SyncResult, SyncRun } from '../lib/types';
|
||||
import {
|
||||
getAllEvents,
|
||||
getPretixRuns,
|
||||
getSidecarStatus,
|
||||
getSyncRuns,
|
||||
importSessionizeExcel,
|
||||
runPretixSync,
|
||||
runSessionizeSync,
|
||||
} from '../lib/api';
|
||||
import type {
|
||||
Event,
|
||||
ExcelSyncResult,
|
||||
PretixRun,
|
||||
PretixSyncResult,
|
||||
SidecarStatus,
|
||||
SyncResult,
|
||||
SyncRun,
|
||||
} from '../lib/types';
|
||||
import { useToast } from '../context/ToastContext';
|
||||
import { Empty, Modal, Spinner } from '../components/ui';
|
||||
|
||||
@@ -18,6 +34,9 @@ export function Interfaces() {
|
||||
const [excelFile, setExcelFile] = useState<File | null>(null);
|
||||
const [excelBusy, setExcelBusy] = useState(false);
|
||||
const [excelResult, setExcelResult] = useState<ExcelSyncResult | null>(null);
|
||||
const [pretixRuns, setPretixRuns] = useState<SyncRun[]>([]);
|
||||
const [pretixRunning, setPretixRunning] = useState(false);
|
||||
const [pretixResult, setPretixResult] = useState<PretixSyncResult | null>(null);
|
||||
const fileRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const loadableEvents = events.filter((e) => e.sessionize_endpoint);
|
||||
@@ -52,13 +71,24 @@ export function Interfaces() {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadPretixRuns(eventId: string) {
|
||||
try {
|
||||
setPretixRuns(await getPretixRuns(eventId));
|
||||
} catch {
|
||||
setPretixRuns([]);
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
loadStatus();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedId) loadRuns(selectedId);
|
||||
if (selectedId) {
|
||||
loadRuns(selectedId);
|
||||
loadPretixRuns(selectedId);
|
||||
}
|
||||
}, [selectedId]);
|
||||
|
||||
// Poll the sidecar status while a sync is running (the run call is blocking,
|
||||
@@ -67,10 +97,10 @@ export function Interfaces() {
|
||||
loadStatus();
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
if (!running) return;
|
||||
if (!running && !pretixRunning) return;
|
||||
const t = setInterval(pollStatus, 3000);
|
||||
return () => clearInterval(t);
|
||||
}, [running, pollStatus]);
|
||||
}, [running, pretixRunning, pollStatus]);
|
||||
|
||||
async function runSync() {
|
||||
if (!selectedId) return;
|
||||
@@ -87,6 +117,21 @@ export function Interfaces() {
|
||||
}
|
||||
}
|
||||
|
||||
async function runPretixNow() {
|
||||
if (!selectedId) return;
|
||||
setPretixRunning(true);
|
||||
try {
|
||||
const res = await runPretixSync(selectedId);
|
||||
setPretixResult(res);
|
||||
await Promise.all([load(), loadStatus(), loadPretixRuns(selectedId)]);
|
||||
push('success', 'Pretix sync finished');
|
||||
} catch (e) {
|
||||
push('error', e instanceof Error ? e.message : 'Pretix sync failed');
|
||||
} finally {
|
||||
setPretixRunning(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function importExcel() {
|
||||
if (!selectedId || !excelFile) return;
|
||||
setExcelBusy(true);
|
||||
@@ -239,6 +284,109 @@ export function Interfaces() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Pretix */}
|
||||
<div className="card" style={{ marginBottom: 18 }}>
|
||||
<h2 className="h2">🎟 Pretix</h2>
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
{status?.pretixConfigured === false ? (
|
||||
<span className="pill amber" style={{ display: 'inline-block', padding: '8px 12px' }}>
|
||||
Pretix not configured (no API key on the sidecar)
|
||||
</span>
|
||||
) : (
|
||||
<div className="muted small" style={{ display: 'flex', gap: 10, alignItems: 'center', flexWrap: 'wrap' }}>
|
||||
<span>
|
||||
Pretix auto-sync: every {status?.pretixIntervalMs ? status.pretixIntervalMs / 1000 : 60}s
|
||||
</span>
|
||||
{status?.lastPretixRun && (
|
||||
<span>
|
||||
last run {fmtTime(status.lastPretixRun.finished_at)} —{' '}
|
||||
<span
|
||||
className={`pill ${
|
||||
status.lastPretixRun.status === 'success'
|
||||
? 'green'
|
||||
: status.lastPretixRun.status === 'skipped'
|
||||
? 'amber'
|
||||
: 'red'
|
||||
}`}
|
||||
>
|
||||
{status.lastPretixRun.status}
|
||||
</span>
|
||||
{status.lastPretixRun.status === 'success' && (
|
||||
<span className="muted">
|
||||
{' '}
|
||||
· {status.lastPretixRun.orders ?? 0} orders · {status.lastPretixRun.attendees ?? 0}{' '}
|
||||
attendees · {status.lastPretixRun.skipped ?? 0} skipped
|
||||
</span>
|
||||
)}
|
||||
{(status.lastPretixRun.status === 'error' || status.lastPretixRun.status === 'skipped') &&
|
||||
(status.lastPretixRun.error || status.lastPretixRun.reason) && (
|
||||
<span className="muted"> · {status.lastPretixRun.error || status.lastPretixRun.reason}</span>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div style={{ display: 'flex', gap: 12, alignItems: 'center', flexWrap: 'wrap' }}>
|
||||
<select
|
||||
className="input"
|
||||
style={{ maxWidth: 320 }}
|
||||
value={selectedId}
|
||||
onChange={(e) => setSelectedId(e.target.value)}
|
||||
>
|
||||
{events.map((e) => (
|
||||
<option key={e.id} value={e.id}>
|
||||
{e.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<button className="btn primary" disabled={pretixRunning || !selectedId} onClick={runPretixNow}>
|
||||
{pretixRunning ? 'Syncing…' : 'Run Pretix now'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Recent Pretix runs (audit) */}
|
||||
<div className="card" style={{ marginBottom: 18 }}>
|
||||
<h2 className="h2">📜 Recent Pretix runs {selected ? `— ${selected.name}` : ''}</h2>
|
||||
{pretixRuns.length === 0 ? (
|
||||
<Empty icon="🎟" text="No Pretix sync runs recorded for this event yet." />
|
||||
) : (
|
||||
<div className="table-wrap">
|
||||
<table className="data">
|
||||
<thead>
|
||||
<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) */}
|
||||
<div className="card">
|
||||
<h2 className="h2">📜 Recent runs {selected ? `— ${selected.name}` : ''}</h2>
|
||||
@@ -282,10 +430,72 @@ export function Interfaces() {
|
||||
|
||||
{result && <SyncResultModal result={result} onClose={() => setResult(null)} />}
|
||||
{excelResult && <ExcelResultModal result={excelResult} onClose={() => setExcelResult(null)} />}
|
||||
{pretixResult && <PretixResultModal result={pretixResult} onClose={() => setPretixResult(null)} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function PretixResultModal({ result, onClose }: { result: PretixRun; onClose: () => void }) {
|
||||
const s = result.summary;
|
||||
return (
|
||||
<Modal
|
||||
open
|
||||
title={`Pretix sync — ${result.event_name ?? result.event_id}`}
|
||||
onClose={onClose}
|
||||
footer={
|
||||
<button className="btn primary" onClick={onClose}>
|
||||
Close
|
||||
</button>
|
||||
}
|
||||
>
|
||||
{result.status === 'error' || result.status === 'skipped' ? (
|
||||
<div className="pill red" style={{ display: 'inline-block', padding: '8px 12px' }}>
|
||||
{result.error ?? result.reason ?? 'Pretix sync failed'}
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="stat-grid">
|
||||
<div className="stat">
|
||||
<div className="val">{result.orders ?? 0}</div>
|
||||
<div className="lbl">Orders</div>
|
||||
</div>
|
||||
<div className="stat">
|
||||
<div className="val">{result.attendees ?? 0}</div>
|
||||
<div className="lbl">Attendees</div>
|
||||
</div>
|
||||
<div className="stat">
|
||||
<div className="val">{s?.created ?? 0}</div>
|
||||
<div className="lbl">Created</div>
|
||||
</div>
|
||||
<div className="stat">
|
||||
<div className="val">{s?.updated ?? 0}</div>
|
||||
<div className="lbl">Updated</div>
|
||||
</div>
|
||||
<div className="stat">
|
||||
<div className="val">{result.skipped ?? 0}</div>
|
||||
<div className="lbl">Skipped</div>
|
||||
</div>
|
||||
</div>
|
||||
{s && s.errors.length > 0 && (
|
||||
<div style={{ marginTop: 12 }}>
|
||||
<div className="pill red" style={{ display: 'inline-block', marginBottom: 8 }}>
|
||||
{s.errors.length} error(s)
|
||||
</div>
|
||||
<ul style={{ margin: 0, paddingLeft: 18 }}>
|
||||
{s.errors.map((e, i) => (
|
||||
<li key={i} className="small">
|
||||
{e}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
function ExcelResultModal({ result, onClose }: { result: ExcelSyncResult; onClose: () => void }) {
|
||||
const s = result.summary;
|
||||
return (
|
||||
|
||||
Reference in new issue
Block a user