Phase 0 + 1: Dockerized Supabase core + attendee PWA

Phase 0 — Supabase core (Docker via CLI):
- Schema: profiles, slots, sessions, preferences, connections, checkins,
  feedback, leaderboard (Realtime mirror), points_log
- RLS on every table; transactional security-definer points RPCs
- Seed: 6 slots, 18 sessions, 13 demo users (QR token as auth password)

Phase 1 — Attendee web PWA (React + Vite + TS):
- Login via QR token + email (GoTrue, no email sent)
- Home, Agenda, Scan/Connect, staff Check-in, Feedback, live Leaderboard, Profile
- Same-origin proxy to Supabase (Vite dev / nginx in Docker)
- Docker: multi-stage build -> nginx sidecar on the Supabase network

Co-authored-by: Stephan Charles <[email protected]>
Co-authored-by: Amelia Hernandez <[email protected]>
Co-authored-by: Markus Franz <[email protected]>
Co-authored-by: Sabrina Hota <[email protected]>
Co-authored-by: Nilüfer Doğan <[email protected]>
This commit is contained in:
45 files changed
+6922

No files matched your search

+129
View File
@@ -0,0 +1,129 @@
import { supabase } from './supabase';
import type {
AgendaRow,
CheckinResult,
Connection,
Feedback,
FeedbackResult,
LeaderboardRow,
PointsLogRow,
Preference,
PublicProfile,
Session,
Slot,
} from './types';
export class ApiError extends Error {}
async function rpc<T>(fn: string, args: Record<string, unknown>): Promise<T> {
const { data, error } = await supabase.rpc(fn, args);
if (error) throw new ApiError(error.message);
return data as T;
}
/** Resolve a scanned lanyard QR token to a public profile (pre-login + connect). */
export async function lanyardLookup(qrToken: string): Promise<PublicProfile | null> {
const rows = await rpc<PublicProfile[]>('lanyard_lookup', { p_qr_token: qrToken });
return rows && rows.length > 0 ? rows[0] : null;
}
export async function getPublicProfiles(): Promise<PublicProfile[]> {
return rpc<PublicProfile[]>('get_public_profiles', {});
}
export async function getAgenda(): Promise<AgendaRow[]> {
return rpc<AgendaRow[]>('get_agenda', {});
}
/** Group the flat agenda rows into slots with their sessions. */
export function groupAgenda(rows: AgendaRow[]): { slot: Slot; sessions: Session[] }[] {
const map = new Map<number, { slot: Slot; sessions: Session[] }>();
for (const r of rows) {
let entry = map.get(r.slot_id);
if (!entry) {
entry = {
slot: { id: r.slot_id, name: r.slot_name, slot_date: r.slot_date, start_time: r.start_time, end_time: r.end_time },
sessions: [],
};
map.set(r.slot_id, entry);
}
if (r.session_id && r.title) {
entry.sessions.push({
id: r.session_id,
title: r.title,
description: r.description,
slot_id: r.slot_id,
room: r.room,
capacity: r.capacity,
speakers: r.speakers,
});
}
}
return [...map.values()].sort((a, b) => a.slot.id - b.slot.id);
}
export async function getMyPreferences(): Promise<Preference[]> {
const { data, error } = await supabase.from('preferences').select('*').order('slot_id');
if (error) throw new ApiError(error.message);
return data as Preference[];
}
export async function setPreference(sessionId: string): Promise<void> {
await rpc('set_preference', { p_session_id: sessionId });
}
export async function clearPreference(slotId: number): Promise<void> {
await rpc('clear_preference', { p_slot_id: slotId });
}
export async function getMyConnections(): Promise<Connection[]> {
const { data, error } = await supabase.from('connections').select('*').order('created_at', { ascending: false });
if (error) throw new ApiError(error.message);
return data as Connection[];
}
export async function createConnectionRequest(targetQr: string): Promise<Connection> {
return rpc<Connection>('create_connection_request', { p_target_qr: targetQr });
}
export async function acceptConnection(id: string): Promise<Connection> {
return rpc<Connection>('accept_connection', { p_connection_id: id });
}
export async function rejectConnection(id: string): Promise<Connection> {
return rpc<Connection>('reject_connection', { p_connection_id: id });
}
export async function getMyCheckins(): Promise<string[]> {
const { data, error } = await supabase.from('checkins').select('session_id');
if (error) throw new ApiError(error.message);
return (data as { session_id: string }[]).map((c) => c.session_id);
}
export async function checkinAttendee(sessionId: string, attendeeQr: string): Promise<CheckinResult> {
const rows = await rpc<CheckinResult[]>('checkin_attendee', { p_session_id: sessionId, p_attendee_qr: attendeeQr });
return rows[0];
}
export async function getMyFeedback(): Promise<Feedback[]> {
const { data, error } = await supabase.from('feedback').select('*');
if (error) throw new ApiError(error.message);
return data as Feedback[];
}
export async function submitFeedback(sessionId: string, rating: number, comment: string): Promise<FeedbackResult> {
const rows = await rpc<FeedbackResult[]>('submit_feedback', { p_session_id: sessionId, p_rating: rating, p_comment: comment });
return rows[0];
}
export async function getLeaderboard(): Promise<LeaderboardRow[]> {
const { data, error } = await supabase.from('leaderboard').select('*').order('points', { ascending: false });
if (error) throw new ApiError(error.message);
return data as LeaderboardRow[];
}
export async function getMyPointsLog(): Promise<PointsLogRow[]> {
const { data, error } = await supabase.from('points_log').select('*').order('created_at', { ascending: false });
if (error) throw new ApiError(error.message);
return data as PointsLogRow[];
}
+23
View File
@@ -0,0 +1,23 @@
import { createClient } from '@supabase/supabase-js';
// The app talks to Supabase through same-origin paths (/auth, /rest, /realtime,
// /storage). In dev the Vite server proxies them to the local Supabase stack;
// in Docker the app's nginx does the same. This avoids CORS entirely.
const url = import.meta.env.VITE_SUPABASE_URL || window.location.origin;
const anonKey = import.meta.env.VITE_SUPABASE_ANON_KEY;
if (!anonKey) {
// Fail fast with a clear message if the anon key is missing.
console.warn('[convivo] VITE_SUPABASE_ANON_KEY is not set.');
}
export const supabase = createClient(url, anonKey, {
auth: {
persistSession: true,
autoRefreshToken: true,
detectSessionInUrl: false,
},
realtime: {
params: { eventsPerSecond: 10 },
},
});
+43
View File
@@ -0,0 +1,43 @@
import type { Slot } from './types';
/** The event day (from the seed). All slot times are on this date. */
export const EVENT_DATE = '2026-10-23';
/** Simulated "now" used for the demo (matches the mockup: 10:20 on event day). */
export const DEFAULT_NOW = new Date(`${EVENT_DATE}T10:20:00`);
export type SlotStatus = 'done' | 'now' | 'next';
function at(dateStr: string, time: string): Date {
return new Date(`${dateStr}T${time}`);
}
export function slotStart(slot: Slot): Date {
return at(slot.slot_date, slot.start_time);
}
export function slotEnd(slot: Slot): Date {
return at(slot.slot_date, slot.end_time);
}
export function slotStatus(slot: Slot, now: Date): SlotStatus {
if (now >= slotEnd(slot)) return 'done';
if (now >= slotStart(slot)) return 'now';
return 'next';
}
/** "09:00" from "09:00:00". */
export function fmtTime(time: string): string {
return time.slice(0, 5);
}
export function fmtRange(slot: Slot): string {
return `${fmtTime(slot.start_time)}–${fmtTime(slot.end_time)}`;
}
export function greeting(now: Date): string {
const h = now.getHours();
if (h < 12) return 'Good morning';
if (h < 18) return 'Good afternoon';
return 'Good evening';
}
+119
View File
@@ -0,0 +1,119 @@
export type Role = 'attendee' | 'staff' | 'admin';
export interface Profile {
id: string;
email: string;
full_name: string;
company: string | null;
role: Role;
qr_token: string | null;
points: number;
created_at: string;
}
/** Public projection of a profile (no email / qr_token). */
export interface PublicProfile {
id: string;
full_name: string;
company: string | null;
role: Role;
points: number;
}
export interface Slot {
id: number;
name: string;
slot_date: string;
start_time: string;
end_time: string;
}
export interface Session {
id: string;
title: string;
description: string | null;
slot_id: number;
room: string | null;
capacity: number | null;
speakers: string | null;
}
/** Row shape returned by the get_agenda() RPC (slots with nested sessions). */
export interface AgendaRow {
slot_id: number;
slot_name: string;
slot_date: string;
start_time: string;
end_time: string;
session_id: string | null;
title: string | null;
description: string | null;
room: string | null;
capacity: number | null;
speakers: string | null;
}
export interface Preference {
id: string;
profile_id: string;
session_id: string;
slot_id: number;
}
export type ConnectionStatus = 'pending' | 'accepted' | 'rejected';
export interface Connection {
id: string;
from_id: string;
to_id: string;
status: ConnectionStatus;
created_at: string;
resolved_at: string | null;
}
export interface Checkin {
id: string;
profile_id: string;
session_id: string;
staff_id: string;
created_at: string;
}
export interface Feedback {
id: string;
profile_id: string;
session_id: string;
rating: number;
comment: string | null;
created_at: string;
}
export interface LeaderboardRow {
profile_id: string;
full_name: string;
company: string | null;
points: number;
updated_at: string;
}
export interface PointsLogRow {
id: string;
profile_id: string;
delta: number;
category: 'checkin' | 'connection' | 'feedback' | 'admin';
created_at: string;
}
export interface CheckinResult {
checkin_id: string;
attendee_id: string;
attendee_name: string;
points: number;
already: boolean;
}
export interface FeedbackResult {
feedback_id: string;
points: number;
earned: number;
}
+47
View File
@@ -0,0 +1,47 @@
import { useEffect, useState } from 'react';
import { getAgenda, groupAgenda } from './api';
import { DEFAULT_NOW } from './time';
import type { Session, Slot } from './types';
export interface EventData {
slots: { slot: Slot; sessions: Session[] }[];
sessionById: Map<string, Session>;
slotById: Map<number, Slot>;
now: Date;
loading: boolean;
error: string | null;
}
/** Loads the agenda once and exposes it grouped by slot, plus the event clock. */
export function useEvent(): EventData {
const [slots, setSlots] = useState<{ slot: Slot; sessions: Session[] }[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
let active = true;
(async () => {
try {
const rows = await getAgenda();
if (!active) return;
setSlots(groupAgenda(rows));
} catch (e) {
if (active) setError(e instanceof Error ? e.message : 'Failed to load agenda');
} finally {
if (active) setLoading(false);
}
})();
return () => {
active = false;
};
}, []);
const sessionById = new Map<string, Session>();
const slotById = new Map<number, Slot>();
for (const { slot, sessions } of slots) {
slotById.set(slot.id, slot);
for (const s of sessions) sessionById.set(s.id, s);
}
return { slots, sessionById, slotById, now: DEFAULT_NOW, loading, error };
}