Files
Convivo/docs/frontend/admin-app.md
T
Lago b52d8ab007 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.
2026-08-23 10:39:21 +02:00

7.2 KiB
Raw Blame History

Frontend — APPE Admin

The admin console is a desktop-first single-page React app in apps/admin/, branded APPE Admin. It is a separate app from the attendee PWA (same stack, same Supabase core, same same-origin proxy pattern) and is guarded to the is_admin flag — anyone else who signs in is immediately signed out.

It runs on port 3001 (Vite dev) or as the convivo-admin Docker container (nginx). The attendee app stays on 3000.

What it does

View Purpose
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).
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).
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).

Auth guard

Login is the same QR + email flow as the attendee app (signInWithPassword({ email, password: qrToken })), but AuthContext checks the contact's is_admin flag after signing in:

  • If is_admin === true → the session is accepted and the console is shown.
  • Otherwise → the app calls signOut() and shows "This account is not an admin." The same check runs on session restore (page reload) and on every onAuthStateChange, so a non-admin can never see the console.

The demo admin is CVV-ADM-0001 / [email protected].

Source layout

apps/admin/src/
├─ main.tsx            # ReactDOM entry
├─ App.tsx             # Providers + Shell (sidebar nav + view switch)
├─ styles.css          # Desktop-first styling (same design tokens as the PWA)
├─ context/
│  ├─ AuthContext.tsx  # session + contact + is_admin guard
│  └─ ToastContext.tsx # transient toasts
├─ lib/
│  ├─ supabase.ts      # createClient (same-origin)
│  ├─ api.ts           # typed wrapper: reads + writes (contacts, registrations, sponsors, schedule, points)
│  └─ types.ts         # TS types mirroring the DB
├─ components/
│  └─ ui.tsx           # Avatar, Spinner, Empty, Modal, QrImage, TypeBadge, Toggle
├─ screens/
│  └─ Login.tsx        # QR + email login (admin-only)
└─ 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
   ├─ Sponsors.tsx     # sponsor CRUD
   ├─ Schedule.tsx     # slots + sessions + speakers + material + AI-evaluate
   ├─ Activity.tsx     # check-ins / connections / feedback tables
   ├─ Events.tsx       # event management
   └─ Sync.tsx         # Interfaces: Pretix/Sessionize sync + QR CSV export

Data access

The admin app uses the anon key + the admin's session JWT — no service-role key. Everything it can do is allowed by RLS:

  • Reads — admin-only select policies on contacts, registrations, sponsors, connections, feedback, checkins, points_log, plus the public events / slots / sessions / session_speakers / leaderboard. See ../backend/rls.md.
  • 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, create_registration, set_registration_type, evaluate_session_feedback (AI stub), and set_session_material (attach uploaded material). See ../backend/rpcs.md.

Resetting 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.

Adjusting points

adjust_points(contact_email, delta, reason) is the same transactional RPC the event uses, but the category is admin so manual adjustments are auditable in points_log. It keeps registrations.points and the leaderboard mirror in sync.

Session material

The Schedule view uploads a session's material to the materials bucket and sets sessions.material_path (admins can write sessions directly). The Evaluate button calls evaluate_session_feedback (the AI stub) to set ai_generated_feedback.

Interfaces (Pretix + Sessionize sync)

The Interfaces view is the admin's control panel for the data interfaces (Phases 7–8). It does not call the sync RPCs directly — those are service_role-only. Instead it POSTs to the sync-trigger Edge Function (/functions/v1/sync-trigger) with the admin's session JWT; the function verifies the caller is an admin (via the is_admin() RPC), fetches from the configured Pretix/Sessionize base URLs (the local mock API by default), and calls the service-role RPCs sync_pretix_attendees / sync_sessionize_sessions.

  • Sync now / Sync all — trigger one source or both; the response shows created / updated / skipped counts (and any per-item errors).
  • Recent sync runs — the last 8 rows of sync_runs (admin-only read).
  • Export QR CSV — builds a CSV of the active event's registrations (name, email, type, qr_token) and triggers a browser download, so organizers can print lanyards without touching the database.

Full details: ../backend/interfaces.md.

Styling

The admin app reuses the attendee app's design tokens (colors, Poppins font, card/pill/button styles) but is laid out desktop-first: a dark sidebar with the APPE / Admin brand + nav + admin identity, and a wide content area with stat cards and data tables. Below ~760px the sidebar collapses to a top bar so it still works on a phone.