Files
Convivo/docs/frontend/admin-app.md
T
Lago 3adc0fd58f Post-event reporting + talk networking incentives
- Talk networking: per-event talk_networking_bonus awarded when two people
  who shared a checked-in talk accept a connection (accept_connection
  re-created, shared_talk flag, get_talk_cohort RPC, points_log category
  check widened); Convivo Networking sub-tab inside the Connect screen
  (Home quick action deep-links in; Connect button reflects existing
  connection state and is disabled for sent/connected/declined); admin
  Events view bonus input (0-10).
- Reports: sidecar POST /export (CSV / multi-sheet XLSX / PDF report via
  new pdfkit dep); APPE Admin Reports view (any event: on-screen summary,
  session feedback summary, top-5, CSV/Excel/PDF downloads); Activity
  session-feedback per-session aggregate header.
- Also carried: @appe.at admin trigger + default password, bulk contact
  delete, session level/area + event-level feedback, agenda level/area
  filters, admin password self-service, schedule level/area fields.
- 18/18 RPC tests; both apps build; exports verified end-to-end.
2026-09-21 22:34:25 +02:00

147 lines
8.7 KiB
Markdown

# Frontend — APPE Admin
The admin console is a **desktop-first single-page React app** in
[`apps/admin/`](../../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 — 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 a **type optionset** — `Session` / `Service Session`) + 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, toggle active/inactive (a switch; only one can be active at a time — activating one deactivates the rest), edit dates/location + the **Sessionize endpoint** + the **Real-time clock** toggle (on = the attendee app uses the real system clock for Live/Next/Done; off = the simulated mid-event clock, the default). Each row has a **Sync** button that runs a (blocking) Sessionize sync and shows a result modal. |
| **Interfaces** | Manages the Sessionize sync **sidecar**: status (online / running / last run), a **Run sync** control (event picker + blocking run + result modal), an **Import Excel** control (upload the Sessionize "Sessions and speakers (advanced)" `.xlsx` + a "How to get this file" tooltip), and a **Recent runs** table from `sync_runs`. See [../backend/sidecar.md](../backend/sidecar.md). |
## Auth guard
Login is **email + password** (`signInWithPassword({ email, password })`), 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 password is **event-independent** — it is the contact's Auth password
(`contacts.password` must match the bcrypt hash in `auth.users.encrypted_password`),
so the same admin can log in for any event. The seeded staff are
`[email protected]`, `[email protected]`, `[email protected]`, and `[email protected]`, all
with password `appe-admin-2026` (see [../backend/seed.md](../backend/seed.md)).
## 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 # email + password 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 (view) / checked-in + sponsor lookup
├─ Sponsors.tsx # sponsor CRUD
├─ Schedule.tsx # slots + sessions + speakers + material + AI-evaluate
├─ Activity.tsx # check-ins / connections / feedback tables
├─ Events.tsx # event management (+ sessionize_endpoint + per-row Sync + talk networking bonus)
├─ Interfaces.tsx # sidecar status / run / recent runs
└─ Reports.tsx # post-event summary + CSV / Excel / PDF export (sidecar /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](../backend/rls.md).
- **Writes** — direct `insert` / `update` / `delete` on `contacts`, `events`,
`registrations`, `sponsors`, `slots`, `sessions`, and `session_speakers`
(admin-only policies).
- **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). The
`reset_registration_qr_token` RPC still exists but the admin UI no longer
exposes a token reset. See
[../backend/rpcs.md](../backend/rpcs.md).
### 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. The token is **final** — it is generated
per event and can't be reset from the UI (the `reset_registration_qr_token` RPC
still exists, 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 either **link an existing sponsor** (a
dropdown lists the event's sponsors; picking one pre-fills the form) or **create
a new one** (type, name, email, phone, amount, paid). On save it upserts the
sponsor linked to that contact's email, then sets the registration type to
`sponsor` in one step.
### 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`.
### Reports (post-event summary + export)
The **Reports** view is the post-event reporting surface. It works for **any**
event (active or past) — the event selector defaults to the active event but can
pick a past one.
- **On-screen summary** — computed client-side from the same reads the export
uses: registrations (by type), check-ins, connections (total / accepted),
session feedback (count + average), event feedback (count + average), points by
category, and a top-5 leaderboard.
- **Session feedback summary** — a per-session table (title, room, average
rating, response count) sorted by average; this is the post-event session
feedback summary.
- **Export** — three buttons call the sidecar's [`POST /export`](../backend/sidecar.md#http-api):
**Download CSV**, **Download Excel**, **Download PDF report**. CSV/XLSX include
the tables ticked in the checkbox list (default: all); the PDF always uses the
full dataset. The response's base64 body is decoded and downloaded in the
browser (`downloadReport` in `lib/api.ts`).
## 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.