From ffb270c140db7401d62c367d03d8bf16a6f01b7a Mon Sep 17 00:00:00 2001 From: Jose Lago Date: Sun, 23 Aug 2026 21:33:44 +0200 Subject: [PATCH] Registration optionset + speaker auto-promote + welcome check-in MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - registrations.type is now a Postgres ENUM (registration_type) - session_speakers trigger auto-promotes attendee -> speaker (never overrides staff/sponsor) - new welcome_checkin RPC: staff marks an attendee present at the event - admin Registrations: QR token is final (no reset); failed sponsor change opens in-place sponsor lookup - Convivo Home: Now/Next cards always render; red pending-material pill + popup for speakers - Convivo Agenda: speakers can delete their material to re-upload - Convivo Scan: staff Session/Welcome check-in toggle (uiverse switch) - seed: staff (Bruno/Rita) get a password so staff QR login works after reset Co-authored-by: Stephan Charles Co-authored-by: Amelia Hernandez Co-authored-by: Markus Franz Co-authored-by: Sabrina Hota Co-authored-by: Nilüfer Doğan --- apps/admin/src/views/Registrations.tsx | 192 ++++++++++++++---- apps/convivo/src/lib/api.ts | 24 +++ apps/convivo/src/lib/types.ts | 7 + apps/convivo/src/screens/Agenda.tsx | 20 ++ apps/convivo/src/screens/Home.tsx | 103 ++++++++-- apps/convivo/src/screens/Scan.tsx | 76 +++++-- apps/convivo/src/styles.css | 43 ++++ docs/backend/rpcs.md | 10 + docs/backend/schema.md | 10 +- docs/backend/seed.md | 57 ++++-- docs/frontend/admin-app.md | 31 +-- docs/frontend/api-client.md | 4 +- docs/frontend/screens.md | 41 ++-- docs/next-steps.md | 62 +++++- ...ionset_speaker_promote_welcome_checkin.sql | 164 +++++++++++++++ supabase/seed.sql | 28 +-- 16 files changed, 730 insertions(+), 142 deletions(-) create mode 100644 supabase/migrations/20260829000000_registration_type_optionset_speaker_promote_welcome_checkin.sql diff --git a/apps/admin/src/views/Registrations.tsx b/apps/admin/src/views/Registrations.tsx index 490093b..044623e 100644 --- a/apps/admin/src/views/Registrations.tsx +++ b/apps/admin/src/views/Registrations.tsx @@ -4,11 +4,11 @@ import { getAllContacts, getActiveEvent, getRegistrations, - resetQrToken, setCheckedIn, setRegistrationType, + upsertSponsor, } from '../lib/api'; -import type { Contact, Event, Registration, RegistrationType } from '../lib/types'; +import type { Contact, Event, Registration, RegistrationType, SponsorType } from '../lib/types'; import { useToast } from '../context/ToastContext'; import { Avatar, Empty, Modal, QrImage, Spinner, Toggle, TypeBadge } from '../components/ui'; @@ -24,7 +24,7 @@ export function Registrations() { const [query, setQuery] = useState(''); const [adding, setAdding] = useState(false); const [qrFor, setQrFor] = useState(null); - const [newToken, setNewToken] = useState(null); + const [sponsorFor, setSponsorFor] = useState(null); const [busy, setBusy] = useState(false); async function load() { @@ -69,7 +69,14 @@ export function Registrations() { await load(); push('success', `${byEmail.get(r.contact_email)?.full_name ?? r.contact_email} → ${type}`); } catch (e) { - push('error', e instanceof Error ? e.message : 'Update failed'); + const msg = e instanceof Error ? e.message : 'Update failed'; + // A sponsor registration needs a sponsor lookup — open the in-place + // sponsor popup instead of just failing. + if (type === 'sponsor' && /sponsor lookup/i.test(msg)) { + setSponsorFor(r); + } else { + push('error', msg); + } } finally { setBusy(false); } @@ -87,21 +94,6 @@ 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 ; if (!loaded) return ( @@ -195,7 +187,7 @@ export function Registrations() {
{r.qr_token ?? '—'} -
@@ -233,35 +225,34 @@ export function Registrations() { title={`QR — ${byEmail.get(qrFor.contact_email)?.full_name ?? qrFor.contact_email}`} onClose={() => setQrFor(null)} footer={ - <> - - - + } >
- {newToken ? ( - <> - -
{newToken}
-

- New token issued. The old token no longer works — the person must re-scan. -

- - ) : ( - <> - -
{qrFor.qr_token ?? '—'}
-

Current token. Reset to issue a new one.

- - )} + +
{qrFor.qr_token ?? '—'}
+

+ This token is final — it was generated by Pretix and can’t be reset. +

)} + + {sponsorFor && ( + setSponsorFor(null)} + onSaved={async (msg) => { + setSponsorFor(null); + await load(); + push('success', msg); + }} + /> + )} ); } @@ -340,3 +331,118 @@ function AddRegistrationModal({ ); } + +/** + * In-place sponsor lookup: shown when an admin tries to set a registration to + * 'sponsor' but no sponsor exists for that contact yet. Lets them create the + * sponsor (with a contact search) and then retry the type change. + */ +function SponsorLookupModal({ + registration, + contact, + eventId, + onClose, + onSaved, +}: { + registration: Registration; + contact: Contact | undefined; + eventId: string; + onClose: () => void; + onSaved: (msg: string) => void; +}) { + const [type, setType] = useState('gold'); + const [name, setName] = useState(''); + const [email, setEmail] = useState(''); + const [phone, setPhone] = useState(''); + const [paid, setPaid] = useState(false); + const [amount, setAmount] = useState(''); + const [busy, setBusy] = useState(false); + + const contactEmail = registration.contact_email; + + async function save() { + if (!name.trim()) return; + setBusy(true); + try { + await upsertSponsor(null, { + event_id: eventId, + type, + name: name.trim(), + email: email.trim() || null, + phone: phone.trim() || null, + paid, + amount_eur: amount ? parseFloat(amount) : null, + contact_email: contactEmail, + }); + await setRegistrationType(contactEmail, 'sponsor'); + onSaved(`Sponsor "${name.trim()}" created — ${contact?.full_name ?? contactEmail} is now a sponsor`); + } catch (e) { + onSaved(e instanceof Error ? e.message : 'Save failed'); + } finally { + setBusy(false); + } + } + + return ( + + + + + } + > +

+ A sponsor registration needs a sponsor lookup. Create the sponsor below — it will be linked to{' '} + {contact?.full_name ?? contactEmail} and their registration type set to Sponsor. +

+
+
+ + +
+
+ + setName(e.target.value)} placeholder="e.g. Nubank" /> +
+
+
+
+ + setEmail(e.target.value)} placeholder="—" /> +
+
+ + setPhone(e.target.value)} placeholder="—" /> +
+
+
+
+ + setAmount(e.target.value)} placeholder="0" /> +
+
+ +
+ +
+
+
+
+ ); +} diff --git a/apps/convivo/src/lib/api.ts b/apps/convivo/src/lib/api.ts index 2e1cc06..d4375ea 100644 --- a/apps/convivo/src/lib/api.ts +++ b/apps/convivo/src/lib/api.ts @@ -14,6 +14,7 @@ import type { Registration, Session, Slot, + WelcomeCheckinResult, } from './types'; export class ApiError extends Error {} @@ -157,6 +158,12 @@ export async function checkinAttendee(sessionId: string, attendeeQr: string): Pr return rows[0]; } +/** Staff welcome check-in: mark an attendee present at the event (no session). */ +export async function welcomeCheckin(attendeeQr: string): Promise { + const rows = await rpc('welcome_checkin', { p_attendee_qr: attendeeQr }); + return rows[0]; +} + export async function getMyFeedback(email: string): Promise { const { data, error } = await supabase.from('feedback').select('*').eq('contact_email', email); if (error) throw new ApiError(error.message); @@ -212,3 +219,20 @@ export async function uploadSessionMaterial(sessionId: string, file: File): Prom if (dbErr) throw new ApiError(dbErr.message); return path; } + +/** Remove a session's material (storage object + clear material_path). Speakers + * can delete their own material to re-upload; the path is cleared via the + * `set_session_material` RPC (sessions is admin-write only). */ +export async function removeSessionMaterial(sessionId: string): Promise { + const { data } = await supabase.from('sessions').select('material_path').eq('id', sessionId).maybeSingle(); + const path = (data as Session | null)?.material_path; + if (path) { + const { error: rmErr } = await supabase.storage.from('materials').remove([path]); + if (rmErr) throw new ApiError(rmErr.message); + } + const { error: dbErr } = await supabase.rpc('set_session_material', { + p_session_id: sessionId, + p_material_path: null, + }); + if (dbErr) throw new ApiError(dbErr.message); +} diff --git a/apps/convivo/src/lib/types.ts b/apps/convivo/src/lib/types.ts index 03fc446..3e93a82 100644 --- a/apps/convivo/src/lib/types.ts +++ b/apps/convivo/src/lib/types.ts @@ -159,6 +159,13 @@ export interface CheckinResult { already: boolean; } +/** Result of a staff welcome check-in (marks an attendee present at the event). */ +export interface WelcomeCheckinResult { + attendee_email: string; + attendee_name: string; + already: boolean; +} + export interface FeedbackResult { feedback_id: string; points: number; diff --git a/apps/convivo/src/screens/Agenda.tsx b/apps/convivo/src/screens/Agenda.tsx index e76c6f8..66f90c3 100644 --- a/apps/convivo/src/screens/Agenda.tsx +++ b/apps/convivo/src/screens/Agenda.tsx @@ -6,6 +6,7 @@ import { getMyCheckins, getMyPreferences, getMySpeakerSessions, + removeSessionMaterial, sessionMaterialUrl, setPreference, uploadSessionMaterial, @@ -114,6 +115,19 @@ export function Agenda({ openFeedback }: { openFeedback: (sessionId: string) => } } + async function handleDeleteMaterial() { + if (!selected) return; + if (!confirm('Remove this material? You can upload a new one.')) return; + try { + await removeSessionMaterial(selected.id); + toast('Material removed', 'ok'); + setSelected(null); + reload(); + } catch (err) { + toast(err instanceof Error ? err.message : 'Could not remove material', 'err'); + } + } + return (
@@ -222,6 +236,12 @@ export function Agenda({ openFeedback }: { openFeedback: (sessionId: string) => 📎 Download material )} + {/* Speakers can remove their own material to re-upload. */} + {selISpeaker && selected.material_path && ( + + )}
)} diff --git a/apps/convivo/src/screens/Home.tsx b/apps/convivo/src/screens/Home.tsx index b436c99..035c24a 100644 --- a/apps/convivo/src/screens/Home.tsx +++ b/apps/convivo/src/screens/Home.tsx @@ -1,16 +1,18 @@ import { useEffect, useState } from 'react'; import { useAuth } from '../context/AuthContext'; import { useEvent } from '../lib/useEvent'; -import { getMyCheckins, getMyPreferences } from '../lib/api'; +import { getMyCheckins, getMyPreferences, getMySpeakerSessions } from '../lib/api'; import { fmtRange, greeting, slotStatus } from '../lib/time'; -import type { Preference } from '../lib/types'; -import { Empty, Spinner } from '../components/ui'; +import type { Preference, Session } from '../lib/types'; +import { Empty, Sheet, Spinner } from '../components/ui'; export function Home({ go }: { go: (tab: string) => void }) { const { contact, registration } = useAuth(); const { event, slots, sessionById, now, loading } = useEvent(); const [prefs, setPrefs] = useState([]); const [checkins, setCheckins] = useState([]); + const [mySpeakerSessions, setMySpeakerSessions] = useState([]); + const [materialSheetOpen, setMaterialSheetOpen] = useState(false); const email = contact?.email ?? ''; @@ -18,10 +20,15 @@ export function Home({ go }: { go: (tab: string) => void }) { let active = true; (async () => { try { - const [p, c] = await Promise.all([getMyPreferences(), getMyCheckins(email)]); + const [p, c, sp] = await Promise.all([ + getMyPreferences(), + getMyCheckins(email), + getMySpeakerSessions(email), + ]); if (!active) return; setPrefs(p); setCheckins(c); + setMySpeakerSessions(sp); } catch { /* non-fatal */ } @@ -60,6 +67,11 @@ export function Home({ go }: { go: (tab: string) => void }) { const nowSession = current ? sessionById.get(pickFor(current.slot.id) ?? '') : undefined; const nextSession = next ? sessionById.get(pickFor(next.slot.id) ?? '') : undefined; + // Sessions the signed-in contact speaks in that still have no material uploaded. + const pendingMaterial = mySpeakerSessions + .map((id) => sessionById.get(id)) + .filter((s): s is Session => !!s && !s.material_path); + const firstName = contact.full_name.split(' ')[0]; return ( @@ -69,37 +81,60 @@ export function Home({ go }: { go: (tab: string) => void }) {
{greeting(now)}, {firstName} 👋
{event.name}
-
go('leaderboard')}>⚡ {points}
+
+ {pendingMaterial.length > 0 && ( +
setMaterialSheetOpen(true)}> + 📎 {pendingMaterial.length} +
+ )} +
go('leaderboard')}>⚡ {points}
+
- {nowSession && current && ( + {current && (
● Now {fmtRange(current.slot)}
-
{nowSession.title}
-
- {nowSession.room} · {nowSession.speakers} -
- {checkins.includes(nowSession.id) ? ( - ✓ Checked in + {nowSession ? ( + <> +
{nowSession.title}
+
+ {nowSession.room} · {nowSession.speakers} +
+ {checkins.includes(nowSession.id) ? ( + ✓ Checked in + ) : ( + Show your QR to staff to check in + )} + ) : ( - Show your QR to staff to check in +
+ No pick yet — tap a session in the Agenda to choose. +
)}
)} - {nextSession && next && ( + {next && (
Next {fmtRange(next.slot)}
-
{nextSession.title}
-
- {nextSession.room} · {nextSession.speakers} -
+ {nextSession ? ( + <> +
{nextSession.title}
+
+ {nextSession.room} · {nextSession.speakers} +
+ + ) : ( +
+ No pick yet — tap a session in the Agenda to choose. +
+ )}
)} @@ -145,6 +180,38 @@ export function Home({ go }: { go: (tab: string) => void }) {
+ + {/* Pending material popup (speakers only, when a session is missing its attachment) */} + setMaterialSheetOpen(false)}> +

📎 Pending material

+
+ The following sessions are pending to upload their attachments. +
+
+ {pendingMaterial.map((s) => { + const slot = slots.find((x) => x.slot.id === s.slot_id)?.slot; + return ( + + ); + })} +
+ +
); } diff --git a/apps/convivo/src/screens/Scan.tsx b/apps/convivo/src/screens/Scan.tsx index e11f7c8..ecc1e54 100644 --- a/apps/convivo/src/screens/Scan.tsx +++ b/apps/convivo/src/screens/Scan.tsx @@ -1,9 +1,9 @@ import { useEffect, useState } from 'react'; import { useAuth } from '../context/AuthContext'; import { useEvent } from '../lib/useEvent'; -import { checkinAttendee, createConnectionRequest, lanyardLookup } from '../lib/api'; +import { checkinAttendee, createConnectionRequest, lanyardLookup, welcomeCheckin } from '../lib/api'; import { capWords } from '../lib/time'; -import type { CheckinResult, PublicContact } from '../lib/types'; +import type { CheckinResult, PublicContact, WelcomeCheckinResult } from '../lib/types'; import { Avatar, Scanner, Sheet, Spinner } from '../components/ui'; import { useToast } from '../context/ToastContext'; @@ -13,8 +13,10 @@ export function Scan() { const isStaff = !!contact?.is_admin; const [mode, setMode] = useState<'attendee' | 'staff'>(isStaff ? 'staff' : 'attendee'); const [sessionId, setSessionId] = useState(''); + const [welcomeMode, setWelcomeMode] = useState(false); const [connectTarget, setConnectTarget] = useState<{ contact: PublicContact; qr: string } | null>(null); const [checkin, setCheckin] = useState(null); + const [welcome, setWelcome] = useState(null); const [busy, setBusy] = useState(false); const { toast } = useToast(); @@ -42,12 +44,17 @@ export function Scan() { setBusy(true); try { if (activeStaff) { - if (!sessionId) { - toast('Pick a session first', 'err'); - return; + if (welcomeMode) { + const res = await welcomeCheckin(token); + setWelcome(res); + } else { + if (!sessionId) { + toast('Pick a session first', 'err'); + return; + } + const res = await checkinAttendee(sessionId, token); + setCheckin(res); } - const res = await checkinAttendee(sessionId, token); - setCheckin(res); } else { const found = await lanyardLookup(token); if (!found) { @@ -103,22 +110,40 @@ export function Scan() { {activeStaff && (
-
Checking in to session
- setWelcomeMode(e.target.checked)} + /> + +
+ {welcomeMode ? ( +
+ 🏷 Welcome check-in — marks the attendee present at the event. +
+ ) : ( + <> +
Checking in to session
+ + + + )} )} {busy &&
} - {activeStaff && selSession && ( + {activeStaff && !welcomeMode && selSession && (
{selSession.room} · {selSession.speakers}
@@ -172,6 +197,23 @@ export function Scan() { )} + + {/* Welcome check-in result sheet */} + setWelcome(null)}> + {welcome && ( +
+
{welcome.already ? '⚠️' : '👋'}
+

{welcome.attendee_name}

+
{welcome.already ? 'Already checked in to the event' : 'Welcome to the event!'}
+
+ ✓ Checked in +
+ +
+ )} +
); } diff --git a/apps/convivo/src/styles.css b/apps/convivo/src/styles.css index e3c435c..5b4ed52 100644 --- a/apps/convivo/src/styles.css +++ b/apps/convivo/src/styles.css @@ -165,6 +165,11 @@ textarea.input { resize: none; min-height: 96px; } background: rgba(245,158,11,.14); border: 1px solid rgba(245,158,11,.4); color: #b45309; font-weight: 800; font-size: 14px; cursor: pointer; flex-shrink: 0; white-space: nowrap; } +.material-pill { + display: inline-flex; align-items: center; gap: 6px; padding: 8px 13px; border-radius: 999px; + background: rgba(213,0,0,.1); border: 1px solid rgba(213,0,0,.4); + color: #d50000; font-weight: 800; font-size: 14px; cursor: pointer; flex-shrink: 0; white-space: nowrap; +} .now-card { background: linear-gradient(135deg, rgba(213,0,0,.1), rgba(32,178,170,.08)); border: 1px solid rgba(213,0,0,.35); } .qa-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; } .qa { @@ -215,6 +220,44 @@ textarea.input { resize: none; min-height: 96px; } .sheet h3 { font-size: 19px; font-weight: 800; letter-spacing: -.3px; } .sheet .sub { color: var(--muted); font-size: 13px; margin-top: 3px; } +/* ---------- Scan: uiverse check-in type toggle (Shoh2008 / brown-bulldog-12) ---------- */ +.uiverse-toggle { display: inline-flex; } +.uiverse-toggle input[type="checkbox"] { + --size: 58px; + -webkit-appearance: none; + appearance: none; + width: var(--size); + height: calc(var(--size) / 2); + background-color: var(--surface); + border: 3px solid var(--line); + border-radius: 30px 100px 100px 100px; + box-shadow: 0 6px 14px rgba(66,60,60,.14); + outline: none; + cursor: pointer; + position: relative; + transition: all .4s; +} +.uiverse-toggle input[type="checkbox"]::before { + content: ""; + position: absolute; + width: calc(var(--size) / 2 - 8px); + height: calc(var(--size) / 2 - 8px); + left: 3px; + top: 50%; + transform: translateY(-50%) scale(1); + border-radius: 50%; + background-color: var(--muted); + transition: all .4s; +} +.uiverse-toggle input[type="checkbox"]:checked { + background-color: var(--accent); + border-color: var(--accent); +} +.uiverse-toggle input[type="checkbox"]:checked::before { + left: calc(100% - calc(var(--size) / 2 - 8px) - 3px); + background-color: #fff; +} + /* ---------- Connections ---------- */ .seg { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 13px; padding: 4px; } .seg button { diff --git a/docs/backend/rpcs.md b/docs/backend/rpcs.md index 1392240..cf787a1 100644 --- a/docs/backend/rpcs.md +++ b/docs/backend/rpcs.md @@ -111,6 +111,15 @@ Staff checks an attendee into a session. > `return query` inside an `if` block would *not* terminate the function and would > double-award. +### `welcome_checkin(p_attendee_qr)` → `(attendee_email, attendee_name, already)` +Staff **welcome** check-in: marks an attendee present at the **event** (distinct +from `checkin_attendee`, which checks someone into a specific session). +- **Role check:** `is_staff_or_admin()` or it raises `staff or admin only`. +- Resolves the attendee by `qr_token` for the active event. +- Sets `registrations.checked_in = true` (no points — that's the session + check-in's job). +- `already` is `true` if the attendee was already checked in to the event. + ### `submit_feedback(p_session_id, p_rating, p_comment)` → `(feedback_id, points, earned)` Post-session feedback. - **Requires the caller to be checked in** to that session (else raises). @@ -166,6 +175,7 @@ immediately. ### `set_registration_type(p_contact_email, p_type)` → `registrations` **Admin-only.** Changes a contact's registration type for the active event. +`p_type` is `text` and is cast to the `registration_type` enum on write. ### `evaluate_session_feedback(p_session_id)` → `sessions` **Admin-only.** The **AI-feedback stub**: sets `ai_generated_feedback` to a diff --git a/docs/backend/schema.md b/docs/backend/schema.md index 82e034f..cfc6e21 100644 --- a/docs/backend/schema.md +++ b/docs/backend/schema.md @@ -94,7 +94,7 @@ Points are scoped **per event** here (one row per contact per event). | `id` | `uuid` PK | | | `event_id` | `uuid` FK → `events` | `on delete cascade` | | `contact_email` | `text` FK → `contacts` | `on delete cascade` | -| `type` | `text` | `attendee` \| `speaker` \| `staff` \| `sponsor` (default `attendee`) | +| `type` | `registration_type` (enum) | `attendee` \| `speaker` \| `staff` \| `sponsor` (default `attendee`) | | `checked_in` | `boolean` | default `false` | | `points` | `integer` | `>= 0`, default 0 | | `qr_token` | `text` | nullable — the lanyard token; **doubles as the Auth password** (generated per event) | @@ -105,6 +105,14 @@ Points are scoped **per event** here (one row per contact per event). 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). +**`type` is a Postgres ENUM** (`public.registration_type`), not free text — the +four ticket types are enforced at the database level. + +**Speaker auto-promote:** the `session_speakers_speaker_promote` trigger (after +insert on `session_speakers`) promotes a contact's active-event registration from +`attendee` → `speaker` when they're added as a speaker. It is one-way (removing a +speaker never demotes) and never overrides an explicit `staff`/`sponsor` ticket. + ## `sponsors` — a sponsor for an event Unpaid sponsors are hidden from non-admins (RLS). diff --git a/docs/backend/seed.md b/docs/backend/seed.md index 8feb63c..2a8da80 100644 --- a/docs/backend/seed.md +++ b/docs/backend/seed.md @@ -42,31 +42,43 @@ Source of truth: [`supabase/seed.sql`](../../supabase/seed.sql). The seed runs o ## Demo accounts -**Attendees & staff** log in with **QR code** (typed or scanned) + **email** — -the QR token is the Auth password. The **APPE Admin** (and any staff member you -give one) can also log in with **email + password** (event-independent, so it -works for any event). The password lives in `contacts.password`; a trigger -(`trg_contact_password_sync`) **auto-syncs** it as the bcrypt hash in -`auth.users.encrypted_password`, so just set `contacts.password` in Supabase and -it works with `signInWithPassword` immediately. +**Attendees** log in with **QR code** (typed or scanned) + **email** — the QR +token is the Auth password. **Staff** log in with **QR code + their staff +password** (the Convivo app shows a password field when a staff QR is detected; +the email comes from the resolved contact). The **APPE Admin** (and any staff +member you give one) can also log in with **email + password** in the admin app +(event-independent, so it works for any event). The password lives in +`contacts.password`; a trigger (`trg_contact_password_sync`) **auto-syncs** it as +the bcrypt hash in `auth.users.encrypted_password`, so just set +`contacts.password` in Supabase and it works with `signInWithPassword` +immediately. | Person | Type | Login | Email | Start pts | |---|---|---|---|---| -| **Ana Silva** | attendee | QR `CVV-ANA-4821` | ana.silva@nubank.com | 40 | -| **Bruno Costa** | staff (admin) | QR `CVV-BRU-1177` | bruno.costa@acme.com | 140 | -| **Rita Lopes** | staff (admin) | QR `CVV-RIT-9034` | rita.lopes@globant.com | 95 | +| **Ana Silva** | speaker | QR `CVV-ANA-4821` | ana.silva@nubank.com | 40 | +| **Bruno Costa** | staff (admin) | QR `CVV-BRU-1177` + **password** `appe-admin-2026` | bruno.costa@acme.com | 140 | +| **Rita Lopes** | staff (admin) | QR `CVV-RIT-9034` + **password** `appe-admin-2026` | rita.lopes@globant.com | 95 | | **APPE Admin** | staff (admin) | **password** `appe-admin-2026` | admin@appe.at | 0 | -| Tomás Ribeiro | attendee | `CVV-TOM-5566` | tomas.ribeiro@dataprev.com | 88 | -| Sofia Almeida | attendee | `CVV-SOF-2299` | sofia.almeida@loop.com | 76 | -| Marco Chen | attendee | `CVV-MRC-7712` | marco.chen@deepmind.com | 70 | -| Julia Santos | attendee | `CVV-JUL-3345` | julia.santos@ifood.com | 64 | -| Pedro Nunes | attendee | `CVV-PED-8801` | pedro.nunes@microsoft.com | 58 | -| Carla Mendes | attendee | `CVV-CAR-6623` | carla.mendes@quintoessencial.com | 52 | -| Diego Ferreira | attendee | `CVV-DIE-4458` | diego.ferreira@stone.com | 35 | -| Marina Costa | attendee | `CVV-MNA-2210` | marina.costa@olx.com | 28 | -| Lucas Oliveira | attendee | `CVV-LUC-9987` | lucas.oliveira@usp.br | 15 | +| Tomás Ribeiro | speaker | `CVV-TOM-5566` | tomas.ribeiro@dataprev.com | 88 | +| Sofia Almeida | speaker | `CVV-SOF-2299` | sofia.almeida@loop.com | 76 | +| Marco Chen | speaker | `CVV-MRC-7712` | marco.chen@deepmind.com | 70 | +| Julia Santos | speaker | `CVV-JUL-3345` | julia.santos@ifood.com | 64 | +| Pedro Nunes | speaker | `CVV-PED-8801` | pedro.nunes@microsoft.com | 58 | +| Carla Mendes | speaker | `CVV-CAR-6623` | carla.mendes@quintoessencial.com | 52 | +| Diego Ferreira | speaker | `CVV-DIE-4458` | diego.ferreira@stone.com | 35 | +| Marina Costa | speaker | `CVV-MNA-2210` | marina.costa@olx.com | 28 | +| Lucas Oliveira | speaker | `CVV-LUC-9987` | lucas.oliveira@usp.br | 15 | | Dr. Elena Vasquez | (external speaker) | — | elena.vasquez@keynote.com | — | +> **Speaker auto-promote:** every seeded attendee who speaks in a session is +> typed `speaker` (the `session_speakers_speaker_promote` trigger promotes +> `attendee` → `speaker` on insert, so the seed states the final type). Only +> Bruno, Rita, and the APPE Admin are `staff` (the trigger never overrides an +> explicit staff/sponsor ticket). +> +> **Staff passwords:** Bruno and Rita have `contacts.password = 'appe-admin-2026'` +> so the Convivo **staff QR login** (QR + staff password) works out of the box. + > **Dr. Elena Vasquez** is an external keynote speaker: she has a `contacts` row > (and speaks in `session_speakers`) but **no registration, no QR token, and no > auth user**, so she can't log in — she only appears as a speaker on the agenda. @@ -101,8 +113,11 @@ Ana (`ana.silva@nubank.com`) is seeded with a coherent 40-point history: 1. Log in as **Ana** (attendee) → Home, Agenda, Leaderboard all populated. 2. Scan **Marco** (`CVV-MRC-7712`) → send a connection request. -3. Log in as **Bruno** (staff) → the Scan tab becomes **Check-in** → pick a - session → scan **Carla** (`CVV-CAR-6623`) → she gets +10. +3. Log in as **Bruno** (staff) → QR `CVV-BRU-1177` + staff password + `appe-admin-2026` → the Scan tab becomes **Check-in** → pick a session → scan + **Carla** (`CVV-CAR-6623`) → she gets +10. Flip the **check-in type toggle** + to **Welcome check-in** and scan **Tomás** (`CVV-TOM-5566`) → he's marked + present at the event (no points). 4. Watch the **Leaderboard** update live (Realtime). 5. Log in as **APPE Admin** (`admin@appe.at` / password `appe-admin-2026`) in the admin app → Dashboard, Contacts, Registrations, Sponsors, Schedule, Activity, diff --git a/docs/frontend/admin-app.md b/docs/frontend/admin-app.md index 4b23bfb..9ac159e 100644 --- a/docs/frontend/admin-app.md +++ b/docs/frontend/admin-app.md @@ -15,7 +15,7 @@ It runs on **port 3001** (Vite dev) or as the `convivo-admin` Docker container |---|---| | **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`). Edit, toggle `is_admin`, set visibility, adjust points. (No QR token here — it lives on the registration.) | -| **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). | +| **Registrations** | Per active event: list (contact, type, **QR token**, checked_in, points). Change type (enforces the sponsor rule — a failed sponsor change opens an **in-place sponsor lookup** popup), mark checked-in, **view the QR token** (final — no reset). | | **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 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). | @@ -59,7 +59,7 @@ apps/admin/src/ └─ views/ ├─ Dashboard.tsx # active event + aggregates + top points + activity ├─ Contacts.tsx # table + edit / is_admin / visibility / points - ├─ Registrations.tsx# per-event list + type / QR token (+reset) / checked-in + ├─ Registrations.tsx# per-event list + type / QR token (view) / checked-in + sponsor lookup ├─ Sponsors.tsx # sponsor CRUD ├─ Schedule.tsx # slots + sessions + speakers + material + AI-evaluate ├─ Activity.tsx # check-ins / connections / feedback tables @@ -79,22 +79,29 @@ key. Everything it can do is allowed by RLS: - **Writes** — direct `insert` / `update` / `delete` on `contacts`, `events`, `registrations`, `sponsors`, `slots`, `sessions`, and `session_speakers` (admin-only policies). -- **RPCs** — `reset_registration_qr_token` (regenerate a registration's lanyard - token), `adjust_points` (manual, audited as `admin`), `upsert_contact`, +- **RPCs** — `adjust_points` (manual, audited as `admin`), `upsert_contact`, `create_registration`, `set_registration_type`, `evaluate_session_feedback` - (AI stub), and `set_session_material` (attach uploaded material). See + (AI stub), and `set_session_material` (attach uploaded material). The + `reset_registration_qr_token` RPC still exists (used by the sync path) but the + admin UI no longer exposes a token reset. See [../backend/rpcs.md](../backend/rpcs.md). -### Resetting a QR token +### Viewing a QR token The QR token lives on the **registration** (per event), not the contact. The **Registrations** view shows each registration's token and a **QR** button that -opens a modal with the scannable code + a **Reset token** action. Reset calls -`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. +opens a modal with the scannable code. The token is **final** — it is generated by +Pretix and can't be reset from the UI (the `reset_registration_qr_token` RPC still +exists for the sync path, but the admin UI no longer exposes a reset action). + +### Sponsor lookup (in-place) + +Setting a registration's type to **Sponsor** requires a sponsor lookup. If none +exists for that contact, the change fails with `a sponsor registration requires a +sponsor lookup` and the UI opens an **in-place sponsor popup** (instead of just +erroring). The popup lets the admin create the sponsor (type, name, email, phone, +amount, paid) linked to that contact, then sets the registration type to +`sponsor` in one step. ### Adjusting points diff --git a/docs/frontend/api-client.md b/docs/frontend/api-client.md index 4b4a4b1..239eb78 100644 --- a/docs/frontend/api-client.md +++ b/docs/frontend/api-client.md @@ -50,10 +50,12 @@ These map 1:1 to the Postgres RPCs documented in | `createConnectionRequest(targetQr)` | `create_connection_request` | Send a connection request | | `acceptConnection(id)` | `accept_connection` | Accept (+5 to both) | | `rejectConnection(id)` | `reject_connection` | Decline | -| `checkinAttendee(sessionId, attendeeQr)` | `checkin_attendee` | Staff check-in (+10) | +| `checkinAttendee(sessionId, attendeeQr)` | `checkin_attendee` | Staff session check-in (+10) | +| `welcomeCheckin(attendeeQr)` | `welcome_checkin` | Staff welcome check-in (marks present at event, no points) | | `submitFeedback(sessionId, rating, comment)` | `submit_feedback` | Rate a session (+5/+10) | | `getLeaderboard()` | `get_leaderboard` | Active-event leaderboard | | `uploadSessionMaterial(sessionId, file)` | `set_session_material` | Upload to `materials` bucket + set `material_path` | +| `removeSessionMaterial(sessionId)` | `set_session_material` | Delete storage object + clear `material_path` (speakers) | | `updateMyProfile({linkedin_url, show_email, show_linkedin})` | `update_my_profile` | Self-service: set LinkedIn + visibility toggles on the caller's own contact | ### Direct table reads (RLS-scoped) diff --git a/docs/frontend/screens.md b/docs/frontend/screens.md index d4c5ab9..094a43c 100644 --- a/docs/frontend/screens.md +++ b/docs/frontend/screens.md @@ -45,12 +45,15 @@ A 3-step flow: **splash → scan → confirm**. ## Home The landing screen. Shows: -- **Greeting + points pill** — "Good morning, Ana 👋" and `⚡ {points}` (tapping - the pill opens the Leaderboard). The event name (`event.name`) is shown under - the greeting. -- **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. -- **Next card** — the pick for the next slot. +- **Greeting + pills** — "Good morning, Ana 👋" and, to the right, a **red + material pill** `📎 {n}` (only for speakers who have one or more of their + sessions without material — tapping it opens a popup listing the pending + sessions) and the **points pill** `⚡ {points}` (tapping opens the Leaderboard). + The event name (`event.name`) is shown under the greeting. +- **Now card** — **always shown** for the current slot. If the user has a pick, + the session title + a "✓ Checked in" / "Show your QR to staff to check in" + pill; otherwise a "No pick yet" placeholder (identical layout for every role). +- **Next card** — **always shown** for the next slot (pick or "No pick yet"). - **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. - **Quick actions** — Scan & connect, Agenda, Connections, Leaderboard. @@ -58,11 +61,14 @@ The landing screen. Shows: Check back soon!"). > **Identical for every role.** The Home screen (and the tab bar) is the same for -> attendees and staff — no role badge, no "Check-in" relabel. Staff keep their -> check-in capability inside the **Scan** screen (Attendee/Staff mode toggle). +> attendees and staff — no role badge, no "Check-in" relabel. The Now/Next cards +> always render (with a "No pick yet" placeholder when there's no pick), so the +> layout is identical whether or not the user has picks. Staff keep their check-in +> capability inside the **Scan** screen (Attendee/Staff mode toggle). Data: `useEvent()` (event + agenda + clock) + `getMyPreferences()` + -`getMyCheckins(email)`. Slot status comes from `slotStatus(slot, now)` +`getMyCheckins(email)` + `getMySpeakerSessions(email)` (for the pending-material +pill). Slot status comes from `slotStatus(slot, now)` ([app-structure.md#the-event-clock](./app-structure.md#the-event-clock)). ## Agenda @@ -84,6 +90,9 @@ user speaks shows a **"🎤 you"** tag; a session with material shows a **📎** notice is gone and a **📎 Download material** button appears (visible to **all** attendees), pinned to the **bottom** of the sheet's button stack (below "Pick this session"). + - **Remove material** — a speaker of the session can also **🗑 Remove material** + (to re-upload). This deletes the storage object and clears `material_path` via + `set_session_material` (null) — `removeSessionMaterial`. - Picking is "one per slot" — picking a new session in a slot replaces the old pick (enforced by the `set_preference` RPC). @@ -101,10 +110,16 @@ is role-aware — staff (`contact.is_admin`) default to **Staff** mode, attendee "Connect with {name}?" sheet (with the peer's registration-type badge + LinkedIn link if visible) → `createConnectionRequest(qr)`. Guards: can't connect with yourself. Result toast reflects the connection status (sent / already connected). -- **Staff mode (check-in):** pick a session (dropdown grouped by slot), then scan - an attendee's lanyard → `checkinAttendee(sessionId, qr)`. Shows a result sheet: - "✓ {name} — Checked in — +10 pts · now {total}" or "⚠️ Already checked in — no - extra points" (the `already` flag from the RPC). +- **Staff mode (check-in):** a **check-in type toggle** (uiverse switch) switches + between two sub-modes: + - **Session check-in** (default) — pick a session (dropdown grouped by slot), + then scan an attendee's lanyard → `checkinAttendee(sessionId, qr)`. Shows a + result sheet: "✓ {name} — Checked in — +10 pts · now {total}" or "⚠️ Already + checked in — no extra points" (the `already` flag from the RPC). + - **Welcome check-in** — no session dropdown; scanning an attendee's lanyard → + `welcomeCheckin(qr)` marks them present at the **event** + (`registrations.checked_in = true`, no points). Result sheet: "👋 {name} — + Welcome to the event! — ✓ Checked in" (or "Already checked in to the event"). Data: `useEvent()` (for the session list) + the RPCs above. diff --git a/docs/next-steps.md b/docs/next-steps.md index 696d5de..1a4a94d 100644 --- a/docs/next-steps.md +++ b/docs/next-steps.md @@ -4,15 +4,21 @@ 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 current phase. -> **Current state:** Phases 0–8 are complete and verified, plus three polish +> **Current state:** Phases 0–8 are complete and verified, plus five polish > rounds: **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), > **Admin password + profile self-service** (admin logs in with email + password; -> attendees set LinkedIn + visibility on their Profile), and **Staff exclusions -> + password sync** (setting `contacts.password` auto-syncs the Auth password; +> attendees set LinkedIn + visibility on their Profile), **Staff exclusions + +> password sync** (setting `contacts.password` auto-syncs the Auth password; > staff excluded from the leaderboard; Home/Agenda/Profile identical for all -> roles). +> roles), **Convivo staff QR login** (a staff QR asks for the staff password, not +> an email), and **Registration optionset + speaker promote + welcome check-in** +> (`registrations.type` is now a Postgres enum; adding a speaker auto-promotes +> their registration to `speaker`; staff can do a Welcome check-in that marks an +> attendee present at the event; the admin QR token is final (no reset) and a +> failed sponsor change opens an in-place sponsor lookup; speakers see a red +> pending-material pill on Home and can delete their material to re-upload). > Remaining work is cross-cutting (real event clock, deployment, testing) and > the open questions in [backend/interfaces.md](./backend/interfaces.md). @@ -304,6 +310,54 @@ browser-verified. - Agenda session sheet: **"Download material"** moved to the **bottom** of the button stack (below "Pick this session") with proper spacing. +## Registration optionset + speaker promote + welcome check-in — ✅ complete + +Migration `20260829000000_registration_type_optionset_speaker_promote_welcome_checkin.sql` ++ app changes, all browser-verified. + +**`registrations.type` is now a Postgres ENUM** (`public.registration_type`). +- The `text` column (with its old CHECK constraint + text default) is converted + to the enum; the old CHECK and default are dropped first (they can't be + auto-cast), then the enum default is set. +- The admin RPCs (`create_registration`, `set_registration_type`) take `p_type + text` and now cast it to the enum on write. + +**Speaker auto-promote trigger.** +- `session_speakers_speaker_promote` (after insert on `session_speakers`) + promotes a contact's active-event registration from `attendee` → `speaker`. + One-way (removing a speaker never demotes) and never overrides an explicit + `staff`/`sponsor` ticket. The seed states the final types explicitly. + +**Welcome check-in (staff).** +- New `welcome_checkin(p_attendee_qr)` RPC (staff-only): resolves the attendee by + QR for the active event and sets `registrations.checked_in = true` (no points). +- The Convivo **Scan** screen's Staff mode has a **check-in type toggle** + (uiverse switch) switching between **Session check-in** (existing dropdown + + `checkin_attendee`) and **Welcome check-in** (`welcome_checkin`). + +**Admin Registrations: final QR token + in-place sponsor lookup.** +- The **Reset token** button is gone — the token is final (generated by Pretix). + The QR modal now says "This token is final…". +- Setting a type to **Sponsor** when no sponsor lookup exists opens an + **in-place sponsor popup** (create the sponsor linked to the contact, then set + the type) instead of just erroring. + +**Convivo Home: always-on Now/Next + pending-material pill.** +- The **Now** and **Next** cards always render (with a "No pick yet" placeholder + when there's no pick), so the layout is identical for every role. +- Speakers with one or more sessions missing material see a **red `📎 {n}` pill** + (left of the points pill); tapping it opens a popup listing the pending + sessions. The pill disappears once every session has material. + +**Convivo Agenda: speakers can delete their material.** +- A speaker of a session with material sees a **🗑 Remove material** button + (deletes the storage object + clears `material_path` via `set_session_material` + null) so they can re-upload. + +**Seed: staff passwords.** +- Bruno and Rita now have `contacts.password = 'appe-admin-2026'` so the Convivo + **staff QR login** (QR + staff password) works out of the box after a reset. + ## Cross-cutting / later - **Real event clock** — replace the simulated `DEFAULT_NOW` diff --git a/supabase/migrations/20260829000000_registration_type_optionset_speaker_promote_welcome_checkin.sql b/supabase/migrations/20260829000000_registration_type_optionset_speaker_promote_welcome_checkin.sql new file mode 100644 index 0000000..778ac0e --- /dev/null +++ b/supabase/migrations/20260829000000_registration_type_optionset_speaker_promote_welcome_checkin.sql @@ -0,0 +1,164 @@ +-- ============================================================================= +-- Convivo — Registration type optionset + speaker auto-promote + welcome check-in +-- +-- 1. `registrations.type` becomes a Postgres ENUM (`registration_type`) — a true +-- optionset of the four ticket types, enforced at the database level. +-- 2. A trigger auto-promotes a contact's registration from 'attendee' to +-- 'speaker' when they're added to `session_speakers` (never overrides +-- staff/sponsor — those are explicit ticket types). +-- 3. New `welcome_checkin` RPC: staff scan an attendee's lanyard to mark them +-- checked in to the EVENT (registrations.checked_in = true). Distinct from +-- `checkin_attendee`, which checks someone into a specific session. +-- ============================================================================= + +-- ----------------------------------------------------------------------------- +-- 1. REGISTRATION TYPE OPTIONSET (Postgres ENUM) +-- ----------------------------------------------------------------------------- +do $$ +begin + if not exists (select 1 from pg_type where typname = 'registration_type') then + create type public.registration_type as enum ('attendee', 'speaker', 'staff', 'sponsor'); + end if; +end $$; + +-- Convert the column to the enum. Existing values ('attendee'/'speaker'/'staff'/ +-- 'sponsor') all map cleanly. The `type` column name is quoted to avoid any +-- keyword ambiguity in the ALTER; the USING clause does the explicit text→enum +-- cast (Postgres won't cast text to an enum implicitly). The old text CHECK +-- constraint and text default can't be auto-cast, so drop both first, convert, +-- then set the enum default. +alter table public.registrations drop constraint if exists registrations_type_check; +alter table public.registrations alter column "type" drop default; +alter table public.registrations + alter column "type" type public.registration_type using "type"::public.registration_type; +alter table public.registrations + alter column "type" set default 'attendee'::public.registration_type; + +-- The admin RPCs take `p_type text` and write it to the (now enum) column. +-- Re-create them with an explicit cast so the text param maps to the enum. +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; +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; + insert into public.registrations (event_id, contact_email, type) + values (v_event_id, p_contact_email, p_type::public.registration_type) + on conflict (event_id, contact_email) do update set type = excluded.type + returning * into v_reg; + return v_reg; +end; +$$; + +create or replace function public.set_registration_type(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; +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 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; + update public.registrations set type = p_type::public.registration_type + where event_id = v_event_id and contact_email = p_contact_email + returning * into v_reg; + if not found then raise exception 'registration not found'; end if; + return v_reg; +end; +$$; + +-- ----------------------------------------------------------------------------- +-- 2. SPEAKER AUTO-PROMOTE TRIGGER +-- ----------------------------------------------------------------------------- +-- When a contact is added as a speaker of a session, promote their active-event +-- registration from 'attendee' to 'speaker'. This is one-way: removing a speaker +-- never demotes them, and it never overrides an explicit staff/sponsor ticket. +create or replace function public._trg_speaker_promote() returns trigger +language plpgsql security definer set search_path = public as $$ +declare + v_event_id uuid; +begin + if tg_op = 'INSERT' then + select s.event_id into v_event_id + from public.sessions s where s.id = new.session_id; + if v_event_id is not null then + update public.registrations + set "type" = 'speaker' + where event_id = v_event_id + and contact_email = new.contact_email + and "type" = 'attendee'; + end if; + end if; + return new; +end; +$$; + +drop trigger if exists session_speakers_speaker_promote on public.session_speakers; +create trigger session_speakers_speaker_promote + after insert on public.session_speakers + for each row execute function public._trg_speaker_promote(); + +-- ----------------------------------------------------------------------------- +-- 3. WELCOME CHECK-IN (staff marks an attendee present at the event) +-- ----------------------------------------------------------------------------- +-- Resolves the scanned lanyard QR to the attendee's active-event registration and +-- marks them checked in to the event. No points are awarded (that's the session +-- check-in's job); this just records that the person is on site. +create or replace function public.welcome_checkin(p_attendee_qr text) +returns table (attendee_email text, attendee_name text, 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_checked boolean; +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 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 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 = v_event_id; + if v_attendee is null then raise exception 'no attendee found for that QR code'; end if; + select checked_in into v_checked + from public.registrations + where event_id = v_event_id and contact_email = v_attendee; + update public.registrations set checked_in = true + where event_id = v_event_id and contact_email = v_attendee; + return query select v_attendee, v_name, coalesce(v_checked, false); +end; +$$; + +grant execute on function public.welcome_checkin(text) to authenticated; diff --git a/supabase/seed.sql b/supabase/seed.sql index d0d5587..c78b0b1 100644 --- a/supabase/seed.sql +++ b/supabase/seed.sql @@ -58,8 +58,8 @@ on conflict (id) do nothing; -- Staff (Bruno/Rita) keep their QR token as the auth password for the attendee app. insert into public.contacts (email, full_name, linkedin_url, show_email, show_linkedin, is_admin, password) values ('ana.silva@nubank.com', 'Ana Silva', 'https://linkedin.com/in/anasilva', true, true, false, null), - ('bruno.costa@acme.com', 'Bruno Costa', 'https://linkedin.com/in/brunocosta', false, true, true, null), - ('rita.lopes@globant.com', 'Rita Lopes', null, false, false, true, null), + ('bruno.costa@acme.com', 'Bruno Costa', 'https://linkedin.com/in/brunocosta', false, true, true, 'appe-admin-2026'), + ('rita.lopes@globant.com', 'Rita Lopes', null, false, false, true, 'appe-admin-2026'), ('tomas.ribeiro@dataprev.com','Tomás Ribeiro', null, false, false, false, null), ('sofia.almeida@loop.com', 'Sofia Almeida', null, false, false, false, null), ('marco.chen@deepmind.com', 'Marco Chen', null, false, false, false, null), @@ -85,19 +85,23 @@ on conflict (id) do nothing; -- (per event, generated by Pretix) and doubles as the auth password. -- Ana is checked in (has check-ins below). -- ----------------------------------------------------------------------------- +-- Note: everyone who speaks in a session is typed 'speaker' (the +-- session_speakers_speaker_promote trigger auto-promotes 'attendee' → 'speaker' +-- on insert, so the seed states the final type explicitly). Only Bruno, Rita and +-- the admin are 'staff' (the trigger never overrides an explicit staff/sponsor). insert into public.registrations (event_id, contact_email, type, checked_in, points, qr_token) values - ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'ana.silva@nubank.com', 'attendee', true, 40, 'CVV-ANA-4821'), + ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'ana.silva@nubank.com', 'speaker', true, 40, 'CVV-ANA-4821'), ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'bruno.costa@acme.com', 'staff', false, 140, 'CVV-BRU-1177'), ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'rita.lopes@globant.com', 'staff', false, 95, 'CVV-RIT-9034'), - ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'tomas.ribeiro@dataprev.com','attendee', false, 88, 'CVV-TOM-5566'), - ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'sofia.almeida@loop.com', 'attendee', false, 76, 'CVV-SOF-2299'), - ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'marco.chen@deepmind.com', 'attendee', false, 70, 'CVV-MRC-7712'), - ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'julia.santos@ifood.com', 'attendee', false, 64, 'CVV-JUL-3345'), - ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'pedro.nunes@microsoft.com', 'attendee', false, 58, 'CVV-PED-8801'), - ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'carla.mendes@quintoessencial.com', 'attendee', false, 52, 'CVV-CAR-6623'), - ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'diego.ferreira@stone.com', 'attendee', false, 35, 'CVV-DIE-4458'), - ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'marina.costa@olx.com', 'attendee', false, 28, 'CVV-MNA-2210'), - ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'lucas.oliveira@usp.br', 'attendee', false, 15, 'CVV-LUC-9987'), + ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'tomas.ribeiro@dataprev.com','speaker', false, 88, 'CVV-TOM-5566'), + ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'sofia.almeida@loop.com', 'speaker', false, 76, 'CVV-SOF-2299'), + ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'marco.chen@deepmind.com', 'speaker', false, 70, 'CVV-MRC-7712'), + ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'julia.santos@ifood.com', 'speaker', false, 64, 'CVV-JUL-3345'), + ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'pedro.nunes@microsoft.com', 'speaker', false, 58, 'CVV-PED-8801'), + ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'carla.mendes@quintoessencial.com', 'speaker', false, 52, 'CVV-CAR-6623'), + ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'diego.ferreira@stone.com', 'speaker', false, 35, 'CVV-DIE-4458'), + ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'marina.costa@olx.com', 'speaker', false, 28, 'CVV-MNA-2210'), + ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'lucas.oliveira@usp.br', 'speaker', false, 15, 'CVV-LUC-9987'), ('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'admin@appe.at', 'staff', false, 0, 'CVV-ADM-0001') on conflict (event_id, contact_email) do nothing;