feat: add sidecar service for Sessionize sync
- Introduced a new Node HTTP service (sidecar) to sync event agendas from Sessionize into Convivo. - Implemented two import paths: API sync and Excel import for session and speaker data. - Added necessary database migrations for sessionize integration, including new columns and audit tables. - Created functions for handling speaker and session imports, ensuring proper error handling and logging. - Established row-level security and grants for new functions to restrict access to service-role only. 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
a0bcf866dc
commit
5f8ded56f6
31 files changed
+2729
-390
No files matched your search
@@ -0,0 +1,431 @@
|
||||
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 { useToast } from '../context/ToastContext';
|
||||
import { Empty, Modal, Spinner } from '../components/ui';
|
||||
|
||||
export function Interfaces() {
|
||||
const { push } = useToast();
|
||||
const [events, setEvents] = useState<Event[]>([]);
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [status, setStatus] = useState<SidecarStatus | null>(null);
|
||||
const [sidecarError, setSidecarError] = useState<string | null>(null);
|
||||
const [selectedId, setSelectedId] = useState<string>('');
|
||||
const [runs, setRuns] = useState<SyncRun[]>([]);
|
||||
const [running, setRunning] = useState(false);
|
||||
const [result, setResult] = useState<SyncResult | null>(null);
|
||||
const [excelFile, setExcelFile] = useState<File | null>(null);
|
||||
const [excelBusy, setExcelBusy] = useState(false);
|
||||
const [excelResult, setExcelResult] = useState<ExcelSyncResult | null>(null);
|
||||
const fileRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const loadableEvents = events.filter((e) => e.sessionize_endpoint);
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
const evs = await getAllEvents();
|
||||
setEvents(evs);
|
||||
const first = evs.find((e) => e.sessionize_endpoint);
|
||||
if (first) setSelectedId((cur) => cur || first.id);
|
||||
setLoaded(true);
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : 'Failed to load');
|
||||
}
|
||||
}
|
||||
|
||||
async function loadStatus() {
|
||||
try {
|
||||
setStatus(await getSidecarStatus());
|
||||
setSidecarError(null);
|
||||
} catch (e) {
|
||||
setStatus(null);
|
||||
setSidecarError(e instanceof Error ? e.message : 'Sidecar unreachable');
|
||||
}
|
||||
}
|
||||
|
||||
async function loadRuns(eventId: string) {
|
||||
try {
|
||||
setRuns(await getSyncRuns(eventId));
|
||||
} catch {
|
||||
setRuns([]);
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
loadStatus();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedId) loadRuns(selectedId);
|
||||
}, [selectedId]);
|
||||
|
||||
// Poll the sidecar status while a sync is running (the run call is blocking,
|
||||
// so this mainly refreshes the "running" indicator + last run).
|
||||
const pollStatus = useCallback(() => {
|
||||
loadStatus();
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
if (!running) return;
|
||||
const t = setInterval(pollStatus, 3000);
|
||||
return () => clearInterval(t);
|
||||
}, [running, pollStatus]);
|
||||
|
||||
async function runSync() {
|
||||
if (!selectedId) return;
|
||||
setRunning(true);
|
||||
try {
|
||||
const res = await runSessionizeSync(selectedId);
|
||||
setResult(res);
|
||||
await Promise.all([load(), loadStatus(), loadRuns(selectedId)]);
|
||||
push('success', 'Sessionize sync finished');
|
||||
} catch (e) {
|
||||
push('error', e instanceof Error ? e.message : 'Sync failed');
|
||||
} finally {
|
||||
setRunning(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function importExcel() {
|
||||
if (!selectedId || !excelFile) return;
|
||||
setExcelBusy(true);
|
||||
try {
|
||||
const res = await importSessionizeExcel(selectedId, excelFile);
|
||||
setExcelResult(res);
|
||||
await Promise.all([load(), loadStatus(), loadRuns(selectedId)]);
|
||||
push('success', 'Excel import finished');
|
||||
} catch (e) {
|
||||
push('error', e instanceof Error ? e.message : 'Excel import failed');
|
||||
} finally {
|
||||
setExcelBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (error) return <Empty icon="⚠️" text={error} />;
|
||||
if (!loaded)
|
||||
return (
|
||||
<div className="loading-screen">
|
||||
<Spinner />
|
||||
</div>
|
||||
);
|
||||
|
||||
const selected = events.find((e) => e.id === selectedId);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="page-head">
|
||||
<div>
|
||||
<h1>Interfaces</h1>
|
||||
<div className="sub">External data sources. The Sessionize sidecar runs on demand only.</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Sidecar status */}
|
||||
<div className="card" style={{ marginBottom: 18 }}>
|
||||
<h2 className="h2">🔌 Sidecar status</h2>
|
||||
{sidecarError ? (
|
||||
<div className="pill red" style={{ display: 'inline-block', padding: '8px 12px' }}>
|
||||
{sidecarError}
|
||||
</div>
|
||||
) : status ? (
|
||||
<div style={{ display: 'flex', gap: 10, alignItems: 'center', flexWrap: 'wrap' }}>
|
||||
<span className={`pill ${status.ok ? 'green' : 'red'}`}>{status.ok ? 'online' : 'offline'}</span>
|
||||
{status.running && <span className="pill amber">sync running…</span>}
|
||||
{status.lastRun && (
|
||||
<span className="muted small">
|
||||
last run {fmtTime(status.lastRun.finished_at)} —{' '}
|
||||
<span className={status.lastRun.status === 'success' ? 'pill green' : 'pill red'}>
|
||||
{status.lastRun.status}
|
||||
</span>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<Spinner />
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Run control */}
|
||||
<div className="card" style={{ marginBottom: 18 }}>
|
||||
<h2 className="h2">▶ Run a sync</h2>
|
||||
{loadableEvents.length === 0 ? (
|
||||
<Empty icon="🔌" text="No events have a Sessionize endpoint yet. Set one in the Events menu." />
|
||||
) : (
|
||||
<div style={{ display: 'flex', gap: 12, alignItems: 'center', flexWrap: 'wrap' }}>
|
||||
<select
|
||||
className="input"
|
||||
style={{ maxWidth: 320 }}
|
||||
value={selectedId}
|
||||
onChange={(e) => setSelectedId(e.target.value)}
|
||||
>
|
||||
{loadableEvents.map((e) => (
|
||||
<option key={e.id} value={e.id}>
|
||||
{e.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<button className="btn primary" disabled={running || !selectedId} onClick={runSync}>
|
||||
{running ? 'Syncing…' : 'Run sync'}
|
||||
</button>
|
||||
{selected?.last_synced_at && (
|
||||
<span className="muted small">last synced {fmtTime(selected.last_synced_at)}</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Excel import (Sessions & speakers advanced) */}
|
||||
<div className="card" style={{ marginBottom: 18 }}>
|
||||
<h2 className="h2">📄 Import from Sessionize export</h2>
|
||||
<div className="muted small" style={{ marginBottom: 12, maxWidth: 640 }}>
|
||||
Upload the <strong>“Sessions and speakers (advanced)”</strong> .xlsx export from your
|
||||
Sessionize event. It imports speakers (by email), sessions, the agenda, and creates the
|
||||
speaker registrations — no API key needed.
|
||||
</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>
|
||||
<input
|
||||
ref={fileRef}
|
||||
type="file"
|
||||
accept=".xlsx,.xls"
|
||||
style={{ display: 'none' }}
|
||||
onChange={(e) => setExcelFile(e.target.files?.[0] ?? null)}
|
||||
/>
|
||||
<button className="btn" disabled={excelBusy} onClick={() => fileRef.current?.click()}>
|
||||
{excelFile ? `📎 ${excelFile.name}` : 'Choose .xlsx…'}
|
||||
</button>
|
||||
<button className="btn primary" disabled={excelBusy || !excelFile || !selectedId} onClick={importExcel}>
|
||||
{excelBusy ? 'Importing…' : 'Import'}
|
||||
</button>
|
||||
<div className="uiverse-tooltip">
|
||||
<button type="button" className="uiverse-btn">
|
||||
<span>
|
||||
<svg viewBox="0 0 24 24" stroke="currentColor" fill="none" width="16" height="16">
|
||||
<path d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" strokeWidth="2" strokeLinejoin="round" strokeLinecap="round" />
|
||||
</svg>
|
||||
How to get this file
|
||||
</span>
|
||||
</button>
|
||||
<div className="uiverse-card">
|
||||
<div className="uiverse-head">
|
||||
<div className="uiverse-ico">
|
||||
<svg viewBox="0 0 20 20" fill="currentColor" width="16" height="16">
|
||||
<path clipRule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" fillRule="evenodd" />
|
||||
</svg>
|
||||
</div>
|
||||
<h3>Export from Sessionize</h3>
|
||||
</div>
|
||||
<p>
|
||||
In your Sessionize event, open <strong>Export</strong> → <strong>“Sessions and
|
||||
speakers (advanced)”</strong> and download the .xlsx. Any organizer with access to
|
||||
the event can generate it. Upload it here to import speakers, sessions, the agenda
|
||||
and speaker registrations.
|
||||
</p>
|
||||
<div className="uiverse-foot">No API key required</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Recent runs (audit) */}
|
||||
<div className="card">
|
||||
<h2 className="h2">📜 Recent runs {selected ? `— ${selected.name}` : ''}</h2>
|
||||
{runs.length === 0 ? (
|
||||
<Empty icon="📜" text="No 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>
|
||||
{runs.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>
|
||||
|
||||
{result && <SyncResultModal result={result} onClose={() => setResult(null)} />}
|
||||
{excelResult && <ExcelResultModal result={excelResult} onClose={() => setExcelResult(null)} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ExcelResultModal({ result, onClose }: { result: ExcelSyncResult; onClose: () => void }) {
|
||||
const s = result.summary;
|
||||
return (
|
||||
<Modal
|
||||
open
|
||||
title={`Excel import — ${result.event_name ?? result.event_id}`}
|
||||
onClose={onClose}
|
||||
footer={
|
||||
<button className="btn primary" onClick={onClose}>
|
||||
Close
|
||||
</button>
|
||||
}
|
||||
>
|
||||
{result.status === 'error' || !s ? (
|
||||
<div className="pill red" style={{ display: 'inline-block', padding: '8px 12px' }}>
|
||||
{result.error ?? 'Import failed'}
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="stat-grid">
|
||||
<div className="stat">
|
||||
<div className="val">{s.speakers_created}</div>
|
||||
<div className="lbl">Speakers created</div>
|
||||
</div>
|
||||
<div className="stat">
|
||||
<div className="val">{s.sessions_created}</div>
|
||||
<div className="lbl">Sessions created</div>
|
||||
</div>
|
||||
<div className="stat">
|
||||
<div className="val">{s.slots_created}</div>
|
||||
<div className="lbl">Slots created</div>
|
||||
</div>
|
||||
<div className="stat">
|
||||
<div className="val">{s.speakers_linked}</div>
|
||||
<div className="lbl">Speaker links</div>
|
||||
</div>
|
||||
<div className="stat">
|
||||
<div className="val">{s.registrations_created}</div>
|
||||
<div className="lbl">Speaker regs created</div>
|
||||
</div>
|
||||
<div className="stat">
|
||||
<div className="val">{s.registrations_updated}</div>
|
||||
<div className="lbl">Speaker regs updated</div>
|
||||
</div>
|
||||
</div>
|
||||
{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 SyncResultModal({ result, onClose }: { result: SyncResult; onClose: () => void }) {
|
||||
const s = result.summary;
|
||||
return (
|
||||
<Modal
|
||||
open
|
||||
title={`Sessionize sync — ${result.event_name ?? result.event_id}`}
|
||||
onClose={onClose}
|
||||
footer={
|
||||
<button className="btn primary" onClick={onClose}>
|
||||
Close
|
||||
</button>
|
||||
}
|
||||
>
|
||||
{result.status === 'error' || !s ? (
|
||||
<div className="pill red" style={{ display: 'inline-block', padding: '8px 12px' }}>
|
||||
{result.error ?? 'Sync failed'}
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="stat-grid">
|
||||
<div className="stat">
|
||||
<div className="val">{s.speakers_created}</div>
|
||||
<div className="lbl">Speakers created</div>
|
||||
</div>
|
||||
<div className="stat">
|
||||
<div className="val">{s.speakers_updated}</div>
|
||||
<div className="lbl">Speakers updated</div>
|
||||
</div>
|
||||
<div className="stat">
|
||||
<div className="val">{s.sessions_created}</div>
|
||||
<div className="lbl">Sessions created</div>
|
||||
</div>
|
||||
<div className="stat">
|
||||
<div className="val">{s.sessions_updated}</div>
|
||||
<div className="lbl">Sessions updated</div>
|
||||
</div>
|
||||
<div className="stat">
|
||||
<div className="val">{s.slots_created}</div>
|
||||
<div className="lbl">Slots created</div>
|
||||
</div>
|
||||
<div className="stat">
|
||||
<div className="val">{s.speakers_linked}</div>
|
||||
<div className="lbl">Speaker links</div>
|
||||
</div>
|
||||
</div>
|
||||
{result.skipped_speakers && result.skipped_speakers.length > 0 && (
|
||||
<div className="muted small">
|
||||
Skipped {result.skipped_speakers.length} speaker(s) without an email: {result.skipped_speakers.join(', ')}
|
||||
</div>
|
||||
)}
|
||||
{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 fmtTime(iso: string): string {
|
||||
return new Date(iso).toLocaleString([], {
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user