Fixes & Refinements: QR token on registration, role caps, connection detail + red dot, admin schedule/sponsors
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.
This commit is contained in:
1 parent
005f1d404f
commit
b52d8ab007
30 files changed
+1076
-225
No files matched your search
@@ -81,7 +81,7 @@ export function QrImage({ value, size = 180 }: { value: string; size?: number })
|
|||||||
|
|
||||||
/** Small colored badge for a registration / sponsor type. */
|
/** Small colored badge for a registration / sponsor type. */
|
||||||
export function TypeBadge({ type }: { type: string }) {
|
export function TypeBadge({ type }: { type: string }) {
|
||||||
return <span className={`pill pill-${type}`}>{type.replace('_', ' ')}</span>;
|
return <span className={`pill ${type}`}>{type.replace(/_/g, ' ')}</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A small on/off toggle switch. */
|
/** A small on/off toggle switch. */
|
||||||
|
|||||||
+23
-10
@@ -66,15 +66,14 @@ export async function upsertContact(input: {
|
|||||||
full_name: string;
|
full_name: string;
|
||||||
linkedin_url?: string | null;
|
linkedin_url?: string | null;
|
||||||
is_admin?: boolean;
|
is_admin?: boolean;
|
||||||
qr_token?: string | null;
|
|
||||||
}): Promise<Contact> {
|
}): Promise<Contact> {
|
||||||
// upsert_contact returns a single composite row (a JSON object, not an array).
|
// upsert_contact returns a single composite row (a JSON object, not an array).
|
||||||
|
// Contacts no longer carry a QR token — the token lives on the registration.
|
||||||
return await rpc<Contact>('upsert_contact', {
|
return await rpc<Contact>('upsert_contact', {
|
||||||
p_email: input.email,
|
p_email: input.email,
|
||||||
p_full_name: input.full_name,
|
p_full_name: input.full_name,
|
||||||
p_linkedin_url: input.linkedin_url ?? null,
|
p_linkedin_url: input.linkedin_url ?? null,
|
||||||
p_is_admin: input.is_admin ?? false,
|
p_is_admin: input.is_admin ?? false,
|
||||||
p_qr_token: input.qr_token ?? null,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,9 +85,13 @@ export async function updateContact(
|
|||||||
if (error) throw new ApiError(error.message);
|
if (error) throw new ApiError(error.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Regenerate a contact's QR token (syncs the auth password, forces re-login). */
|
/**
|
||||||
|
* Regenerate the QR token of a contact's registration for the active event
|
||||||
|
* (syncs the auth password, forces re-login). The token lives on the
|
||||||
|
* registration, not the contact.
|
||||||
|
*/
|
||||||
export async function resetQrToken(email: string): Promise<ResetQrResult> {
|
export async function resetQrToken(email: string): Promise<ResetQrResult> {
|
||||||
const rows = await rpc<ResetQrResult[]>('reset_qr_token', { p_contact_email: email });
|
const rows = await rpc<ResetQrResult[]>('reset_registration_qr_token', { p_contact_email: email });
|
||||||
return rows[0];
|
return rows[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,13 +170,23 @@ export async function adjustPoints(contactEmail: string, delta: number, reason:
|
|||||||
// ---- Sessions: speakers, material, AI feedback -------------------------------
|
// ---- Sessions: speakers, material, AI feedback -------------------------------
|
||||||
|
|
||||||
export async function setSessionSpeakers(sessionId: string, emails: string[]): Promise<void> {
|
export async function setSessionSpeakers(sessionId: string, emails: string[]): Promise<void> {
|
||||||
// Replace the speaker set: delete all, then insert the new set.
|
// Replace the speaker set with a diff: insert the new set first, then delete
|
||||||
const { error: delErr } = await supabase.from('session_speakers').delete().eq('session_id', sessionId);
|
// only the speakers that are no longer in the set. Deleting first would trip
|
||||||
if (delErr) throw new ApiError(delErr.message);
|
// the `session_needs_speaker` trigger (it counts the row being deleted, so
|
||||||
|
// removing the last speaker always fails) and abort the whole save.
|
||||||
if (emails.length > 0) {
|
if (emails.length > 0) {
|
||||||
const rows = emails.map((contact_email) => ({ session_id: sessionId, contact_email }));
|
const rows = emails.map((contact_email) => ({ session_id: sessionId, contact_email }));
|
||||||
const { error: insErr } = await supabase.from('session_speakers').insert(rows);
|
// upsert (on conflict do nothing) so re-adding an existing speaker is a no-op.
|
||||||
|
const { error: insErr } = await supabase
|
||||||
|
.from('session_speakers')
|
||||||
|
.upsert(rows, { onConflict: 'session_id,contact_email', ignoreDuplicates: true });
|
||||||
if (insErr) throw new ApiError(insErr.message);
|
if (insErr) throw new ApiError(insErr.message);
|
||||||
|
const { error: delErr } = await supabase
|
||||||
|
.from('session_speakers')
|
||||||
|
.delete()
|
||||||
|
.eq('session_id', sessionId)
|
||||||
|
.not('contact_email', 'in', `(${emails.join(',')})`);
|
||||||
|
if (delErr) throw new ApiError(delErr.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,8 +275,8 @@ export async function exportQrCsv(eventId: string): Promise<number> {
|
|||||||
let count = 0;
|
let count = 0;
|
||||||
for (const r of regs) {
|
for (const r of regs) {
|
||||||
const c = byEmail.get(r.contact_email);
|
const c = byEmail.get(r.contact_email);
|
||||||
if (!c?.qr_token) continue;
|
if (!r.qr_token) continue;
|
||||||
lines.push([esc(c.full_name), esc(c.email), esc(r.type), esc(c.qr_token)].join(','));
|
lines.push([esc(c?.full_name ?? r.contact_email), esc(r.contact_email), esc(r.type), esc(r.qr_token)].join(','));
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
const blob = new Blob([lines.join('\n')], { type: 'text/csv;charset=utf-8' });
|
const blob = new Blob([lines.join('\n')], { type: 'text/csv;charset=utf-8' });
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ export interface Contact {
|
|||||||
show_email: boolean;
|
show_email: boolean;
|
||||||
show_linkedin: boolean;
|
show_linkedin: boolean;
|
||||||
is_admin: boolean;
|
is_admin: boolean;
|
||||||
qr_token: string | null;
|
|
||||||
created_at: string;
|
created_at: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,6 +44,7 @@ export interface Registration {
|
|||||||
type: RegistrationType;
|
type: RegistrationType;
|
||||||
checked_in: boolean;
|
checked_in: boolean;
|
||||||
points: number;
|
points: number;
|
||||||
|
qr_token: string | null;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ body {
|
|||||||
font-size: 11.5px; font-weight: 700; background: var(--surface-2); border: 1px solid var(--line); text-transform: capitalize;
|
font-size: 11.5px; font-weight: 700; background: var(--surface-2); border: 1px solid var(--line); text-transform: capitalize;
|
||||||
}
|
}
|
||||||
.pill.attendee { background: rgba(148,163,184,.14); border-color: rgba(148,163,184,.4); color: #64748b; }
|
.pill.attendee { background: rgba(148,163,184,.14); border-color: rgba(148,163,184,.4); color: #64748b; }
|
||||||
.pill.staff { background: rgba(32,178,170,.13); border-color: rgba(32,178,170,.4); color: #0f766e; }
|
.pill.staff { background: rgba(220,38,38,.12); border-color: rgba(220,38,38,.4); color: #b91c1c; }
|
||||||
.pill.admin { background: var(--accent-soft); border-color: rgba(213,0,0,.35); color: var(--accent); }
|
.pill.admin { background: var(--accent-soft); border-color: rgba(213,0,0,.35); color: var(--accent); }
|
||||||
.pill.amber { background: rgba(245,158,11,.14); border-color: rgba(245,158,11,.4); color: #b45309; }
|
.pill.amber { background: rgba(245,158,11,.14); border-color: rgba(245,158,11,.4); color: #b45309; }
|
||||||
.pill.green { background: rgba(5,150,105,.12); border-color: rgba(5,150,105,.35); color: var(--green); }
|
.pill.green { background: rgba(5,150,105,.12); border-color: rgba(5,150,105,.35); color: var(--green); }
|
||||||
@@ -239,15 +239,39 @@ table.data tr:hover td { background: rgba(244,245,249,.6); }
|
|||||||
}
|
}
|
||||||
.event-name { font-size: 22px; font-weight: 900; letter-spacing: -.5px; }
|
.event-name { font-size: 22px; font-weight: 900; letter-spacing: -.5px; }
|
||||||
|
|
||||||
/* ---------- Speaker picker (schedule) ---------- */
|
/* ---------- Speaker multi-select (schedule) ---------- */
|
||||||
.speaker-pick { display: flex; flex-wrap: wrap; gap: 8px; max-height: 220px; overflow-y: auto; padding: 4px; }
|
.msel { display: flex; flex-direction: column; gap: 8px; }
|
||||||
.speaker-opt {
|
.msel-chips { display: flex; flex-wrap: wrap; gap: 6px; }
|
||||||
display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; border-radius: 999px;
|
.msel-chip {
|
||||||
border: 1px solid var(--line); background: var(--surface-2); font-size: 13px; font-weight: 600;
|
display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 11px; border-radius: 999px;
|
||||||
cursor: pointer; transition: all .12s;
|
background: var(--accent-soft); border: 1px solid rgba(213,0,0,.35); color: var(--accent);
|
||||||
|
font-size: 12.5px; font-weight: 700;
|
||||||
}
|
}
|
||||||
.speaker-opt input { accent-color: var(--accent); }
|
.msel-x {
|
||||||
.speaker-opt.on { background: var(--accent-soft); border-color: rgba(213,0,0,.4); color: var(--accent); }
|
display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px;
|
||||||
|
border: none; border-radius: 50%; background: rgba(213,0,0,.12); color: var(--accent);
|
||||||
|
font-size: 10px; cursor: pointer; line-height: 1;
|
||||||
|
}
|
||||||
|
.msel-x:hover { background: rgba(213,0,0,.22); }
|
||||||
|
.msel-list {
|
||||||
|
border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
|
||||||
|
background: var(--surface); max-height: 200px; overflow-y: auto;
|
||||||
|
}
|
||||||
|
.msel-item {
|
||||||
|
display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
|
||||||
|
padding: 8px 12px; background: none; border: none; border-bottom: 1px solid var(--line);
|
||||||
|
cursor: pointer; font: inherit;
|
||||||
|
}
|
||||||
|
.msel-item:last-child { border-bottom: none; }
|
||||||
|
.msel-item:hover { background: var(--surface-2); }
|
||||||
|
.msel-item.on { background: var(--accent-soft); }
|
||||||
|
.msel-check {
|
||||||
|
width: 18px; height: 18px; flex: none; display: inline-flex; align-items: center; justify-content: center;
|
||||||
|
border: 1.5px solid var(--line); border-radius: 5px; font-size: 11px; color: var(--accent);
|
||||||
|
}
|
||||||
|
.msel-item.on .msel-check { background: var(--accent); border-color: var(--accent); color: #fff; }
|
||||||
|
.msel-item .n { font-weight: 600; font-size: 13px; color: var(--text); }
|
||||||
|
.msel-item .e { font-size: 12px; color: var(--muted); margin-left: auto; }
|
||||||
|
|
||||||
/* ---------- AI feedback box (schedule) ---------- */
|
/* ---------- AI feedback box (schedule) ---------- */
|
||||||
.ai-box {
|
.ai-box {
|
||||||
@@ -268,6 +292,21 @@ table.data tr:hover td { background: rgba(244,245,249,.6); }
|
|||||||
.toast-error { border-color: rgba(213,0,0,.55); }
|
.toast-error { border-color: rgba(213,0,0,.55); }
|
||||||
.toast-info { border-color: rgba(32,178,170,.5); }
|
.toast-info { border-color: rgba(32,178,170,.5); }
|
||||||
|
|
||||||
|
/* ---------- Contact search-and-pick (Sponsors) ------------------------------ */
|
||||||
|
.contact-pick {
|
||||||
|
margin-top: 6px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
|
||||||
|
background: var(--surface); max-height: 180px; overflow-y: auto;
|
||||||
|
}
|
||||||
|
.contact-pick-item {
|
||||||
|
display: flex; flex-direction: column; gap: 1px; width: 100%; text-align: left;
|
||||||
|
padding: 8px 12px; background: none; border: none; border-bottom: 1px solid var(--line);
|
||||||
|
cursor: pointer; font: inherit;
|
||||||
|
}
|
||||||
|
.contact-pick-item:last-child { border-bottom: none; }
|
||||||
|
.contact-pick-item:hover { background: var(--surface-2); }
|
||||||
|
.contact-pick-item .n { font-weight: 600; font-size: 13px; color: var(--text); }
|
||||||
|
.contact-pick-item .e { font-size: 12px; color: var(--muted); }
|
||||||
|
|
||||||
/* ---------- Responsive: collapse sidebar to top bar on narrow screens ---------- */
|
/* ---------- Responsive: collapse sidebar to top bar on narrow screens ---------- */
|
||||||
@media (max-width: 760px) {
|
@media (max-width: 760px) {
|
||||||
.app { flex-direction: column; }
|
.app { flex-direction: column; }
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
import { adjustPoints, getAllContacts, resetQrToken, updateContact, upsertContact } from '../lib/api';
|
import { adjustPoints, getAllContacts, updateContact, upsertContact } from '../lib/api';
|
||||||
import type { Contact } from '../lib/types';
|
import type { Contact } from '../lib/types';
|
||||||
import { useToast } from '../context/ToastContext';
|
import { useToast } from '../context/ToastContext';
|
||||||
import { Avatar, Empty, Modal, QrImage, Spinner, Toggle } from '../components/ui';
|
import { Avatar, Empty, Modal, Spinner, Toggle } from '../components/ui';
|
||||||
|
|
||||||
export function Contacts() {
|
export function Contacts() {
|
||||||
const { push } = useToast();
|
const { push } = useToast();
|
||||||
@@ -12,10 +12,7 @@ export function Contacts() {
|
|||||||
|
|
||||||
const [editing, setEditing] = useState<Contact | null>(null);
|
const [editing, setEditing] = useState<Contact | null>(null);
|
||||||
const [creating, setCreating] = useState(false);
|
const [creating, setCreating] = useState(false);
|
||||||
const [qrFor, setQrFor] = useState<Contact | null>(null);
|
|
||||||
const [newToken, setNewToken] = useState<string | null>(null);
|
|
||||||
const [pointsFor, setPointsFor] = useState<Contact | null>(null);
|
const [pointsFor, setPointsFor] = useState<Contact | null>(null);
|
||||||
const [busy, setBusy] = useState(false);
|
|
||||||
|
|
||||||
async function load() {
|
async function load() {
|
||||||
try {
|
try {
|
||||||
@@ -37,26 +34,10 @@ export function Contacts() {
|
|||||||
(c) =>
|
(c) =>
|
||||||
c.full_name.toLowerCase().includes(q) ||
|
c.full_name.toLowerCase().includes(q) ||
|
||||||
c.email.toLowerCase().includes(q) ||
|
c.email.toLowerCase().includes(q) ||
|
||||||
(c.linkedin_url ?? '').toLowerCase().includes(q) ||
|
(c.linkedin_url ?? '').toLowerCase().includes(q),
|
||||||
(c.qr_token ?? '').toLowerCase().includes(q),
|
|
||||||
);
|
);
|
||||||
}, [contacts, query]);
|
}, [contacts, query]);
|
||||||
|
|
||||||
async function doResetQr(c: Contact) {
|
|
||||||
setBusy(true);
|
|
||||||
try {
|
|
||||||
const res = await resetQrToken(c.email);
|
|
||||||
setNewToken(res.qr_token);
|
|
||||||
setQrFor(c);
|
|
||||||
await load();
|
|
||||||
push('success', `New QR token issued for ${c.full_name}`);
|
|
||||||
} catch (e) {
|
|
||||||
push('error', e instanceof Error ? e.message : 'Reset failed');
|
|
||||||
} finally {
|
|
||||||
setBusy(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error) return <Empty icon="⚠️" text={error} />;
|
if (error) return <Empty icon="⚠️" text={error} />;
|
||||||
if (!contacts)
|
if (!contacts)
|
||||||
return (
|
return (
|
||||||
@@ -70,13 +51,13 @@ export function Contacts() {
|
|||||||
<div className="page-head">
|
<div className="page-head">
|
||||||
<div>
|
<div>
|
||||||
<h1>Contacts</h1>
|
<h1>Contacts</h1>
|
||||||
<div className="sub">{contacts.length} people · manage contacts, QR tokens, and points.</div>
|
<div className="sub">{contacts.length} people · manage contacts and points.</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="row" style={{ gap: 10 }}>
|
<div className="row" style={{ gap: 10 }}>
|
||||||
<input
|
<input
|
||||||
className="input"
|
className="input"
|
||||||
style={{ maxWidth: 260 }}
|
style={{ maxWidth: 260 }}
|
||||||
placeholder="Search name, email, token…"
|
placeholder="Search name, email…"
|
||||||
value={query}
|
value={query}
|
||||||
onChange={(e) => setQuery(e.target.value)}
|
onChange={(e) => setQuery(e.target.value)}
|
||||||
/>
|
/>
|
||||||
@@ -94,7 +75,6 @@ export function Contacts() {
|
|||||||
<th>LinkedIn</th>
|
<th>LinkedIn</th>
|
||||||
<th>Visibility</th>
|
<th>Visibility</th>
|
||||||
<th>Admin</th>
|
<th>Admin</th>
|
||||||
<th>QR token</th>
|
|
||||||
<th style={{ textAlign: 'right' }}>Actions</th>
|
<th style={{ textAlign: 'right' }}>Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -132,17 +112,11 @@ export function Contacts() {
|
|||||||
<td>
|
<td>
|
||||||
{c.is_admin ? <span className="pill admin">admin</span> : <span className="muted small">—</span>}
|
{c.is_admin ? <span className="pill admin">admin</span> : <span className="muted small">—</span>}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
|
||||||
<span className="mono small">{c.qr_token ?? '—'}</span>
|
|
||||||
</td>
|
|
||||||
<td>
|
<td>
|
||||||
<div className="row-actions">
|
<div className="row-actions">
|
||||||
<button className="btn small" onClick={() => setEditing(c)}>
|
<button className="btn small" onClick={() => setEditing(c)}>
|
||||||
Edit
|
Edit
|
||||||
</button>
|
</button>
|
||||||
<button className="btn small" onClick={() => { setNewToken(null); setQrFor(c); }}>
|
|
||||||
QR
|
|
||||||
</button>
|
|
||||||
<button className="btn small" onClick={() => setPointsFor(c)}>
|
<button className="btn small" onClick={() => setPointsFor(c)}>
|
||||||
Points
|
Points
|
||||||
</button>
|
</button>
|
||||||
@@ -178,42 +152,6 @@ export function Contacts() {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{qrFor && (
|
|
||||||
<Modal
|
|
||||||
open
|
|
||||||
title={`QR — ${qrFor.full_name}`}
|
|
||||||
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>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{pointsFor && (
|
{pointsFor && (
|
||||||
<AdjustPointsModal
|
<AdjustPointsModal
|
||||||
contact={pointsFor}
|
contact={pointsFor}
|
||||||
@@ -361,7 +299,7 @@ function CreateContactModal({
|
|||||||
<div className="row">
|
<div className="row">
|
||||||
<Toggle checked={isAdmin} onChange={setIsAdmin} label="Admin / staff" />
|
<Toggle checked={isAdmin} onChange={setIsAdmin} label="Admin / staff" />
|
||||||
</div>
|
</div>
|
||||||
<p className="muted small">A QR token is generated automatically and becomes the login password.</p>
|
<p className="muted small">A QR token is generated when the contact is registered for an event — it becomes the login password.</p>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,13 @@ import {
|
|||||||
getAllContacts,
|
getAllContacts,
|
||||||
getActiveEvent,
|
getActiveEvent,
|
||||||
getRegistrations,
|
getRegistrations,
|
||||||
|
resetQrToken,
|
||||||
setCheckedIn,
|
setCheckedIn,
|
||||||
setRegistrationType,
|
setRegistrationType,
|
||||||
} from '../lib/api';
|
} from '../lib/api';
|
||||||
import type { Contact, Event, Registration, RegistrationType } from '../lib/types';
|
import type { Contact, Event, Registration, RegistrationType } from '../lib/types';
|
||||||
import { useToast } from '../context/ToastContext';
|
import { useToast } from '../context/ToastContext';
|
||||||
import { Avatar, Empty, Modal, Spinner, Toggle, TypeBadge } from '../components/ui';
|
import { Avatar, Empty, Modal, QrImage, Spinner, Toggle, TypeBadge } from '../components/ui';
|
||||||
|
|
||||||
const TYPES: RegistrationType[] = ['attendee', 'speaker', 'staff', 'sponsor'];
|
const TYPES: RegistrationType[] = ['attendee', 'speaker', 'staff', 'sponsor'];
|
||||||
|
|
||||||
@@ -22,6 +23,8 @@ export function Registrations() {
|
|||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [query, setQuery] = useState('');
|
const [query, setQuery] = useState('');
|
||||||
const [adding, setAdding] = useState(false);
|
const [adding, setAdding] = useState(false);
|
||||||
|
const [qrFor, setQrFor] = useState<Registration | null>(null);
|
||||||
|
const [newToken, setNewToken] = useState<string | null>(null);
|
||||||
const [busy, setBusy] = useState(false);
|
const [busy, setBusy] = useState(false);
|
||||||
|
|
||||||
async function load() {
|
async function load() {
|
||||||
@@ -84,6 +87,21 @@ export function Registrations() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 (error) return <Empty icon="⚠️" text={error} />;
|
||||||
if (!loaded)
|
if (!loaded)
|
||||||
return (
|
return (
|
||||||
@@ -137,6 +155,7 @@ export function Registrations() {
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Contact</th>
|
<th>Contact</th>
|
||||||
<th>Type</th>
|
<th>Type</th>
|
||||||
|
<th>QR token</th>
|
||||||
<th>Checked in</th>
|
<th>Checked in</th>
|
||||||
<th style={{ textAlign: 'right' }}>Points</th>
|
<th style={{ textAlign: 'right' }}>Points</th>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -173,6 +192,14 @@ export function Registrations() {
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</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>
|
<td>
|
||||||
<Toggle checked={r.checked_in} onChange={(v) => toggleCheckedIn(r, v)} />
|
<Toggle checked={r.checked_in} onChange={(v) => toggleCheckedIn(r, v)} />
|
||||||
</td>
|
</td>
|
||||||
@@ -199,6 +226,42 @@ export function Registrations() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{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>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ export function Schedule() {
|
|||||||
</div>
|
</div>
|
||||||
<div className="muted small" style={{ marginTop: 4 }}>
|
<div className="muted small" style={{ marginTop: 4 }}>
|
||||||
{s.average_feedback != null && <span>⭐ {s.average_feedback.toFixed(1)}</span>}
|
{s.average_feedback != null && <span>⭐ {s.average_feedback.toFixed(1)}</span>}
|
||||||
{s.material_path && <span> · 📎 material</span>}
|
<span> · {s.material_path ? '📎 material submitted' : '⬜ material not submitted'}</span>
|
||||||
{s.ai_generated_feedback && (
|
{s.ai_generated_feedback && (
|
||||||
<span className="ai-state"> · 🤖 {s.ai_generated_feedback}</span>
|
<span className="ai-state"> · 🤖 {s.ai_generated_feedback}</span>
|
||||||
)}
|
)}
|
||||||
@@ -320,7 +320,7 @@ function SlotModal({
|
|||||||
<select className="input" value={type} onChange={(e) => setType(e.target.value as SlotType)}>
|
<select className="input" value={type} onChange={(e) => setType(e.target.value as SlotType)}>
|
||||||
{SLOT_TYPES.map((t) => (
|
{SLOT_TYPES.map((t) => (
|
||||||
<option key={t} value={t}>
|
<option key={t} value={t}>
|
||||||
{t.replace('_', ' ')}
|
{t.replace(/_/g, ' ')}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
@@ -448,18 +448,11 @@ function SessionModal({
|
|||||||
|
|
||||||
<div className="field">
|
<div className="field">
|
||||||
<label>Speakers ({speakerEmails.length})</label>
|
<label>Speakers ({speakerEmails.length})</label>
|
||||||
<div className="speaker-pick">
|
<SpeakerMultiSelect
|
||||||
{contacts.map((c) => (
|
contacts={contacts}
|
||||||
<label key={c.email} className={`speaker-opt ${speakerEmails.includes(c.email) ? 'on' : ''}`}>
|
selected={speakerEmails}
|
||||||
<input
|
onToggle={toggleSpeaker}
|
||||||
type="checkbox"
|
|
||||||
checked={speakerEmails.includes(c.email)}
|
|
||||||
onChange={() => toggleSpeaker(c.email)}
|
|
||||||
/>
|
/>
|
||||||
{c.full_name}
|
|
||||||
</label>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
{speakerEmails.length === 0 && (
|
{speakerEmails.length === 0 && (
|
||||||
<span className="muted small">A session needs at least one speaker.</span>
|
<span className="muted small">A session needs at least one speaker.</span>
|
||||||
)}
|
)}
|
||||||
@@ -510,6 +503,69 @@ function SessionModal({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Multi-select with a search box: type to filter, click to add/remove. */
|
||||||
|
function SpeakerMultiSelect({
|
||||||
|
contacts,
|
||||||
|
selected,
|
||||||
|
onToggle,
|
||||||
|
}: {
|
||||||
|
contacts: Contact[];
|
||||||
|
selected: string[];
|
||||||
|
onToggle: (email: string) => void;
|
||||||
|
}) {
|
||||||
|
const [query, setQuery] = useState('');
|
||||||
|
const nameOf = (email: string) => contacts.find((c) => c.email === email)?.full_name ?? email;
|
||||||
|
|
||||||
|
const q = query.trim().toLowerCase();
|
||||||
|
const matches = (q
|
||||||
|
? contacts.filter(
|
||||||
|
(c) => c.full_name.toLowerCase().includes(q) || c.email.toLowerCase().includes(q),
|
||||||
|
)
|
||||||
|
: contacts
|
||||||
|
).slice(0, 8);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="msel">
|
||||||
|
{selected.length > 0 && (
|
||||||
|
<div className="msel-chips">
|
||||||
|
{selected.map((email) => (
|
||||||
|
<span key={email} className="msel-chip">
|
||||||
|
{nameOf(email)}
|
||||||
|
<button className="msel-x" onClick={() => onToggle(email)} aria-label={`Remove ${nameOf(email)}`}>
|
||||||
|
✕
|
||||||
|
</button>
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<input
|
||||||
|
className="input"
|
||||||
|
placeholder="Search speakers by name or email…"
|
||||||
|
value={query}
|
||||||
|
onChange={(e) => setQuery(e.target.value)}
|
||||||
|
/>
|
||||||
|
{matches.length > 0 && (
|
||||||
|
<div className="msel-list">
|
||||||
|
{matches.map((c) => {
|
||||||
|
const on = selected.includes(c.email);
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
key={c.email}
|
||||||
|
className={`msel-item ${on ? 'on' : ''}`}
|
||||||
|
onClick={() => onToggle(c.email)}
|
||||||
|
>
|
||||||
|
<span className="msel-check">{on ? '✓' : ''}</span>
|
||||||
|
<span className="n">{c.full_name}</span>
|
||||||
|
<span className="e">{c.email}</span>
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function fmtDate(d: string): string {
|
function fmtDate(d: string): string {
|
||||||
return new Date(d + 'T00:00:00').toLocaleDateString([], { weekday: 'short', month: 'short', day: 'numeric' });
|
return new Date(d + 'T00:00:00').toLocaleDateString([], { weekday: 'short', month: 'short', day: 'numeric' });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -186,8 +186,19 @@ function SponsorModal({
|
|||||||
const [paid, setPaid] = useState(sponsor?.paid ?? false);
|
const [paid, setPaid] = useState(sponsor?.paid ?? false);
|
||||||
const [amount, setAmount] = useState(sponsor?.amount_eur != null ? String(sponsor.amount_eur) : '');
|
const [amount, setAmount] = useState(sponsor?.amount_eur != null ? String(sponsor.amount_eur) : '');
|
||||||
const [contactEmail, setContactEmail] = useState(sponsor?.contact_email ?? '');
|
const [contactEmail, setContactEmail] = useState(sponsor?.contact_email ?? '');
|
||||||
|
const [contactQuery, setContactQuery] = useState('');
|
||||||
const [busy, setBusy] = useState(false);
|
const [busy, setBusy] = useState(false);
|
||||||
|
|
||||||
|
const contactMatches = (() => {
|
||||||
|
const q = contactQuery.trim().toLowerCase();
|
||||||
|
const list = q
|
||||||
|
? contacts.filter(
|
||||||
|
(c) => c.full_name.toLowerCase().includes(q) || c.email.toLowerCase().includes(q),
|
||||||
|
)
|
||||||
|
: contacts;
|
||||||
|
return list.slice(0, 6);
|
||||||
|
})();
|
||||||
|
|
||||||
async function save() {
|
async function save() {
|
||||||
if (!name.trim()) return;
|
if (!name.trim()) return;
|
||||||
setBusy(true);
|
setBusy(true);
|
||||||
@@ -259,14 +270,42 @@ function SponsorModal({
|
|||||||
</div>
|
</div>
|
||||||
<div className="field">
|
<div className="field">
|
||||||
<label>Contact (lookup)</label>
|
<label>Contact (lookup)</label>
|
||||||
<select className="input" value={contactEmail} onChange={(e) => setContactEmail(e.target.value)}>
|
{contactEmail ? (
|
||||||
<option value="">— none —</option>
|
<div className="row" style={{ gap: 8 }}>
|
||||||
{contacts.map((c) => (
|
<span className="input" style={{ flex: 1, display: 'flex', alignItems: 'center' }}>
|
||||||
<option key={c.email} value={c.email}>
|
{contacts.find((c) => c.email === contactEmail)?.full_name ?? contactEmail}
|
||||||
{c.full_name}
|
</span>
|
||||||
</option>
|
<button className="btn small" onClick={() => { setContactEmail(''); setContactQuery(''); }}>
|
||||||
|
Clear
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<input
|
||||||
|
className="input"
|
||||||
|
placeholder="Search name or email…"
|
||||||
|
value={contactQuery}
|
||||||
|
onChange={(e) => setContactQuery(e.target.value)}
|
||||||
|
/>
|
||||||
|
{contactMatches.length > 0 && (
|
||||||
|
<div className="contact-pick">
|
||||||
|
{contactMatches.map((c) => (
|
||||||
|
<button
|
||||||
|
key={c.email}
|
||||||
|
className="contact-pick-item"
|
||||||
|
onClick={() => {
|
||||||
|
setContactEmail(c.email);
|
||||||
|
setContactQuery('');
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span className="n">{c.full_name}</span>
|
||||||
|
<span className="e">{c.email}</span>
|
||||||
|
</button>
|
||||||
))}
|
))}
|
||||||
</select>
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="row">
|
<div className="row">
|
||||||
|
|||||||
@@ -46,6 +46,13 @@ function Shell() {
|
|||||||
// Keep the Connect red-dot fresh: poll every 5s while visible.
|
// Keep the Connect red-dot fresh: poll every 5s while visible.
|
||||||
usePolling(() => void loadPending(), 5000, !!email);
|
usePolling(() => void loadPending(), 5000, !!email);
|
||||||
|
|
||||||
|
// Recalc immediately when a connection is accepted/declined/sent.
|
||||||
|
useEffect(() => {
|
||||||
|
const onChanged = () => void loadPending();
|
||||||
|
window.addEventListener('connections-changed', onChanged);
|
||||||
|
return () => window.removeEventListener('connections-changed', onChanged);
|
||||||
|
}, [loadPending]);
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return (
|
return (
|
||||||
<div className="app">
|
<div className="app">
|
||||||
|
|||||||
@@ -41,3 +41,8 @@ export function greeting(now: Date): string {
|
|||||||
if (h < 18) return 'Good afternoon';
|
if (h < 18) return 'Good afternoon';
|
||||||
return 'Good evening';
|
return 'Good evening';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** "lunch_break" → "Lunch Break" (capitalize each word). */
|
||||||
|
export function capWords(s: string): string {
|
||||||
|
return s.replace(/_/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase());
|
||||||
|
}
|
||||||
@@ -10,11 +10,12 @@ export interface Contact {
|
|||||||
show_email: boolean;
|
show_email: boolean;
|
||||||
show_linkedin: boolean;
|
show_linkedin: boolean;
|
||||||
is_admin: boolean;
|
is_admin: boolean;
|
||||||
qr_token: string | null;
|
|
||||||
created_at: string;
|
created_at: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The signed-in contact's registration for the active event. */
|
/** 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. */
|
||||||
export interface Registration {
|
export interface Registration {
|
||||||
id: string;
|
id: string;
|
||||||
event_id: string;
|
event_id: string;
|
||||||
@@ -22,6 +23,7 @@ export interface Registration {
|
|||||||
type: RegistrationType;
|
type: RegistrationType;
|
||||||
checked_in: boolean;
|
checked_in: boolean;
|
||||||
points: number;
|
points: number;
|
||||||
|
qr_token: string | null;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import { useAuth } from '../context/AuthContext';
|
import { useAuth } from '../context/AuthContext';
|
||||||
import { acceptConnection, getMyConnections, getPublicContacts, rejectConnection } from '../lib/api';
|
import { acceptConnection, getLeaderboard, getMyConnections, getPublicContacts, rejectConnection } from '../lib/api';
|
||||||
import { usePolling } from '../lib/usePolling';
|
import { usePolling } from '../lib/usePolling';
|
||||||
|
import { capWords } from '../lib/time';
|
||||||
import type { Connection, PublicContact } from '../lib/types';
|
import type { Connection, PublicContact } from '../lib/types';
|
||||||
import { Avatar, Empty, Spinner } from '../components/ui';
|
import { Avatar, Empty, Sheet, Spinner } from '../components/ui';
|
||||||
import { useToast } from '../context/ToastContext';
|
import { useToast } from '../context/ToastContext';
|
||||||
|
|
||||||
export function Connections() {
|
export function Connections() {
|
||||||
@@ -11,14 +12,17 @@ export function Connections() {
|
|||||||
const [tab, setTab] = useState<'mine' | 'req'>('mine');
|
const [tab, setTab] = useState<'mine' | 'req'>('mine');
|
||||||
const [conns, setConns] = useState<Connection[]>([]);
|
const [conns, setConns] = useState<Connection[]>([]);
|
||||||
const [people, setPeople] = useState<Map<string, PublicContact>>(new Map());
|
const [people, setPeople] = useState<Map<string, PublicContact>>(new Map());
|
||||||
|
const [points, setPoints] = useState<Map<string, number>>(new Map());
|
||||||
|
const [detail, setDetail] = useState<{ email: string; status: Connection['status'] } | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
const load = useCallback(async () => {
|
const load = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
const [c, p] = await Promise.all([getMyConnections(), getPublicContacts()]);
|
const [c, p, lb] = await Promise.all([getMyConnections(), getPublicContacts(), getLeaderboard()]);
|
||||||
setConns(c);
|
setConns(c);
|
||||||
setPeople(new Map(p.map((x) => [x.email, x])));
|
setPeople(new Map(p.map((x) => [x.email, x])));
|
||||||
|
setPoints(new Map(lb.map((x) => [x.contact_email, x.points])));
|
||||||
} catch {
|
} catch {
|
||||||
/* non-fatal */
|
/* non-fatal */
|
||||||
} finally {
|
} finally {
|
||||||
@@ -37,6 +41,7 @@ export function Connections() {
|
|||||||
const me = contact.email;
|
const me = contact.email;
|
||||||
const nameOf = (email: string) => people.get(email)?.full_name ?? '…';
|
const nameOf = (email: string) => people.get(email)?.full_name ?? '…';
|
||||||
const typeOf = (email: string) => people.get(email)?.registration_type ?? null;
|
const typeOf = (email: string) => people.get(email)?.registration_type ?? null;
|
||||||
|
const pointsOf = (email: string) => points.get(email) ?? 0;
|
||||||
|
|
||||||
const accepted = conns.filter((c) => c.status === 'accepted');
|
const accepted = conns.filter((c) => c.status === 'accepted');
|
||||||
const incoming = conns.filter((c) => c.status === 'pending' && c.to_email === me);
|
const incoming = conns.filter((c) => c.status === 'pending' && c.to_email === me);
|
||||||
@@ -47,6 +52,7 @@ export function Connections() {
|
|||||||
if (accept) await acceptConnection(id);
|
if (accept) await acceptConnection(id);
|
||||||
else await rejectConnection(id);
|
else await rejectConnection(id);
|
||||||
toast(accept ? 'Connected! +5 pts 🤝' : 'Request declined', accept ? 'ok' : '');
|
toast(accept ? 'Connected! +5 pts 🤝' : 'Request declined', accept ? 'ok' : '');
|
||||||
|
window.dispatchEvent(new Event('connections-changed'));
|
||||||
await load();
|
await load();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast(e instanceof Error ? e.message : 'Could not update request', 'err');
|
toast(e instanceof Error ? e.message : 'Could not update request', 'err');
|
||||||
@@ -80,11 +86,13 @@ export function Connections() {
|
|||||||
accepted.map((c) => {
|
accepted.map((c) => {
|
||||||
const otherEmail = c.from_email === me ? c.to_email : c.from_email;
|
const otherEmail = c.from_email === me ? c.to_email : c.from_email;
|
||||||
return (
|
return (
|
||||||
<div className="conn" key={c.id}>
|
<div className="conn clickable" key={c.id} onClick={() => setDetail({ email: otherEmail, status: c.status })}>
|
||||||
<Avatar name={nameOf(otherEmail)} id={otherEmail} size={44} />
|
<Avatar name={nameOf(otherEmail)} id={otherEmail} size={44} />
|
||||||
<div className="grow">
|
<div className="grow">
|
||||||
<div className="name">{nameOf(otherEmail)}</div>
|
<div className="name">{nameOf(otherEmail)}</div>
|
||||||
{typeOf(otherEmail) && <div className="meta">{typeOf(otherEmail)!.replace('_', ' ')}</div>}
|
{typeOf(otherEmail) && (
|
||||||
|
<div className="meta">{capWords(typeOf(otherEmail)!)}</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<span className="pill green">Connected</span>
|
<span className="pill green">Connected</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -102,10 +110,15 @@ export function Connections() {
|
|||||||
<div className="muted small" style={{ marginBottom: 8, fontWeight: 700 }}>Incoming</div>
|
<div className="muted small" style={{ marginBottom: 8, fontWeight: 700 }}>Incoming</div>
|
||||||
{incoming.map((c) => (
|
{incoming.map((c) => (
|
||||||
<div className="conn" key={c.id}>
|
<div className="conn" key={c.id}>
|
||||||
|
<div className="clickable" style={{ display: 'flex', alignItems: 'center', gap: 10, flex: 1 }}
|
||||||
|
onClick={() => setDetail({ email: c.from_email, status: c.status })}>
|
||||||
<Avatar name={nameOf(c.from_email)} id={c.from_email} size={44} />
|
<Avatar name={nameOf(c.from_email)} id={c.from_email} size={44} />
|
||||||
<div className="grow">
|
<div className="grow">
|
||||||
<div className="name">{nameOf(c.from_email)}</div>
|
<div className="name">{nameOf(c.from_email)}</div>
|
||||||
{typeOf(c.from_email) && <div className="meta">{typeOf(c.from_email)!.replace('_', ' ')}</div>}
|
{typeOf(c.from_email) && (
|
||||||
|
<div className="meta">{capWords(typeOf(c.from_email)!)}</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button className="btn primary small" onClick={() => resolve(c.id, true)}>Accept</button>
|
<button className="btn primary small" onClick={() => resolve(c.id, true)}>Accept</button>
|
||||||
<button className="btn small" onClick={() => resolve(c.id, false)}>Decline</button>
|
<button className="btn small" onClick={() => resolve(c.id, false)}>Decline</button>
|
||||||
@@ -117,11 +130,13 @@ export function Connections() {
|
|||||||
<div>
|
<div>
|
||||||
<div className="muted small" style={{ marginBottom: 8, fontWeight: 700 }}>Sent</div>
|
<div className="muted small" style={{ marginBottom: 8, fontWeight: 700 }}>Sent</div>
|
||||||
{outgoing.map((c) => (
|
{outgoing.map((c) => (
|
||||||
<div className="conn" key={c.id}>
|
<div className="conn clickable" key={c.id} onClick={() => setDetail({ email: c.to_email, status: c.status })}>
|
||||||
<Avatar name={nameOf(c.to_email)} id={c.to_email} size={44} />
|
<Avatar name={nameOf(c.to_email)} id={c.to_email} size={44} />
|
||||||
<div className="grow">
|
<div className="grow">
|
||||||
<div className="name">{nameOf(c.to_email)}</div>
|
<div className="name">{nameOf(c.to_email)}</div>
|
||||||
{typeOf(c.to_email) && <div className="meta">{typeOf(c.to_email)!.replace('_', ' ')}</div>}
|
{typeOf(c.to_email) && (
|
||||||
|
<div className="meta">{capWords(typeOf(c.to_email)!)}</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<span className="pill amber">Pending</span>
|
<span className="pill amber">Pending</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -130,6 +145,32 @@ export function Connections() {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{detail && (() => {
|
||||||
|
const p = people.get(detail.email);
|
||||||
|
const t = p?.registration_type ?? null;
|
||||||
|
return (
|
||||||
|
<Sheet open onClose={() => setDetail(null)}>
|
||||||
|
<div className="center" style={{ flexDirection: 'column', gap: 10, padding: '8px 0 20px' }}>
|
||||||
|
<Avatar name={p?.full_name ?? '…'} id={detail.email} size={72} />
|
||||||
|
<div className="h2" style={{ textAlign: 'center' }}>{p?.full_name ?? '…'}</div>
|
||||||
|
<div className="row" style={{ justifyContent: 'center', gap: 8 }}>
|
||||||
|
{t && <span className={`pill reg-${t}`}>{capWords(t)}</span>}
|
||||||
|
<span className="pill violet">⚡ {pointsOf(detail.email)} pts</span>
|
||||||
|
</div>
|
||||||
|
{p?.linkedin_url && (
|
||||||
|
<a className="link" href={p.linkedin_url} target="_blank" rel="noreferrer">
|
||||||
|
{p.linkedin_url.replace(/^https?:\/\//, '')}
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
{p?.show_email && <div className="muted small">{detail.email}</div>}
|
||||||
|
<div className="muted small">
|
||||||
|
{detail.status === 'accepted' ? 'Connected' : detail.status === 'pending' ? 'Request pending' : 'Request declined'}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Sheet>
|
||||||
|
);
|
||||||
|
})()}
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
|
|||||||
import { useAuth } from '../context/AuthContext';
|
import { useAuth } from '../context/AuthContext';
|
||||||
import { useEvent } from '../lib/useEvent';
|
import { useEvent } from '../lib/useEvent';
|
||||||
import { getMyCheckins, getMyPreferences } from '../lib/api';
|
import { getMyCheckins, getMyPreferences } from '../lib/api';
|
||||||
import { fmtRange, greeting, slotStatus } from '../lib/time';
|
import { capWords, fmtRange, greeting, slotStatus } from '../lib/time';
|
||||||
import type { Preference } from '../lib/types';
|
import type { Preference } from '../lib/types';
|
||||||
import { Avatar, Empty, Spinner } from '../components/ui';
|
import { Avatar, Empty, Spinner } from '../components/ui';
|
||||||
|
|
||||||
@@ -107,22 +107,23 @@ export function Home({ go }: { go: (tab: string) => void }) {
|
|||||||
<div>
|
<div>
|
||||||
<div className="row between" style={{ marginBottom: 9 }}>
|
<div className="row between" style={{ marginBottom: 9 }}>
|
||||||
<span className="h2">My picks today</span>
|
<span className="h2">My picks today</span>
|
||||||
<span className="muted small">tap to change</span>
|
<a className="muted small link" onClick={() => go('agenda')}>tap to change</a>
|
||||||
</div>
|
</div>
|
||||||
<div style={{ display: 'flex', flexDirection: 'column' }}>
|
<div style={{ display: 'flex', flexDirection: 'column' }}>
|
||||||
{slots.map(({ slot }) => {
|
{[
|
||||||
const sid = pickFor(slot.id);
|
{ label: 'Now', slot: current?.slot, session: nowSession },
|
||||||
const s = sid ? sessionById.get(sid) : undefined;
|
{ label: 'Next', slot: next?.slot, session: nextSession },
|
||||||
return (
|
]
|
||||||
<button key={slot.id} className="pick-chip" onClick={() => go('agenda')}>
|
.filter((r) => r.slot)
|
||||||
<span className="t">{fmtRange(slot)}</span>
|
.map((r) => (
|
||||||
|
<button key={r.label} className="pick-chip" onClick={() => go('agenda')}>
|
||||||
|
<span className="t">{fmtRange(r.slot!)}</span>
|
||||||
<span className="grow" style={{ fontWeight: 600, textAlign: 'left' }}>
|
<span className="grow" style={{ fontWeight: 600, textAlign: 'left' }}>
|
||||||
{s ? s.title : 'No pick yet'}
|
{r.session ? r.session.title : 'No pick yet'}
|
||||||
</span>
|
</span>
|
||||||
{s && <span className="muted small">{s.room}</span>}
|
{r.session && <span className="muted small">{r.session.room}</span>}
|
||||||
</button>
|
</button>
|
||||||
);
|
))}
|
||||||
})}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -145,9 +146,11 @@ export function Home({ go }: { go: (tab: string) => void }) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style={{ height: 8 }} />
|
<div style={{ height: 8 }} />
|
||||||
|
{registration && registration.type !== 'attendee' && (
|
||||||
<div className="muted small" style={{ textAlign: 'center', opacity: 0.5 }}>
|
<div className="muted small" style={{ textAlign: 'center', opacity: 0.5 }}>
|
||||||
<Avatar name={contact.full_name} id={contact.email} size={22} fs={9} /> {registration?.type.replace('_', ' ') ?? ''}
|
<Avatar name={contact.full_name} id={contact.email} size={22} fs={9} /> {capWords(registration.type)}
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { supabase } from '../lib/supabase';
|
import { supabase } from '../lib/supabase';
|
||||||
import { lanyardLookup } from '../lib/api';
|
import { lanyardLookup } from '../lib/api';
|
||||||
|
import { capWords } from '../lib/time';
|
||||||
import type { PublicContact } from '../lib/types';
|
import type { PublicContact } from '../lib/types';
|
||||||
import { Avatar, Scanner } from '../components/ui';
|
import { Avatar, Scanner } from '../components/ui';
|
||||||
import { useToast } from '../context/ToastContext';
|
import { useToast } from '../context/ToastContext';
|
||||||
@@ -88,7 +89,7 @@ export function Login() {
|
|||||||
<div>
|
<div>
|
||||||
<div className="h2">{found ? found.full_name : 'Lanyard found'}</div>
|
<div className="h2">{found ? found.full_name : 'Lanyard found'}</div>
|
||||||
<div className="muted small">
|
<div className="muted small">
|
||||||
{found ? (found.registration_type ? found.registration_type.replace('_', ' ') : 'Confirm it’s you') : 'Confirm it’s you'}
|
{found ? (found.registration_type ? capWords(found.registration_type) : 'Confirm it’s you') : 'Confirm it’s you'}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useAuth } from '../context/AuthContext';
|
import { useAuth } from '../context/AuthContext';
|
||||||
import { getMyPointsLog } from '../lib/api';
|
import { getMyPointsLog } from '../lib/api';
|
||||||
|
import { capWords } from '../lib/time';
|
||||||
import type { PointsLogRow } from '../lib/types';
|
import type { PointsLogRow } from '../lib/types';
|
||||||
import { Avatar, QrImage, Spinner } from '../components/ui';
|
import { Avatar, QrImage, Spinner } from '../components/ui';
|
||||||
|
|
||||||
@@ -49,7 +50,7 @@ export function Profile() {
|
|||||||
<div className="h2" style={{ marginTop: 10 }}>{contact.full_name}</div>
|
<div className="h2" style={{ marginTop: 10 }}>{contact.full_name}</div>
|
||||||
<div className="muted small">{contact.email}</div>
|
<div className="muted small">{contact.email}</div>
|
||||||
<div className="row" style={{ justifyContent: 'center', marginTop: 10, gap: 8 }}>
|
<div className="row" style={{ justifyContent: 'center', marginTop: 10, gap: 8 }}>
|
||||||
{registration && <span className={`pill reg-${registration.type}`}>{registration.type.replace('_', ' ')}</span>}
|
{registration && <span className={`pill reg-${registration.type}`}>{capWords(registration.type)}</span>}
|
||||||
{contact.is_admin && <span className="pill admin">staff</span>}
|
{contact.is_admin && <span className="pill admin">staff</span>}
|
||||||
<span className="pill amber">⚡ {points} pts</span>
|
<span className="pill amber">⚡ {points} pts</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -57,8 +58,8 @@ export function Profile() {
|
|||||||
|
|
||||||
<div className="card qr-wrap">
|
<div className="card qr-wrap">
|
||||||
<div className="h2">My QR code</div>
|
<div className="h2">My QR code</div>
|
||||||
{contact.qr_token ? (
|
{registration?.qr_token ? (
|
||||||
<QrImage value={contact.qr_token} size={180} />
|
<QrImage value={registration.qr_token} size={180} />
|
||||||
) : (
|
) : (
|
||||||
<div className="muted small">No QR token assigned.</div>
|
<div className="muted small">No QR token assigned.</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useEffect, useState } from 'react';
|
|||||||
import { useAuth } from '../context/AuthContext';
|
import { useAuth } from '../context/AuthContext';
|
||||||
import { useEvent } from '../lib/useEvent';
|
import { useEvent } from '../lib/useEvent';
|
||||||
import { checkinAttendee, createConnectionRequest, lanyardLookup } from '../lib/api';
|
import { checkinAttendee, createConnectionRequest, lanyardLookup } from '../lib/api';
|
||||||
|
import { capWords } from '../lib/time';
|
||||||
import type { CheckinResult, PublicContact } from '../lib/types';
|
import type { CheckinResult, PublicContact } from '../lib/types';
|
||||||
import { Avatar, Scanner, Sheet, Spinner } from '../components/ui';
|
import { Avatar, Scanner, Sheet, Spinner } from '../components/ui';
|
||||||
import { useToast } from '../context/ToastContext';
|
import { useToast } from '../context/ToastContext';
|
||||||
@@ -74,6 +75,7 @@ export function Scan() {
|
|||||||
if (conn.status === 'accepted') toast('You’re connected! 🤝', 'ok');
|
if (conn.status === 'accepted') toast('You’re connected! 🤝', 'ok');
|
||||||
else if (conn.status === 'pending') toast('Connection request sent', 'ok');
|
else if (conn.status === 'pending') toast('Connection request sent', 'ok');
|
||||||
else toast('Request already resolved');
|
else toast('Request already resolved');
|
||||||
|
window.dispatchEvent(new Event('connections-changed'));
|
||||||
setConnectTarget(null);
|
setConnectTarget(null);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast(e instanceof Error ? e.message : 'Could not send request', 'err');
|
toast(e instanceof Error ? e.message : 'Could not send request', 'err');
|
||||||
@@ -130,7 +132,7 @@ export function Scan() {
|
|||||||
<h3 style={{ marginTop: 12 }}>{connectTarget.contact.full_name}</h3>
|
<h3 style={{ marginTop: 12 }}>{connectTarget.contact.full_name}</h3>
|
||||||
{connectTarget.contact.registration_type && (
|
{connectTarget.contact.registration_type && (
|
||||||
<span className={`pill reg-${connectTarget.contact.registration_type}`} style={{ marginTop: 8 }}>
|
<span className={`pill reg-${connectTarget.contact.registration_type}`} style={{ marginTop: 8 }}>
|
||||||
{connectTarget.contact.registration_type.replace('_', ' ')}
|
{capWords(connectTarget.contact.registration_type)}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{connectTarget.contact.linkedin_url && (
|
{connectTarget.contact.linkedin_url && (
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ body {
|
|||||||
/* registration types */
|
/* registration types */
|
||||||
.pill.reg-attendee { background: rgba(148,163,184,.14); border-color: rgba(148,163,184,.4); color: #64748b; }
|
.pill.reg-attendee { background: rgba(148,163,184,.14); border-color: rgba(148,163,184,.4); color: #64748b; }
|
||||||
.pill.reg-speaker { background: rgba(124,58,237,.12); border-color: rgba(124,58,237,.4); color: #6d28d9; }
|
.pill.reg-speaker { background: rgba(124,58,237,.12); border-color: rgba(124,58,237,.4); color: #6d28d9; }
|
||||||
.pill.reg-staff { background: rgba(32,178,170,.13); border-color: rgba(32,178,170,.4); color: #0f766e; }
|
.pill.reg-staff { background: rgba(220,38,38,.12); border-color: rgba(220,38,38,.4); color: #b91c1c; }
|
||||||
.pill.reg-sponsor { background: rgba(234,88,12,.13); border-color: rgba(234,88,12,.4); color: #c2410c; }
|
.pill.reg-sponsor { background: rgba(234,88,12,.13); border-color: rgba(234,88,12,.4); color: #c2410c; }
|
||||||
/* slot types */
|
/* slot types */
|
||||||
.pill.slot-type-session { background: rgba(14,165,233,.12); border-color: rgba(14,165,233,.4); color: #0369a1; }
|
.pill.slot-type-session { background: rgba(14,165,233,.12); border-color: rgba(14,165,233,.4); color: #0369a1; }
|
||||||
@@ -279,3 +279,5 @@ textarea.input { resize: none; min-height: 96px; }
|
|||||||
@keyframes spin { to { transform: rotate(360deg); } }
|
@keyframes spin { to { transform: rotate(360deg); } }
|
||||||
.center { display: flex; align-items: center; justify-content: center; }
|
.center { display: flex; align-items: center; justify-content: center; }
|
||||||
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
|
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
|
||||||
|
.link { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
|
||||||
|
.clickable { cursor: pointer; }
|
||||||
@@ -95,10 +95,10 @@ flag. See [frontend/admin-app.md](./frontend/admin-app.md):
|
|||||||
Sponsors, Schedule (slots/sessions/speakers/material/AI-evaluate), Activity,
|
Sponsors, Schedule (slots/sessions/speakers/material/AI-evaluate), Activity,
|
||||||
Events, and **Interfaces** (trigger Pretix/Sessionize syncs + export the QR CSV).
|
Events, and **Interfaces** (trigger Pretix/Sessionize syncs + export the QR CSV).
|
||||||
- **Auth guard** — same QR + email login, but non-admin sessions are rejected.
|
- **Auth guard** — same QR + email login, but non-admin sessions are rejected.
|
||||||
- **Key RPCs** — `reset_qr_token` (regenerate a lanyard token + sync the Auth
|
- **Key RPCs** — `reset_registration_qr_token` (regenerate a registration's
|
||||||
password), `adjust_points`, `upsert_contact`, `create_registration`,
|
lanyard token + sync the Auth password), `adjust_points`, `upsert_contact`,
|
||||||
`set_registration_type`, `evaluate_session_feedback` (AI stub), and
|
`create_registration`, `set_registration_type`, `evaluate_session_feedback`
|
||||||
`set_session_material` (see [backend/rpcs.md](./backend/rpcs.md)).
|
(AI stub), and `set_session_material` (see [backend/rpcs.md](./backend/rpcs.md)).
|
||||||
|
|
||||||
## 5. How a request flows (example: staff check-in)
|
## 5. How a request flows (example: staff check-in)
|
||||||
|
|
||||||
@@ -182,7 +182,9 @@ Convivo/
|
|||||||
│ ├─ migrations/
|
│ ├─ migrations/
|
||||||
│ │ ├─ 20260822000000_init.sql # original schema (replaced by the Redesign)
|
│ │ ├─ 20260822000000_init.sql # original schema (replaced by the Redesign)
|
||||||
│ │ ├─ 20260823000000_admin_app.sql # admin read RLS + reset_qr_token (superseded)
|
│ │ ├─ 20260823000000_admin_app.sql # admin read RLS + reset_qr_token (superseded)
|
||||||
│ │ └─ 20260824000000_redesign.sql # ← current: multi-event model, RPCs, RLS, materials
|
│ │ ├─ 20260824000000_redesign.sql # multi-event model, RPCs, RLS, materials
|
||||||
|
│ │ ├─ 20260825000000_interfaces.sql # external_id + sync_runs + sync RPCs
|
||||||
|
│ │ └─ 20260826000000_registration_qr_token.sql # ← current: QR token on registration
|
||||||
│ └─ seed.sql # 1 event, 6 slots, 18 sessions, 14 contacts, demo state
|
│ └─ seed.sql # 1 event, 6 slots, 18 sessions, 14 contacts, demo state
|
||||||
├─ docker-compose.yml # Runs both app sidecars on the Supabase network
|
├─ docker-compose.yml # Runs both app sidecars on the Supabase network
|
||||||
├─ docs/ # ← this documentation
|
├─ docs/ # ← this documentation
|
||||||
|
|||||||
@@ -98,15 +98,18 @@ Input: a JSON array of
|
|||||||
`{ email, full_name, ticket_type, qr_token?, linkedin_url?, external_id? }`.
|
`{ email, full_name, ticket_type, qr_token?, linkedin_url?, external_id? }`.
|
||||||
|
|
||||||
For each item:
|
For each item:
|
||||||
- **Upsert the contact** by `email`. Keeps the existing QR token unless a new
|
- **Upsert the contact** by `email` (no token on the contact).
|
||||||
one is supplied; **generates a token** (`CVV-XXX-NNNN`) for new ticket holders
|
|
||||||
(Pretix doesn't provide one) so they can log in.
|
|
||||||
- **Ensure the auth user** exists (`_ensure_auth_user` — QR token = password).
|
|
||||||
- **Map the ticket type** to a registration type via `_map_ticket_type`
|
- **Map the ticket type** to a registration type via `_map_ticket_type`
|
||||||
(case-insensitive substring: `speaker` / `staff` / `sponsor`, else `attendee`).
|
(case-insensitive substring: `speaker` / `staff` / `sponsor`, else `attendee`).
|
||||||
- **Auto-create a sponsor row** if the type is `sponsor` (the sponsor rule
|
- **Auto-create a sponsor row** if the type is `sponsor` (the sponsor rule
|
||||||
requires a sponsor lookup).
|
requires a sponsor lookup).
|
||||||
- **Upsert the registration** for the active event (by contact).
|
- **Upsert the registration** for the active event (by contact). The **QR token
|
||||||
|
lives on the registration**: it keeps the existing token unless a new one is
|
||||||
|
supplied (so a re-sync never invalidates a lanyard), and **generates a token**
|
||||||
|
(`CVV-XXX-NNNN`) for new ticket holders (Pretix doesn't always provide one) so
|
||||||
|
they can log in.
|
||||||
|
- **Ensure the auth user** exists and **sync the token as the Auth password**
|
||||||
|
(QR token = password).
|
||||||
|
|
||||||
Returns `{ created, updated, skipped, errors[] }`.
|
Returns `{ created, updated, skipped, errors[] }`.
|
||||||
|
|
||||||
@@ -114,7 +117,7 @@ Returns `{ created, updated, skipped, errors[] }`.
|
|||||||
|
|
||||||
Input: a JSON array of
|
Input: a JSON array of
|
||||||
`{ external_id, title, description?, room?, capacity?, date, start_time, end_time,
|
`{ external_id, title, description?, room?, capacity?, date, start_time, end_time,
|
||||||
speakers: [{ email, full_name, qr_token? }] }`.
|
speakers: [{ email, full_name }] }`.
|
||||||
|
|
||||||
For each item:
|
For each item:
|
||||||
- **Find or create the slot** by `(event, date, start, end)` (new slots get an
|
- **Find or create the slot** by `(event, date, start, end)` (new slots get an
|
||||||
@@ -146,7 +149,7 @@ Interfaces view shows the last 8 runs.
|
|||||||
| `attendee_name` | `contacts.full_name` |
|
| `attendee_name` | `contacts.full_name` |
|
||||||
| `ticket_type` | `registrations.type` (via `_map_ticket_type`) |
|
| `ticket_type` | `registrations.type` (via `_map_ticket_type`) |
|
||||||
| `order_code` | `contacts.external_id` + `registrations.external_id` |
|
| `order_code` | `contacts.external_id` + `registrations.external_id` |
|
||||||
| *(generated)* | `contacts.qr_token` (for new ticket holders) |
|
| `qr_token` / *(generated)* | `registrations.qr_token` (Pretix per-ticket, or generated for new holders) |
|
||||||
|
|
||||||
| Sessionize field | → Convivo |
|
| Sessionize field | → Convivo |
|
||||||
|---|---|
|
|---|---|
|
||||||
|
|||||||
+20
-7
@@ -125,28 +125,41 @@ Used by the APPE Admin console to award prizes or correct mistakes. Goes through
|
|||||||
`_award_points`, so it floors at 0, writes `points_log`, and re-syncs the
|
`_award_points`, so it floors at 0, writes `points_log`, and re-syncs the
|
||||||
leaderboard.
|
leaderboard.
|
||||||
|
|
||||||
### `reset_qr_token(p_contact_email)` → `(email, qr_token)`
|
### `reset_registration_qr_token(p_contact_email)` → `(email, qr_token)`
|
||||||
**Admin-only.** Regenerates a contact's lanyard QR token.
|
**Admin-only.** Regenerates the lanyard QR token of a contact's **registration**
|
||||||
- Generates a fresh `CVV-XXX-NNNN` token and writes it to `contacts.qr_token`.
|
for the active event (the token lives on the registration, not the contact).
|
||||||
|
- Requires the contact to have a registration for the active event.
|
||||||
|
- Generates a fresh `CVV-XXX-NNNN` token and writes it to
|
||||||
|
`registrations.qr_token`.
|
||||||
- **Re-hashes it as the Auth password** (`extensions.crypt(token,
|
- **Re-hashes it as the Auth password** (`extensions.crypt(token,
|
||||||
extensions.gen_salt('bf'))` on `auth.users.encrypted_password`), so the **old
|
extensions.gen_salt('bf'))` on `auth.users.encrypted_password`), so the **old
|
||||||
token stops working** and the contact must re-scan with the new one.
|
token stops working** and the contact must re-scan with the new one.
|
||||||
- **Deletes the contact's existing `auth.sessions`**, forcing a re-login.
|
- **Deletes the contact's existing `auth.sessions`**, forcing a re-login.
|
||||||
- Returns the new token so the admin can print/show it as a QR code.
|
- Returns the new token so the admin can print/show it as a QR code.
|
||||||
|
|
||||||
|
> **Implementation note:** the function's output column is named `email`
|
||||||
|
> (`returns table (email, qr_token)`), so any reference to `auth.users.email`
|
||||||
|
> inside the body must be **qualified** (`auth.users.email`) — a bare `email`
|
||||||
|
> is ambiguous between the output column and the table column.
|
||||||
|
|
||||||
> **Implementation note:** pgcrypto's `gen_salt` / `crypt` live in the
|
> **Implementation note:** pgcrypto's `gen_salt` / `crypt` live in the
|
||||||
> `extensions` schema (not `public`), so the function — whose `search_path` is
|
> `extensions` schema (not `public`), so the function — whose `search_path` is
|
||||||
> pinned to `public` — must qualify them as `extensions.gen_salt(...)` /
|
> pinned to `public` — must qualify them as `extensions.gen_salt(...)` /
|
||||||
> `extensions.crypt(...)`. The function owner (`postgres`) can write
|
> `extensions.crypt(...)`. The function owner (`postgres`) can write
|
||||||
> `auth.users` and `auth.sessions`, which is what makes this possible.
|
> `auth.users` and `auth.sessions`, which is what makes this possible.
|
||||||
|
|
||||||
### `upsert_contact(p_email, p_full_name, p_linkedin_url, p_is_admin, p_qr_token)` → `contacts`
|
### `upsert_contact(p_email, p_full_name, p_linkedin_url, p_is_admin)` → `contacts`
|
||||||
**Admin-only.** Creates a contact if it doesn't exist (generating a QR token when
|
**Admin-only.** Creates a contact if it doesn't exist or updates the existing
|
||||||
none is given) or updates the existing one. Returns the contact row.
|
one. Contacts carry **no QR token** — the token is generated when a registration
|
||||||
|
is created. Ensures an `auth.users` row exists (with a placeholder password) so
|
||||||
|
the contact can log in once a registration token is issued. Returns the contact
|
||||||
|
row.
|
||||||
|
|
||||||
### `create_registration(p_contact_email, p_type)` → `registrations`
|
### `create_registration(p_contact_email, p_type)` → `registrations`
|
||||||
**Admin-only.** Creates a registration for the active event (enforces the
|
**Admin-only.** Creates a registration for the active event (enforces the
|
||||||
sponsor-type rule).
|
sponsor-type rule). **Generates a `CVV-XXX-NNNN` token** on the registration and
|
||||||
|
**syncs it as the Auth password**, so a newly registered contact can log in
|
||||||
|
immediately.
|
||||||
|
|
||||||
### `set_registration_type(p_contact_email, p_type)` → `registrations`
|
### `set_registration_type(p_contact_email, p_type)` → `registrations`
|
||||||
**Admin-only.** Changes a contact's registration type for the active event.
|
**Admin-only.** Changes a contact's registration type for the active event.
|
||||||
|
|||||||
@@ -44,7 +44,9 @@ erDiagram
|
|||||||
## `contacts` — people (source of truth)
|
## `contacts` — people (source of truth)
|
||||||
|
|
||||||
One row per person. **`email` is the primary key** (a natural key that matches
|
One row per person. **`email` is the primary key** (a natural key that matches
|
||||||
`auth.users.email`). The `qr_token` doubles as the Supabase Auth password.
|
`auth.users.email`). Contacts carry **no QR token** — the token lives on the
|
||||||
|
registration (it is generated per event by Pretix and doubles as the Auth
|
||||||
|
password).
|
||||||
|
|
||||||
| Column | Type | Notes |
|
| Column | Type | Notes |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
@@ -54,11 +56,9 @@ One row per person. **`email` is the primary key** (a natural key that matches
|
|||||||
| `show_email` | `boolean` | default `false` — visibility toggle |
|
| `show_email` | `boolean` | default `false` — visibility toggle |
|
||||||
| `show_linkedin` | `boolean` | default `false` — visibility toggle |
|
| `show_linkedin` | `boolean` | default `false` — visibility toggle |
|
||||||
| `is_admin` | `boolean` | default `false` — **staff = admin (merged)**; grants check-in + APPE Admin access |
|
| `is_admin` | `boolean` | default `false` — **staff = admin (merged)**; grants check-in + APPE Admin access |
|
||||||
| `qr_token` | `text` **unique** | The lanyard token; **doubles as the Auth password** |
|
|
||||||
| `external_id` | `text` | nullable — the Pretix order code (set by the sync) |
|
| `external_id` | `text` | nullable — the Pretix order code (set by the sync) |
|
||||||
| `created_at` | `timestamptz` | |
|
| `created_at` | `timestamptz` | |
|
||||||
|
|
||||||
Index: `contacts_qr_token_idx (qr_token)` — fast lanyard lookups.
|
|
||||||
Partial unique index: `contacts_external_id_uniq (external_id) WHERE external_id IS NOT NULL`.
|
Partial unique index: `contacts_external_id_uniq (external_id) WHERE external_id IS NOT NULL`.
|
||||||
|
|
||||||
## `events` — a conference
|
## `events` — a conference
|
||||||
@@ -96,11 +96,13 @@ Points are scoped **per event** here (one row per contact per event).
|
|||||||
| `type` | `text` | `attendee` \| `speaker` \| `staff` \| `sponsor` (default `attendee`) |
|
| `type` | `text` | `attendee` \| `speaker` \| `staff` \| `sponsor` (default `attendee`) |
|
||||||
| `checked_in` | `boolean` | default `false` |
|
| `checked_in` | `boolean` | default `false` |
|
||||||
| `points` | `integer` | `>= 0`, default 0 |
|
| `points` | `integer` | `>= 0`, default 0 |
|
||||||
|
| `qr_token` | `text` | nullable — the lanyard token; **doubles as the Auth password** (generated per event) |
|
||||||
| `external_id` | `text` | nullable — the Pretix order code (set by the sync) |
|
| `external_id` | `text` | nullable — the Pretix order code (set by the sync) |
|
||||||
| `created_at` | `timestamptz` | |
|
| `created_at` | `timestamptz` | |
|
||||||
|
|
||||||
**Constraint:** `unique (event_id, contact_email)` — one registration per contact
|
**Constraint:** `unique (event_id, contact_email)` — one registration per contact
|
||||||
per event. Partial unique index: `registrations_external_id_uniq (external_id) WHERE external_id IS NOT NULL`.
|
per event. Partial unique indexes: `registrations_external_id_uniq (external_id) WHERE external_id IS NOT NULL`
|
||||||
|
and `registrations_qr_token_uniq (qr_token) WHERE qr_token IS NOT NULL` (fast lanyard lookups).
|
||||||
|
|
||||||
## `sponsors` — a sponsor for an event
|
## `sponsors` — a sponsor for an event
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ Source of truth: [`supabase/seed.sql`](../../supabase/seed.sql). The seed runs o
|
|||||||
| Data | Count | Notes |
|
| Data | Count | Notes |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `auth.users` + `auth.identities` | 13 | 12 attendees + 1 admin; **QR token = bcrypt password** |
|
| `auth.users` + `auth.identities` | 13 | 12 attendees + 1 admin; **QR token = bcrypt password** |
|
||||||
| `contacts` | 14 | 13 with QR tokens + 1 external keynote speaker (no token) |
|
| `contacts` | 14 | 13 registrants + 1 external keynote speaker (no token — tokens live on registrations) |
|
||||||
| `events` | 1 | **APPE 2026**, 2026-10-23, São Paulo, Brazil, **active** |
|
| `events` | 1 | **APPE 2026**, 2026-10-23, São Paulo, Brazil, **active** |
|
||||||
| `registrations` | 13 | one per contact (Elena has none); points scoped here |
|
| `registrations` | 13 | one per contact (Elena has none); points + **QR token** scoped here |
|
||||||
| `sponsors` | 3 | Nubank (headline, paid), Acme Corp (gold, paid), Globant (community, unpaid) |
|
| `sponsors` | 3 | Nubank (headline, paid), Acme Corp (gold, paid), Globant (community, unpaid) |
|
||||||
| `slots` | 6 | 23 Oct, 09:00–15:45 (see table below) |
|
| `slots` | 6 | 23 Oct, 09:00–15:45 (see table below) |
|
||||||
| `sessions` | 18 | 3 per slot (Main Stage / Room A / Room B) |
|
| `sessions` | 18 | 3 per slot (Main Stage / Room A / Room B) |
|
||||||
@@ -62,8 +62,8 @@ Login = **QR code** (typed or scanned) + **email**. The QR token is the password
|
|||||||
| Dr. Elena Vasquez | (external speaker) | — | elena.vasquez@keynote.com | — |
|
| Dr. Elena Vasquez | (external speaker) | — | elena.vasquez@keynote.com | — |
|
||||||
|
|
||||||
> **Dr. Elena Vasquez** is an external keynote speaker: she has a `contacts` row
|
> **Dr. Elena Vasquez** is an external keynote speaker: she has a `contacts` row
|
||||||
> (and speaks in `session_speakers`) but **no QR token and no auth user**, so she
|
> (and speaks in `session_speakers`) but **no registration, no QR token, and no
|
||||||
> can't log in — she only appears as a speaker on the agenda.
|
> auth user**, so she can't log in — she only appears as a speaker on the agenda.
|
||||||
|
|
||||||
## Ana's demo state (so the app looks alive on first login)
|
## Ana's demo state (so the app looks alive on first login)
|
||||||
|
|
||||||
|
|||||||
+18
-14
@@ -14,10 +14,10 @@ It runs on **port 3001** (Vite dev) or as the `convivo-admin` Docker container
|
|||||||
| View | Purpose |
|
| View | Purpose |
|
||||||
|---|---|
|
|---|---|
|
||||||
| **Dashboard** | Active event card (name, dates, location, aggregates: avg feedback, #sessions, #speakers, #registrations, #checked-in) + top points + recent activity. |
|
| **Dashboard** | Active event card (name, dates, location, aggregates: avg feedback, #sessions, #speakers, #registrations, #checked-in) + top points + recent activity. |
|
||||||
| **Contacts** | Table of all contacts (email, name, LinkedIn, visibility toggles, `is_admin`, QR token). Edit, **reset the QR token**, toggle `is_admin`, set visibility. |
|
| **Contacts** | Table of all contacts (email, name, LinkedIn, visibility toggles, `is_admin`). Edit, toggle `is_admin`, set visibility, adjust points. (No QR token here — it lives on the registration.) |
|
||||||
| **Registrations** | Per active event: list (contact, type, checked_in). Change type (enforces the sponsor rule), mark checked-in. |
|
| **Registrations** | Per active event: list (contact, type, **QR token**, checked_in, points). Change type (enforces the sponsor rule), mark checked-in, **view + reset the QR token** (per registration). |
|
||||||
| **Sponsors** | List (paid only visible to attendees; admin sees all). Add/edit (type, name, email, phone, paid, amount, contact lookup). |
|
| **Sponsors** | List (paid only visible to attendees; admin sees all). Add/edit (type, name, email, phone, paid, amount, **contact search-and-pick**). |
|
||||||
| **Schedule** | Slots (with type) + sessions (with speakers 1:N, material upload, `average_feedback`, `ai_generated_feedback` + an **Evaluate** stub button). |
|
| **Schedule** | Slots (with type) + sessions (with speakers 1:N via a **multi-select search dropdown**, material upload with a **submitted / not submitted** state, `average_feedback`, `ai_generated_feedback` + an **Evaluate** stub button). |
|
||||||
| **Activity** | Tables of check-ins, connections, and feedback (per active event). |
|
| **Activity** | Tables of check-ins, connections, and feedback (per active event). |
|
||||||
| **Events** | Create event, set active (only one), edit dates/location. |
|
| **Events** | Create event, set active (only one), edit dates/location. |
|
||||||
| **Interfaces** | Trigger **Pretix** and **Sessionize** syncs (per-source or "Sync all"), show the result counts, list recent sync runs, and **export the QR CSV** (name/email/type/qr_token for the active event). |
|
| **Interfaces** | Trigger **Pretix** and **Sessionize** syncs (per-source or "Sync all"), show the result counts, list recent sync runs, and **export the QR CSV** (name/email/type/qr_token for the active event). |
|
||||||
@@ -55,8 +55,8 @@ apps/admin/src/
|
|||||||
│ └─ Login.tsx # QR + email login (admin-only)
|
│ └─ Login.tsx # QR + email login (admin-only)
|
||||||
└─ views/
|
└─ views/
|
||||||
├─ Dashboard.tsx # active event + aggregates + top points + activity
|
├─ Dashboard.tsx # active event + aggregates + top points + activity
|
||||||
├─ Contacts.tsx # table + edit / QR-reset / is_admin / visibility
|
├─ Contacts.tsx # table + edit / is_admin / visibility / points
|
||||||
├─ Registrations.tsx# per-event list + type / checked-in
|
├─ Registrations.tsx# per-event list + type / QR token (+reset) / checked-in
|
||||||
├─ Sponsors.tsx # sponsor CRUD
|
├─ Sponsors.tsx # sponsor CRUD
|
||||||
├─ Schedule.tsx # slots + sessions + speakers + material + AI-evaluate
|
├─ Schedule.tsx # slots + sessions + speakers + material + AI-evaluate
|
||||||
├─ Activity.tsx # check-ins / connections / feedback tables
|
├─ Activity.tsx # check-ins / connections / feedback tables
|
||||||
@@ -76,18 +76,22 @@ key. Everything it can do is allowed by RLS:
|
|||||||
- **Writes** — direct `insert` / `update` / `delete` on `contacts`, `events`,
|
- **Writes** — direct `insert` / `update` / `delete` on `contacts`, `events`,
|
||||||
`registrations`, `sponsors`, `slots`, `sessions`, and `session_speakers`
|
`registrations`, `sponsors`, `slots`, `sessions`, and `session_speakers`
|
||||||
(admin-only policies).
|
(admin-only policies).
|
||||||
- **RPCs** — `reset_qr_token` (regenerate a lanyard token), `adjust_points`
|
- **RPCs** — `reset_registration_qr_token` (regenerate a registration's lanyard
|
||||||
(manual, audited as `admin`), `upsert_contact`, `create_registration`,
|
token), `adjust_points` (manual, audited as `admin`), `upsert_contact`,
|
||||||
`set_registration_type`, `evaluate_session_feedback` (AI stub), and
|
`create_registration`, `set_registration_type`, `evaluate_session_feedback`
|
||||||
`set_session_material` (attach uploaded material). See
|
(AI stub), and `set_session_material` (attach uploaded material). See
|
||||||
[../backend/rpcs.md](../backend/rpcs.md).
|
[../backend/rpcs.md](../backend/rpcs.md).
|
||||||
|
|
||||||
### Resetting a QR token
|
### Resetting a QR token
|
||||||
|
|
||||||
`reset_qr_token(contact_email)` generates a new `CVV-XXX-NNNN` token, writes it to
|
The QR token lives on the **registration** (per event), not the contact. The
|
||||||
`contacts.qr_token`, **re-hashes it as the Auth password** (so the old token stops
|
**Registrations** view shows each registration's token and a **QR** button that
|
||||||
working), and deletes the contact's existing sessions (forcing a re-login). The UI
|
opens a modal with the scannable code + a **Reset token** action. Reset calls
|
||||||
shows the new token as a scannable QR code.
|
`reset_registration_qr_token(contact_email)`, which generates a new
|
||||||
|
`CVV-XXX-NNNN` token, writes it to `registrations.qr_token`, **re-hashes it as the
|
||||||
|
Auth password** (so the old token stops working), and deletes the contact's
|
||||||
|
existing sessions (forcing a re-login). The UI shows the new token as a scannable
|
||||||
|
QR code.
|
||||||
|
|
||||||
### Adjusting points
|
### Adjusting points
|
||||||
|
|
||||||
|
|||||||
@@ -37,8 +37,9 @@ Holds the Supabase **session**, the current **`Contact`**, the current
|
|||||||
`refresh()`, `signOut()`.
|
`refresh()`, `signOut()`.
|
||||||
|
|
||||||
> The contact is the app's source of truth for the current user's `is_admin`
|
> The contact is the app's source of truth for the current user's `is_admin`
|
||||||
> (staff powers) and `qr_token`; the registration holds the user's `type` and
|
> (staff powers); the registration holds the user's `type`, `points`, and
|
||||||
> `points`. After any points-changing action, screens re-fetch.
|
> `qr_token` (the lanyard token, per event). After any points-changing action,
|
||||||
|
> screens re-fetch.
|
||||||
|
|
||||||
## ToastContext (`context/ToastContext.tsx`)
|
## ToastContext (`context/ToastContext.tsx`)
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,10 @@ The landing screen. Shows:
|
|||||||
- **Now card** — the session the user picked for the current slot, with a
|
- **Now card** — the session the user picked for the current slot, with a
|
||||||
"✓ Checked in" or "Show your QR to staff to check in" pill.
|
"✓ Checked in" or "Show your QR to staff to check in" pill.
|
||||||
- **Next card** — the pick for the next slot.
|
- **Next card** — the pick for the next slot.
|
||||||
- **My picks today** — the user's pick per slot (tap to change → opens Agenda).
|
- **My picks today** — shows only **2 rows** (the current slot's pick + the next
|
||||||
|
slot's pick). "tap to change" is a **hyperlink** to the Agenda.
|
||||||
|
- **Footer type badge** — the registration-type pill is shown **only for non-
|
||||||
|
attendee** types (Attendee is the default and is not shown at the bottom).
|
||||||
- **Quick actions** — Scan & connect / Check-in, Agenda, Connections, Leaderboard.
|
- **Quick actions** — Scan & connect / Check-in, Agenda, Connections, Leaderboard.
|
||||||
- **No active event** — a graceful empty state ("No active event right now.
|
- **No active event** — a graceful empty state ("No active event right now.
|
||||||
Check back soon!").
|
Check back soon!").
|
||||||
@@ -98,15 +101,24 @@ Data: `useEvent()` (for the session list) + the RPCs above.
|
|||||||
Two tabs: **My connections** and **Requests** (with a count badge).
|
Two tabs: **My connections** and **Requests** (with a count badge).
|
||||||
|
|
||||||
- **My connections** — accepted connections (the other person's name +
|
- **My connections** — accepted connections (the other person's name +
|
||||||
registration type).
|
registration type). **Clicking a row** opens a bottom **sheet** with that
|
||||||
|
person's **public info + their points** (avatar, name, type pill, `⚡ N pts`,
|
||||||
|
LinkedIn if visible, email if `show_email`). **Other people's QR codes are
|
||||||
|
never shown.**
|
||||||
- **Requests** — incoming (`to_email = me`, pending) with **Accept / Decline**
|
- **Requests** — incoming (`to_email = me`, pending) with **Accept / Decline**
|
||||||
buttons (`acceptConnection` / `rejectConnection`), and outgoing (`from_email =
|
buttons (`acceptConnection` / `rejectConnection`), and outgoing (`from_email =
|
||||||
me`, pending) shown as "Sent".
|
me`, pending) shown as "Sent". The person block is also clickable (same detail
|
||||||
|
sheet).
|
||||||
- Accepting awards +5 to both (see
|
- Accepting awards +5 to both (see
|
||||||
[../backend/rpcs.md#accept_connectionp_connection_id--connections](../backend/rpcs.md#accept_connectionp_connection_id--connections)).
|
[../backend/rpcs.md#accept_connectionp_connection_id--connections](../backend/rpcs.md#accept_connectionp_connection_id--connections)).
|
||||||
- **Live-ish:** polls every 5s while the tab is visible (`usePolling`).
|
- **Red dot** — any interaction with the connection logic (accept / decline / send)
|
||||||
|
dispatches a `connections-changed` window event; the Shell listens and
|
||||||
|
**recalculates the Connect red dot immediately** (it stays while any incoming
|
||||||
|
request is pending and disappears once none are). It also polls every 5s as a
|
||||||
|
fallback (`usePolling`).
|
||||||
|
|
||||||
Data: `getMyConnections()` + `getPublicContacts()` (to resolve names + types).
|
Data: `getMyConnections()` + `getPublicContacts()` (names + types) +
|
||||||
|
`getLeaderboard()` (points for the detail sheet).
|
||||||
|
|
||||||
## Feedback
|
## Feedback
|
||||||
|
|
||||||
@@ -144,8 +156,9 @@ event). The `leaderboard` table is kept in sync transactionally by the RPCs —
|
|||||||
|
|
||||||
- **Header** — avatar, name, email, registration-type pill, a **staff** pill when
|
- **Header** — avatar, name, email, registration-type pill, a **staff** pill when
|
||||||
`contact.is_admin`, and a points pill.
|
`contact.is_admin`, and a points pill.
|
||||||
- **My QR code** — renders `contact.qr_token` as a scannable QR (`QrImage`).
|
- **My QR code** — renders `registration.qr_token` (the token lives on the
|
||||||
"Show this to staff for check-in and to peers to connect."
|
registration, per event) as a scannable QR (`QrImage`). "Show this to staff for
|
||||||
|
check-in and to peers to connect."
|
||||||
- **Points breakdown** — sums `points_log` by category
|
- **Points breakdown** — sums `points_log` by category
|
||||||
(Session check-ins / Connections / Feedback / Other) + Total.
|
(Session check-ins / Connections / Feedback / Other) + Total.
|
||||||
- **Log out** — `signOut()`.
|
- **Log out** — `signOut()`.
|
||||||
|
|||||||
+59
-2
@@ -4,8 +4,10 @@ What's done, what's next, and the open decisions. The full roadmap lives in the
|
|||||||
root [`roadmap.md`](../roadmap.md); this file is the working detail for the
|
root [`roadmap.md`](../roadmap.md); this file is the working detail for the
|
||||||
current phase.
|
current phase.
|
||||||
|
|
||||||
> **Current state:** Phases 0–8 are complete and verified. The **Redesign**
|
> **Current state:** Phases 0–8 are complete and verified, plus a round of
|
||||||
> (Phases 3–6) and the **Pretix + Sessionize interfaces** (Phases 7–8) are done.
|
> **Fixes & Refinements** (QR token moved to the registration, role-pill
|
||||||
|
> capitalization, connection detail sheet + red-dot recalc, admin schedule
|
||||||
|
> speaker multi-select + upload/speaker bug fixes, sponsor contact search).
|
||||||
> Remaining work is cross-cutting (real event clock, deployment, testing) and
|
> Remaining work is cross-cutting (real event clock, deployment, testing) and
|
||||||
> the open questions in [backend/interfaces.md](./backend/interfaces.md).
|
> the open questions in [backend/interfaces.md](./backend/interfaces.md).
|
||||||
|
|
||||||
@@ -179,6 +181,61 @@ Sync the **real agenda** (slots, sessions, speakers, rooms) from
|
|||||||
- **Auth** — the Edge Function accepts an admin JWT (verified via `is_admin()`)
|
- **Auth** — the Edge Function accepts an admin JWT (verified via `is_admin()`)
|
||||||
or a `CRON_SECRET` header for scheduled runs.
|
or a `CRON_SECRET` header for scheduled runs.
|
||||||
|
|
||||||
|
## Fixes & Refinements — ✅ complete
|
||||||
|
|
||||||
|
A cross-cutting polish round (migration `20260826000000_registration_qr_token.sql`
|
||||||
|
+ app changes), all browser-verified.
|
||||||
|
|
||||||
|
**Datamodel — QR token moves from `contacts` to `registrations`.**
|
||||||
|
- The token is a property of the **registration** (generated per event by
|
||||||
|
Pretix), not the contact. `contacts.qr_token` is dropped; `registrations.qr_token`
|
||||||
|
is added (partial unique index `registrations_qr_token_uniq`).
|
||||||
|
- `lanyard_lookup`, `create_connection_request`, and `checkin_attendee` now
|
||||||
|
resolve tokens via `registrations` + the active event.
|
||||||
|
- `reset_qr_token(contact)` is replaced by `reset_registration_qr_token(email)`
|
||||||
|
(admin-only; regenerates the active-event registration's token + re-hashes the
|
||||||
|
Auth password + clears sessions). `upsert_contact` no longer takes a token;
|
||||||
|
`create_registration` generates one and syncs it as the password.
|
||||||
|
- The Pretix sync writes the token to the **registration** (keeps the existing
|
||||||
|
token on re-sync so a lanyard is never invalidated).
|
||||||
|
|
||||||
|
**Registration types.**
|
||||||
|
- Type pills have **distinct colors**; **red is reserved for Staff** (both apps).
|
||||||
|
- Roles are shown **capitalized** in both apps (Attendee / Speaker / Sponsor /
|
||||||
|
Staff). "Attendee" is **not shown at the bottom** of the Home screen (it's the
|
||||||
|
default); it *is* shown (capitalized) on Profile, Login, Scan, and Connections.
|
||||||
|
- The **reset-token button is removed from the Contacts view** (meaningless now
|
||||||
|
that the token lives on the registration) and moved to the **Registrations**
|
||||||
|
view (per-registration QR + reset).
|
||||||
|
|
||||||
|
**Sessions (APPE Admin).**
|
||||||
|
- Slot types are shown **capitalized** (Session, Keynote, Lunch Break, …).
|
||||||
|
- The session list shows whether material was **submitted / not submitted**.
|
||||||
|
- Speaker selection is a **multi-select search dropdown** (search + chips),
|
||||||
|
replacing the checkbox list.
|
||||||
|
- **Fixed:** editing a session no longer fails with "a session must have a
|
||||||
|
speaker" — `setSessionSpeakers` now **diffs** (insert the new set, then delete
|
||||||
|
only the removed ones) instead of delete-all-then-insert, so the
|
||||||
|
`session_needs_speaker` trigger (which counts the row being deleted) never
|
||||||
|
fires. This also **fixes the file-upload bug** (the speaker save no longer
|
||||||
|
aborts before the material upload runs).
|
||||||
|
|
||||||
|
**APPE Admin — Sponsors.**
|
||||||
|
- The sponsor **contact lookup is a search field** (filter + click-to-pick), not
|
||||||
|
a dropdown of all contacts.
|
||||||
|
|
||||||
|
**Convivo App.**
|
||||||
|
- **Other people's QR codes are hidden** — the connection detail sheet shows
|
||||||
|
public info + points only (no QR).
|
||||||
|
- **Connect red dot** — any interaction with the connection logic (accept /
|
||||||
|
decline / send) dispatches a `connections-changed` event; the Shell recalculates
|
||||||
|
the dot **immediately** (stays while any incoming request is pending, clears
|
||||||
|
when none are). 5s polling remains as a fallback.
|
||||||
|
- **Connect menu** — clicking any connection (connected or requested) opens a
|
||||||
|
sheet with that person's **public info + their points**.
|
||||||
|
- **"My picks today"** — shows only **2 rows** (current + next slot's pick);
|
||||||
|
"tap to change" is a **hyperlink** to the Agenda.
|
||||||
|
|
||||||
## Cross-cutting / later
|
## Cross-cutting / later
|
||||||
|
|
||||||
- **Real event clock** — replace the simulated `DEFAULT_NOW`
|
- **Real event clock** — replace the simulated `DEFAULT_NOW`
|
||||||
|
|||||||
@@ -4,19 +4,22 @@
|
|||||||
"order_code": "PX-NEW-001",
|
"order_code": "PX-NEW-001",
|
||||||
"attendee_name": "New Attendee One",
|
"attendee_name": "New Attendee One",
|
||||||
"attendee_email": "[email protected]",
|
"attendee_email": "[email protected]",
|
||||||
"ticket_type": "Regular"
|
"ticket_type": "Regular",
|
||||||
|
"qr_token": "CVV-PX1-1001"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"order_code": "PX-NEW-002",
|
"order_code": "PX-NEW-002",
|
||||||
"attendee_name": "New Speaker Two",
|
"attendee_name": "New Speaker Two",
|
||||||
"attendee_email": "[email protected]",
|
"attendee_email": "[email protected]",
|
||||||
"ticket_type": "Speaker"
|
"ticket_type": "Speaker",
|
||||||
|
"qr_token": "CVV-PX2-1002"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"order_code": "PX-ANA-003",
|
"order_code": "PX-ANA-003",
|
||||||
"attendee_name": "Ana Silva",
|
"attendee_name": "Ana Silva",
|
||||||
"attendee_email": "[email protected]",
|
"attendee_email": "[email protected]",
|
||||||
"ticket_type": "Regular"
|
"ticket_type": "Regular",
|
||||||
|
"qr_token": "CVV-ANA-4821"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -86,6 +86,9 @@ async function fetchPretixAttendees(): Promise<Record<string, unknown>[]> {
|
|||||||
full_name: a.attendee_name,
|
full_name: a.attendee_name,
|
||||||
ticket_type: a.ticket_type,
|
ticket_type: a.ticket_type,
|
||||||
external_id: a.order_code,
|
external_id: a.order_code,
|
||||||
|
// Pretix generates a QR token per ticket; it becomes the registration's
|
||||||
|
// token (and the login password).
|
||||||
|
qr_token: a.qr_token ?? null,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,6 +97,7 @@ interface PretixOrder {
|
|||||||
attendee_name: string;
|
attendee_name: string;
|
||||||
attendee_email: string;
|
attendee_email: string;
|
||||||
ticket_type: string;
|
ticket_type: string;
|
||||||
|
qr_token?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Sessionize: fetch + normalize -----------------------------------------
|
// ---- Sessionize: fetch + normalize -----------------------------------------
|
||||||
|
|||||||
@@ -0,0 +1,535 @@
|
|||||||
|
-- =============================================================================
|
||||||
|
-- Convivo — Fixes & Refinements: QR token is a property of the REGISTRATION
|
||||||
|
--
|
||||||
|
-- The QR token is generated by Pretix and changes per event, so it belongs on
|
||||||
|
-- the registration (per event), not the contact (per person). This migration:
|
||||||
|
-- * adds `registrations.qr_token` (unique) and drops `contacts.qr_token`.
|
||||||
|
-- * re-points every token lookup at the active event's registration:
|
||||||
|
-- lanyard_lookup, create_connection_request, checkin_attendee.
|
||||||
|
-- * replaces `reset_qr_token(contact)` with `reset_registration_qr_token(email)`
|
||||||
|
-- (regenerates the active event's registration token + syncs the auth
|
||||||
|
-- password, since the token doubles as the login password).
|
||||||
|
-- * `upsert_contact` no longer takes/sets a token (contacts have none).
|
||||||
|
-- * the Pretix sync writes the token to the registration (Pretix generates it
|
||||||
|
-- per ticket); the Sessionize sync no longer writes contact tokens.
|
||||||
|
--
|
||||||
|
-- The auth password is still the QR token (QR + email login, no email sent).
|
||||||
|
-- =============================================================================
|
||||||
|
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
-- 1. MOVE THE COLUMN
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
alter table public.registrations add column if not exists qr_token text;
|
||||||
|
create unique index if not exists registrations_qr_token_uniq
|
||||||
|
on public.registrations (qr_token) where qr_token is not null;
|
||||||
|
|
||||||
|
-- Copy each contact's token onto their active-event registration (idempotent:
|
||||||
|
-- only fills rows that don't already have a token).
|
||||||
|
update public.registrations r
|
||||||
|
set qr_token = c.qr_token
|
||||||
|
from public.contacts c
|
||||||
|
where r.contact_email = c.email
|
||||||
|
and r.event_id = (select id from public.events where is_active limit 1)
|
||||||
|
and r.qr_token is null
|
||||||
|
and c.qr_token is not null;
|
||||||
|
|
||||||
|
-- Drop the old column (cascades the old index).
|
||||||
|
alter table public.contacts drop column if exists qr_token;
|
||||||
|
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
-- 2. TOKEN LOOKUP: resolve a QR token to the contact + registration type for
|
||||||
|
-- the ACTIVE event (the token now lives on the registration).
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
create or replace function public.lanyard_lookup(p_qr_token text)
|
||||||
|
returns table (email text, full_name text, linkedin_url text,
|
||||||
|
show_email boolean, registration_type text)
|
||||||
|
language sql stable security definer set search_path = public as $$
|
||||||
|
select c.email,
|
||||||
|
c.full_name,
|
||||||
|
case when c.show_linkedin then c.linkedin_url else null end as linkedin_url,
|
||||||
|
c.show_email,
|
||||||
|
r.type as registration_type
|
||||||
|
from public.registrations r
|
||||||
|
join public.contacts c on c.email = r.contact_email
|
||||||
|
where r.qr_token = p_qr_token
|
||||||
|
and r.event_id = (select id from public.events where is_active limit 1);
|
||||||
|
$$;
|
||||||
|
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
-- 3. CONNECTION REQUEST: resolve the scanned token to a contact (active event).
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
create or replace function public.create_connection_request(p_target_qr text)
|
||||||
|
returns public.connections
|
||||||
|
language plpgsql security definer set search_path = public as $$
|
||||||
|
declare
|
||||||
|
v_email text := public.current_email();
|
||||||
|
v_target text;
|
||||||
|
v_event_id uuid;
|
||||||
|
v_conn public.connections;
|
||||||
|
begin
|
||||||
|
if v_email is null then raise exception 'not authenticated'; end if;
|
||||||
|
select r.contact_email into v_target
|
||||||
|
from public.registrations r
|
||||||
|
where r.qr_token = p_target_qr
|
||||||
|
and r.event_id = (select id from public.events where is_active limit 1);
|
||||||
|
if v_target is null then raise exception 'no attendee found for that QR code'; end if;
|
||||||
|
if v_target = v_email then raise exception 'you cannot connect with yourself'; end if;
|
||||||
|
select id into v_event_id from public.events where is_active limit 1;
|
||||||
|
if v_event_id is null then raise exception 'no active event'; end if;
|
||||||
|
select * into v_conn from public.connections
|
||||||
|
where event_id = v_event_id
|
||||||
|
and ((from_email = v_email and to_email = v_target)
|
||||||
|
or (from_email = v_target and to_email = v_email))
|
||||||
|
limit 1;
|
||||||
|
if found then
|
||||||
|
return v_conn;
|
||||||
|
end if;
|
||||||
|
insert into public.connections (event_id, from_email, to_email, status)
|
||||||
|
values (v_event_id, v_email, v_target, 'pending')
|
||||||
|
returning * into v_conn;
|
||||||
|
return v_conn;
|
||||||
|
end;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
-- 4. CHECK-IN: resolve the scanned token to a contact (active event).
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
create or replace function public.checkin_attendee(p_session_id uuid, p_attendee_qr text)
|
||||||
|
returns table (checkin_id uuid, attendee_email text, attendee_name text,
|
||||||
|
points integer, already boolean)
|
||||||
|
language plpgsql security definer set search_path = public as $$
|
||||||
|
declare
|
||||||
|
v_staff text := public.current_email();
|
||||||
|
v_attendee text;
|
||||||
|
v_name text;
|
||||||
|
v_event_id uuid;
|
||||||
|
v_new_id uuid;
|
||||||
|
v_points integer;
|
||||||
|
v_already boolean := false;
|
||||||
|
begin
|
||||||
|
if v_staff is null then raise exception 'not authenticated'; end if;
|
||||||
|
if not public.is_staff_or_admin() then raise exception 'staff or admin only'; end if;
|
||||||
|
select r.contact_email, c.full_name into v_attendee, v_name
|
||||||
|
from public.registrations r
|
||||||
|
join public.contacts c on c.email = r.contact_email
|
||||||
|
where r.qr_token = p_attendee_qr
|
||||||
|
and r.event_id = (select id from public.events where is_active limit 1);
|
||||||
|
if v_attendee is null then raise exception 'no attendee found for that QR code'; end if;
|
||||||
|
select event_id into v_event_id from public.sessions where id = p_session_id;
|
||||||
|
if v_event_id is null then raise exception 'session not found'; end if;
|
||||||
|
insert into public.checkins (event_id, contact_email, session_id, staff_email)
|
||||||
|
values (v_event_id, v_attendee, p_session_id, v_staff)
|
||||||
|
on conflict (event_id, contact_email, session_id) do nothing
|
||||||
|
returning id into v_new_id;
|
||||||
|
if v_new_id is null then
|
||||||
|
v_already := true;
|
||||||
|
select id into v_new_id from public.checkins
|
||||||
|
where event_id = v_event_id and contact_email = v_attendee and session_id = p_session_id;
|
||||||
|
else
|
||||||
|
perform public._award_points(v_event_id, v_attendee, 10, 'checkin');
|
||||||
|
update public.registrations set checked_in = true
|
||||||
|
where event_id = v_event_id and contact_email = v_attendee;
|
||||||
|
end if;
|
||||||
|
select r.points into v_points from public.registrations r
|
||||||
|
where r.event_id = v_event_id and r.contact_email = v_attendee;
|
||||||
|
return query select v_new_id, v_attendee, v_name, coalesce(v_points, 0), v_already;
|
||||||
|
end;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
-- 5. RESET TOKEN: now per registration (active event). Regenerates the token
|
||||||
|
-- and re-hashes it as the auth password (the old token stops working).
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
create or replace function public.reset_registration_qr_token(p_contact_email text)
|
||||||
|
returns table (email text, qr_token text)
|
||||||
|
language plpgsql security definer set search_path = public as $$
|
||||||
|
declare
|
||||||
|
v_uid uuid;
|
||||||
|
v_token text;
|
||||||
|
v_salt text;
|
||||||
|
v_event_id uuid;
|
||||||
|
begin
|
||||||
|
if auth.uid() is null then raise exception 'not authenticated'; end if;
|
||||||
|
if not public.is_admin() then raise exception 'admin only'; end if;
|
||||||
|
select id into v_event_id from public.events where is_active limit 1;
|
||||||
|
if v_event_id is null then raise exception 'no active event'; end if;
|
||||||
|
if not exists (select 1 from public.registrations
|
||||||
|
where event_id = v_event_id and contact_email = p_contact_email) then
|
||||||
|
raise exception 'registration not found';
|
||||||
|
end if;
|
||||||
|
v_token := 'CVV-' || upper(substr(md5(random()::text), 1, 3)) || '-'
|
||||||
|
|| lpad((floor(random() * 10000))::int::text, 4, '0');
|
||||||
|
update public.registrations set qr_token = v_token
|
||||||
|
where event_id = v_event_id and contact_email = p_contact_email;
|
||||||
|
-- Qualify auth.users.email: the function's output column is also named
|
||||||
|
-- `email` (returns table (email, qr_token)), so a bare `email` is ambiguous.
|
||||||
|
select id into v_uid from auth.users where auth.users.email = p_contact_email;
|
||||||
|
if v_uid is not null then
|
||||||
|
v_salt := extensions.gen_salt('bf');
|
||||||
|
update auth.users
|
||||||
|
set encrypted_password = extensions.crypt(v_token, v_salt), updated_at = now()
|
||||||
|
where id = v_uid;
|
||||||
|
delete from auth.sessions where user_id = v_uid;
|
||||||
|
end if;
|
||||||
|
return query select p_contact_email, v_token;
|
||||||
|
end;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
-- Drop the old contact-scoped reset function.
|
||||||
|
drop function if exists public.reset_qr_token(text);
|
||||||
|
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
-- 6. UPSERT CONTACT: contacts no longer carry a token.
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
create or replace function public.upsert_contact(
|
||||||
|
p_email text, p_full_name text, p_linkedin_url text,
|
||||||
|
p_is_admin boolean
|
||||||
|
)
|
||||||
|
returns public.contacts
|
||||||
|
language plpgsql security definer set search_path = public as $$
|
||||||
|
declare
|
||||||
|
v_uid uuid;
|
||||||
|
v_contact public.contacts;
|
||||||
|
begin
|
||||||
|
if auth.uid() is null then raise exception 'not authenticated'; end if;
|
||||||
|
if not public.is_admin() then raise exception 'admin only'; end if;
|
||||||
|
if p_email is null or btrim(p_email) = '' then raise exception 'email is required'; end if;
|
||||||
|
if p_full_name is null or btrim(p_full_name) = '' then raise exception 'full_name is required'; end if;
|
||||||
|
|
||||||
|
insert into public.contacts (email, full_name, linkedin_url, is_admin)
|
||||||
|
values (p_email, p_full_name, p_linkedin_url, coalesce(p_is_admin, false))
|
||||||
|
on conflict (email) do update
|
||||||
|
set full_name = excluded.full_name,
|
||||||
|
linkedin_url = excluded.linkedin_url,
|
||||||
|
is_admin = excluded.is_admin
|
||||||
|
returning * into v_contact;
|
||||||
|
|
||||||
|
-- Ensure an auth user exists so the contact can log in once a registration
|
||||||
|
-- token is issued (the token doubles as the password). If no auth user yet,
|
||||||
|
-- create one with a placeholder password; the registration token (set via
|
||||||
|
-- create_registration / the sync) is what actually unlocks login.
|
||||||
|
select id into v_uid from auth.users where email = p_email;
|
||||||
|
if v_uid is null then
|
||||||
|
insert into auth.users (instance_id, id, aud, role, email, encrypted_password,
|
||||||
|
email_confirmed_at, confirmation_token, recovery_token, email_change_token_new,
|
||||||
|
email_change, raw_app_meta_data, raw_user_meta_data,
|
||||||
|
created_at, updated_at, confirmation_sent_at, last_sign_in_at)
|
||||||
|
values ('00000000-0000-0000-0000-000000000000', gen_random_uuid(), 'authenticated',
|
||||||
|
'authenticated', p_email,
|
||||||
|
extensions.crypt('no-token-yet', extensions.gen_salt('bf')),
|
||||||
|
now(), '', '', '', '', '{"provider":"email","providers":["email"]}',
|
||||||
|
jsonb_build_object('full_name', p_full_name), now(), now(), now(), now())
|
||||||
|
returning id into v_uid;
|
||||||
|
insert into auth.identities (id, provider_id, identity_data, provider, user_id,
|
||||||
|
created_at, updated_at, last_sign_in_at)
|
||||||
|
values (v_uid, v_uid::text,
|
||||||
|
jsonb_build_object('sub', v_uid::text, 'email', p_email),
|
||||||
|
'email', v_uid, now(), now(), now());
|
||||||
|
end if;
|
||||||
|
|
||||||
|
return v_contact;
|
||||||
|
end;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
-- 7. CREATE REGISTRATION: generate a token (Pretix-style) + sync the auth
|
||||||
|
-- password, so a newly registered contact can log in immediately.
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
create or replace function public.create_registration(p_contact_email text, p_type text)
|
||||||
|
returns public.registrations
|
||||||
|
language plpgsql security definer set search_path = public as $$
|
||||||
|
declare
|
||||||
|
v_email text := public.current_email();
|
||||||
|
v_event_id uuid;
|
||||||
|
v_reg public.registrations;
|
||||||
|
v_token text;
|
||||||
|
v_uid uuid;
|
||||||
|
begin
|
||||||
|
if v_email is null then raise exception 'not authenticated'; end if;
|
||||||
|
if not public.is_admin() then raise exception 'admin only'; end if;
|
||||||
|
if not exists (select 1 from public.contacts where email = p_contact_email) then
|
||||||
|
raise exception 'contact not found';
|
||||||
|
end if;
|
||||||
|
if p_type is null or p_type not in ('attendee', 'speaker', 'staff', 'sponsor') then
|
||||||
|
raise exception 'invalid registration type';
|
||||||
|
end if;
|
||||||
|
select id into v_event_id from public.events where is_active limit 1;
|
||||||
|
if v_event_id is null then raise exception 'no active event'; end if;
|
||||||
|
if p_type = 'sponsor' and not exists (
|
||||||
|
select 1 from public.sponsors where event_id = v_event_id and contact_email = p_contact_email
|
||||||
|
) then
|
||||||
|
raise exception 'a sponsor registration requires a sponsor lookup';
|
||||||
|
end if;
|
||||||
|
|
||||||
|
-- Generate a token for the new registration (Pretix generates one per ticket).
|
||||||
|
v_token := 'CVV-' || upper(substr(md5(random()::text), 1, 3)) || '-'
|
||||||
|
|| lpad((floor(random() * 10000))::int::text, 4, '0');
|
||||||
|
|
||||||
|
insert into public.registrations (event_id, contact_email, type, qr_token)
|
||||||
|
values (v_event_id, p_contact_email, p_type, v_token)
|
||||||
|
on conflict (event_id, contact_email) do update
|
||||||
|
set type = excluded.type
|
||||||
|
returning * into v_reg;
|
||||||
|
|
||||||
|
-- Sync the auth password to the new token (so login works right away).
|
||||||
|
select id into v_uid from auth.users where email = p_contact_email;
|
||||||
|
if v_uid is not null then
|
||||||
|
update auth.users
|
||||||
|
set encrypted_password = extensions.crypt(v_reg.qr_token, extensions.gen_salt('bf')),
|
||||||
|
updated_at = now()
|
||||||
|
where id = v_uid;
|
||||||
|
delete from auth.sessions where user_id = v_uid;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
return v_reg;
|
||||||
|
end;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
-- 8. PRETIX SYNC: write the token to the REGISTRATION (Pretix generates it per
|
||||||
|
-- ticket). The contact no longer stores a token.
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
create or replace function public.sync_pretix_attendees(p_attendees jsonb)
|
||||||
|
returns jsonb
|
||||||
|
language plpgsql security definer set search_path = public as $$
|
||||||
|
declare
|
||||||
|
v_event_id uuid;
|
||||||
|
v_run_id uuid;
|
||||||
|
v_started timestamptz := now();
|
||||||
|
v_item jsonb;
|
||||||
|
v_email text;
|
||||||
|
v_name text;
|
||||||
|
v_type text;
|
||||||
|
v_token text;
|
||||||
|
v_linkedin text;
|
||||||
|
v_ext text;
|
||||||
|
v_contact public.contacts;
|
||||||
|
v_reg public.registrations;
|
||||||
|
v_created integer := 0;
|
||||||
|
v_updated integer := 0;
|
||||||
|
v_skipped integer := 0;
|
||||||
|
v_errors jsonb := '[]'::jsonb;
|
||||||
|
v_err text;
|
||||||
|
begin
|
||||||
|
if coalesce(auth.jwt() ->> 'role', '') <> 'service_role' then
|
||||||
|
raise exception 'service_role only';
|
||||||
|
end if;
|
||||||
|
select id into v_event_id from public.events where is_active limit 1;
|
||||||
|
if v_event_id is null then
|
||||||
|
raise exception 'no active event';
|
||||||
|
end if;
|
||||||
|
insert into public.sync_runs (source, started_at, triggered_by)
|
||||||
|
values ('pretix', v_started, 'service_role')
|
||||||
|
returning id into v_run_id;
|
||||||
|
|
||||||
|
for v_item in select * from jsonb_array_elements(coalesce(p_attendees, '[]'::jsonb))
|
||||||
|
loop
|
||||||
|
begin
|
||||||
|
v_email := v_item ->> 'email';
|
||||||
|
v_name := v_item ->> 'full_name';
|
||||||
|
v_type := public._map_ticket_type(v_item ->> 'ticket_type');
|
||||||
|
v_token := v_item ->> 'qr_token';
|
||||||
|
v_linkedin := v_item ->> 'linkedin_url';
|
||||||
|
v_ext := v_item ->> 'external_id';
|
||||||
|
|
||||||
|
if v_email is null or btrim(v_email) = '' or v_name is null or btrim(v_name) = '' then
|
||||||
|
v_skipped := v_skipped + 1;
|
||||||
|
continue;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
-- Upsert the contact (by email). No token on the contact anymore.
|
||||||
|
insert into public.contacts (email, full_name, linkedin_url, is_admin, external_id)
|
||||||
|
values (v_email, v_name, v_linkedin, false, v_ext)
|
||||||
|
on conflict (email) do update
|
||||||
|
set full_name = excluded.full_name,
|
||||||
|
linkedin_url = coalesce(excluded.linkedin_url, public.contacts.linkedin_url),
|
||||||
|
external_id = coalesce(excluded.external_id, public.contacts.external_id)
|
||||||
|
returning * into v_contact;
|
||||||
|
|
||||||
|
-- A `sponsor` registration requires a sponsor lookup (business rule).
|
||||||
|
if v_type = 'sponsor' and not exists (
|
||||||
|
select 1 from public.sponsors
|
||||||
|
where event_id = v_event_id and contact_email = v_email
|
||||||
|
) then
|
||||||
|
insert into public.sponsors (event_id, type, name, contact_email, paid)
|
||||||
|
values (v_event_id, 'community', v_name, v_email, false);
|
||||||
|
end if;
|
||||||
|
|
||||||
|
-- Upsert the registration for the active event (by contact). The QR token
|
||||||
|
-- lives here (Pretix generates it per ticket). Keep the existing token
|
||||||
|
-- unless a new one is supplied (so a re-sync never invalidates a lanyard).
|
||||||
|
select qr_token into v_token
|
||||||
|
from public.registrations
|
||||||
|
where event_id = v_event_id and contact_email = v_email;
|
||||||
|
v_token := coalesce(v_token, v_item ->> 'qr_token',
|
||||||
|
'CVV-' || upper(substr(md5(random()::text), 1, 3)) || '-'
|
||||||
|
|| lpad((floor(random() * 10000))::int::text, 4, '0'));
|
||||||
|
|
||||||
|
insert into public.registrations (event_id, contact_email, type, external_id, qr_token)
|
||||||
|
values (v_event_id, v_email, v_type, v_ext, v_token)
|
||||||
|
on conflict (event_id, contact_email) do update
|
||||||
|
set type = excluded.type,
|
||||||
|
external_id = coalesce(excluded.external_id, public.registrations.external_id),
|
||||||
|
qr_token = coalesce(excluded.qr_token, public.registrations.qr_token)
|
||||||
|
returning * into v_reg;
|
||||||
|
|
||||||
|
-- Ensure the auth user exists (QR token = password).
|
||||||
|
perform public._ensure_auth_user(v_email, v_name, v_reg.qr_token);
|
||||||
|
|
||||||
|
v_updated := v_updated + 1;
|
||||||
|
exception when others then
|
||||||
|
v_err := coalesce(v_email, '<no email>') || ': ' || sqlerrm;
|
||||||
|
v_errors := v_errors || to_jsonb(v_err);
|
||||||
|
v_skipped := v_skipped + 1;
|
||||||
|
end;
|
||||||
|
end loop;
|
||||||
|
|
||||||
|
update public.sync_runs
|
||||||
|
set finished_at = now(), created = v_created, updated = v_updated,
|
||||||
|
skipped = v_skipped, error = case when jsonb_array_length(v_errors) > 0
|
||||||
|
then v_errors::text else null end
|
||||||
|
where id = v_run_id;
|
||||||
|
|
||||||
|
return jsonb_build_object('created', v_created, 'updated', v_updated,
|
||||||
|
'skipped', v_skipped, 'errors', v_errors);
|
||||||
|
end;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
-- 9. SESSIONIZE SYNC: speakers are upserted as contacts (no token) + links.
|
||||||
|
-- (Speakers get a login token only if they also hold a ticket/registration.)
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
create or replace function public.sync_sessionize_sessions(p_sessions jsonb)
|
||||||
|
returns jsonb
|
||||||
|
language plpgsql security definer set search_path = public as $$
|
||||||
|
declare
|
||||||
|
v_event_id uuid;
|
||||||
|
v_run_id uuid;
|
||||||
|
v_started timestamptz := now();
|
||||||
|
v_item jsonb;
|
||||||
|
v_ext text;
|
||||||
|
v_title text;
|
||||||
|
v_desc text;
|
||||||
|
v_room text;
|
||||||
|
v_cap integer;
|
||||||
|
v_date date;
|
||||||
|
v_start time;
|
||||||
|
v_end time;
|
||||||
|
v_slot public.slots;
|
||||||
|
v_session public.sessions;
|
||||||
|
v_spk jsonb;
|
||||||
|
v_spk_email text;
|
||||||
|
v_spk_name text;
|
||||||
|
v_slots_created integer := 0;
|
||||||
|
v_sessions_created integer := 0;
|
||||||
|
v_sessions_updated integer := 0;
|
||||||
|
v_speakers_linked integer := 0;
|
||||||
|
v_errors jsonb := '[]'::jsonb;
|
||||||
|
v_err text;
|
||||||
|
v_existing boolean;
|
||||||
|
begin
|
||||||
|
if coalesce(auth.jwt() ->> 'role', '') <> 'service_role' then
|
||||||
|
raise exception 'service_role only';
|
||||||
|
end if;
|
||||||
|
select id into v_event_id from public.events where is_active limit 1;
|
||||||
|
if v_event_id is null then
|
||||||
|
raise exception 'no active event';
|
||||||
|
end if;
|
||||||
|
insert into public.sync_runs (source, started_at, triggered_by)
|
||||||
|
values ('sessionize', v_started, 'service_role')
|
||||||
|
returning id into v_run_id;
|
||||||
|
|
||||||
|
for v_item in select * from jsonb_array_elements(coalesce(p_sessions, '[]'::jsonb))
|
||||||
|
loop
|
||||||
|
begin
|
||||||
|
v_ext := v_item ->> 'external_id';
|
||||||
|
v_title := v_item ->> 'title';
|
||||||
|
v_desc := v_item ->> 'description';
|
||||||
|
v_room := v_item ->> 'room';
|
||||||
|
v_cap := (v_item ->> 'capacity')::int;
|
||||||
|
v_date := (v_item ->> 'date')::date;
|
||||||
|
v_start := (v_item ->> 'start_time')::time;
|
||||||
|
v_end := (v_item ->> 'end_time')::time;
|
||||||
|
|
||||||
|
if v_ext is null or v_title is null or v_date is null or v_start is null or v_end is null then
|
||||||
|
v_errors := v_errors || to_jsonb(coalesce(v_title, '<no title>') || ': missing required field');
|
||||||
|
continue;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
select * into v_slot from public.slots
|
||||||
|
where event_id = v_event_id and slot_date = v_date
|
||||||
|
and start_time = v_start and end_time = v_end
|
||||||
|
limit 1;
|
||||||
|
if not found then
|
||||||
|
insert into public.slots (id, event_id, type, name, slot_date, start_time, end_time)
|
||||||
|
values (nextval('public.slots_id_seq'), v_event_id, 'session',
|
||||||
|
'Slot ' || to_char(v_start, 'HH24:MI') || '–' || to_char(v_end, 'HH24:MI'),
|
||||||
|
v_date, v_start, v_end)
|
||||||
|
returning * into v_slot;
|
||||||
|
v_slots_created := v_slots_created + 1;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
select exists (select 1 from public.sessions
|
||||||
|
where event_id = v_event_id and external_id = v_ext) into v_existing;
|
||||||
|
insert into public.sessions (event_id, slot_id, title, description, room, capacity, external_id)
|
||||||
|
values (v_event_id, v_slot.id, v_title, v_desc, v_room, v_cap, v_ext)
|
||||||
|
on conflict (external_id) where external_id is not null do update
|
||||||
|
set slot_id = excluded.slot_id,
|
||||||
|
title = excluded.title,
|
||||||
|
description = coalesce(excluded.description, public.sessions.description),
|
||||||
|
room = coalesce(excluded.room, public.sessions.room),
|
||||||
|
capacity = coalesce(excluded.capacity, public.sessions.capacity)
|
||||||
|
returning * into v_session;
|
||||||
|
if v_existing then
|
||||||
|
v_sessions_updated := v_sessions_updated + 1;
|
||||||
|
else
|
||||||
|
v_sessions_created := v_sessions_created + 1;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
for v_spk in select * from jsonb_array_elements(coalesce(v_item -> 'speakers', '[]'::jsonb))
|
||||||
|
loop
|
||||||
|
v_spk_email := v_spk ->> 'email';
|
||||||
|
v_spk_name := v_spk ->> 'full_name';
|
||||||
|
if v_spk_email is null or v_spk_name is null then
|
||||||
|
continue;
|
||||||
|
end if;
|
||||||
|
insert into public.contacts (email, full_name)
|
||||||
|
values (v_spk_email, v_spk_name)
|
||||||
|
on conflict (email) do update
|
||||||
|
set full_name = excluded.full_name;
|
||||||
|
insert into public.session_speakers (session_id, contact_email)
|
||||||
|
values (v_session.id, v_spk_email)
|
||||||
|
on conflict (session_id, contact_email) do nothing;
|
||||||
|
v_speakers_linked := v_speakers_linked + 1;
|
||||||
|
end loop;
|
||||||
|
exception when others then
|
||||||
|
v_err := coalesce(v_title, '<no title>') || ': ' || sqlerrm;
|
||||||
|
v_errors := v_errors || to_jsonb(v_err);
|
||||||
|
end;
|
||||||
|
end loop;
|
||||||
|
|
||||||
|
update public.sync_runs
|
||||||
|
set finished_at = now(),
|
||||||
|
created = v_sessions_created + v_slots_created,
|
||||||
|
updated = v_sessions_updated,
|
||||||
|
skipped = 0,
|
||||||
|
error = case when jsonb_array_length(v_errors) > 0 then v_errors::text else null end
|
||||||
|
where id = v_run_id;
|
||||||
|
|
||||||
|
return jsonb_build_object('slots_created', v_slots_created,
|
||||||
|
'sessions_created', v_sessions_created, 'sessions_updated', v_sessions_updated,
|
||||||
|
'speakers_linked', v_speakers_linked, 'errors', v_errors);
|
||||||
|
end;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
-- 10. GRANTS (new/changed function signatures)
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
grant execute on function public.lanyard_lookup(text) to authenticated;
|
||||||
|
grant execute on function public.create_connection_request(text) to authenticated;
|
||||||
|
grant execute on function public.checkin_attendee(uuid, text) to authenticated;
|
||||||
|
grant execute on function public.reset_registration_qr_token(text) to authenticated;
|
||||||
|
grant execute on function public.upsert_contact(text, text, text, boolean) to authenticated;
|
||||||
|
grant execute on function public.create_registration(text, text) to authenticated;
|
||||||
|
grant execute on function public.sync_pretix_attendees(jsonb) to service_role;
|
||||||
|
grant execute on function public.sync_sessionize_sessions(jsonb) to service_role;
|
||||||
+33
-31
@@ -50,23 +50,24 @@ on conflict (id) do nothing;
|
|||||||
-- -----------------------------------------------------------------------------
|
-- -----------------------------------------------------------------------------
|
||||||
-- CONTACTS (PK = email). Mirrors auth.users.
|
-- CONTACTS (PK = email). Mirrors auth.users.
|
||||||
-- Staff is merged into admin: Bruno, Rita, and the APPE Admin have is_admin.
|
-- Staff is merged into admin: Bruno, Rita, and the APPE Admin have is_admin.
|
||||||
-- Dr. Elena Vasquez is an external keynote speaker (no QR token / auth user).
|
-- Dr. Elena Vasquez is an external keynote speaker (no registration / auth user).
|
||||||
|
-- NOTE: the QR token lives on the REGISTRATION (per event), not the contact.
|
||||||
-- -----------------------------------------------------------------------------
|
-- -----------------------------------------------------------------------------
|
||||||
insert into public.contacts (email, full_name, linkedin_url, show_email, show_linkedin, is_admin, qr_token) values
|
insert into public.contacts (email, full_name, linkedin_url, show_email, show_linkedin, is_admin) values
|
||||||
('[email protected]', 'Ana Silva', 'https://linkedin.com/in/anasilva', true, true, false, 'CVV-ANA-4821'),
|
('[email protected]', 'Ana Silva', 'https://linkedin.com/in/anasilva', true, true, false),
|
||||||
('[email protected]', 'Bruno Costa', 'https://linkedin.com/in/brunocosta', false, true, true, 'CVV-BRU-1177'),
|
('[email protected]', 'Bruno Costa', 'https://linkedin.com/in/brunocosta', false, true, true),
|
||||||
('[email protected]', 'Rita Lopes', null, false, false, true, 'CVV-RIT-9034'),
|
('[email protected]', 'Rita Lopes', null, false, false, true),
|
||||||
('[email protected]','Tomás Ribeiro', null, false, false, false, 'CVV-TOM-5566'),
|
('[email protected]','Tomás Ribeiro', null, false, false, false),
|
||||||
('[email protected]', 'Sofia Almeida', null, false, false, false, 'CVV-SOF-2299'),
|
('[email protected]', 'Sofia Almeida', null, false, false, false),
|
||||||
('[email protected]', 'Marco Chen', null, false, false, false, 'CVV-MRC-7712'),
|
('[email protected]', 'Marco Chen', null, false, false, false),
|
||||||
('[email protected]', 'Julia Santos', null, false, false, false, 'CVV-JUL-3345'),
|
('[email protected]', 'Julia Santos', null, false, false, false),
|
||||||
('[email protected]', 'Pedro Nunes', null, false, false, false, 'CVV-PED-8801'),
|
('[email protected]', 'Pedro Nunes', null, false, false, false),
|
||||||
('[email protected]', 'Carla Mendes', null, false, false, false, 'CVV-CAR-6623'),
|
('[email protected]', 'Carla Mendes', null, false, false, false),
|
||||||
('[email protected]', 'Diego Ferreira', null, false, false, false, 'CVV-DIE-4458'),
|
('[email protected]', 'Diego Ferreira', null, false, false, false),
|
||||||
('[email protected]', 'Marina Costa', null, false, false, false, 'CVV-MNA-2210'),
|
('[email protected]', 'Marina Costa', null, false, false, false),
|
||||||
('[email protected]', 'Lucas Oliveira', null, false, false, false, 'CVV-LUC-9987'),
|
('[email protected]', 'Lucas Oliveira', null, false, false, false),
|
||||||
('[email protected]', 'APPE Admin', null, false, false, true, 'CVV-ADM-0001'),
|
('[email protected]', 'APPE Admin', null, false, false, true),
|
||||||
('[email protected]', 'Dr. Elena Vasquez', null, false, false, false, null)
|
('[email protected]', 'Dr. Elena Vasquez', null, false, false, false)
|
||||||
on conflict (email) do nothing;
|
on conflict (email) do nothing;
|
||||||
|
|
||||||
-- -----------------------------------------------------------------------------
|
-- -----------------------------------------------------------------------------
|
||||||
@@ -77,23 +78,24 @@ insert into public.events (id, name, start_date, end_date, location, is_active)
|
|||||||
on conflict (id) do nothing;
|
on conflict (id) do nothing;
|
||||||
|
|
||||||
-- -----------------------------------------------------------------------------
|
-- -----------------------------------------------------------------------------
|
||||||
-- REGISTRATIONS (per event). Points scoped here.
|
-- REGISTRATIONS (per event). Points scoped here. The QR token lives here
|
||||||
|
-- (per event, generated by Pretix) and doubles as the auth password.
|
||||||
-- Ana is checked in (has check-ins below).
|
-- Ana is checked in (has check-ins below).
|
||||||
-- -----------------------------------------------------------------------------
|
-- -----------------------------------------------------------------------------
|
||||||
insert into public.registrations (event_id, contact_email, type, checked_in, points) values
|
insert into public.registrations (event_id, contact_email, type, checked_in, points, qr_token) values
|
||||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', true, 40),
|
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', true, 40, 'CVV-ANA-4821'),
|
||||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'staff', false, 140),
|
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'staff', false, 140, 'CVV-BRU-1177'),
|
||||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'staff', false, 95),
|
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'staff', false, 95, 'CVV-RIT-9034'),
|
||||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]','attendee', false, 88),
|
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]','attendee', false, 88, 'CVV-TOM-5566'),
|
||||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 76),
|
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 76, 'CVV-SOF-2299'),
|
||||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 70),
|
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 70, 'CVV-MRC-7712'),
|
||||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 64),
|
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 64, 'CVV-JUL-3345'),
|
||||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 58),
|
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 58, 'CVV-PED-8801'),
|
||||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 52),
|
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 52, 'CVV-CAR-6623'),
|
||||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 35),
|
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 35, 'CVV-DIE-4458'),
|
||||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 28),
|
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 28, 'CVV-MNA-2210'),
|
||||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 15),
|
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'attendee', false, 15, 'CVV-LUC-9987'),
|
||||||
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'staff', false, 0)
|
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', '[email protected]', 'staff', false, 0, 'CVV-ADM-0001')
|
||||||
on conflict (event_id, contact_email) do nothing;
|
on conflict (event_id, contact_email) do nothing;
|
||||||
|
|
||||||
-- -----------------------------------------------------------------------------
|
-- -----------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in new issue
Block a user