Redesign Phases 3-6: multi-event model, APPE Admin, Convivo App behaviors, APPE branding
- Phase 3: new migration 20260824000000_redesign.sql (contacts/events/registrations/sponsors, slot types, session speakers + feedback/material), seed rewrite - Phase 4: APPE Admin rebrand + Contacts/Registrations/Sponsors/Schedule/Activity/Events views - Phase 5: Convivo App (24h login, 5s polling, QR type badge, red dot, speaker material) - Phase 6: APPE favicon + PWA icons for both apps - Docs: schema/rpcs/rls/seed/screens/api-client/admin-app/architecture/next-steps/README/roadmap updated 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:
1 parent
2f53d47578
commit
7605c9bbf4
64 files changed
+4593
-1371
No files matched your search
+89
-17
@@ -3,12 +3,15 @@ import type {
|
||||
AgendaRow,
|
||||
CheckinResult,
|
||||
Connection,
|
||||
Contact,
|
||||
Event,
|
||||
Feedback,
|
||||
FeedbackResult,
|
||||
LeaderboardRow,
|
||||
PointsLogRow,
|
||||
Preference,
|
||||
PublicProfile,
|
||||
PublicContact,
|
||||
Registration,
|
||||
Session,
|
||||
Slot,
|
||||
} from './types';
|
||||
@@ -21,14 +24,15 @@ async function rpc<T>(fn: string, args: Record<string, unknown>): Promise<T> {
|
||||
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 });
|
||||
/** Resolve a scanned lanyard QR token to public contact info (pre-login + connect). */
|
||||
export async function lanyardLookup(qrToken: string): Promise<PublicContact | null> {
|
||||
const rows = await rpc<PublicContact[]>('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', {});
|
||||
/** Public directory of contacts registered for the active event (for connection names). */
|
||||
export async function getPublicContacts(): Promise<PublicContact[]> {
|
||||
return rpc<PublicContact[]>('get_public_contacts', {});
|
||||
}
|
||||
|
||||
export async function getAgenda(): Promise<AgendaRow[]> {
|
||||
@@ -42,7 +46,15 @@ export function groupAgenda(rows: AgendaRow[]): { slot: Slot; sessions: Session[
|
||||
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 },
|
||||
slot: {
|
||||
id: r.slot_id,
|
||||
event_id: '',
|
||||
type: r.slot_type,
|
||||
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);
|
||||
@@ -50,18 +62,43 @@ export function groupAgenda(rows: AgendaRow[]): { slot: Slot; sessions: Session[
|
||||
if (r.session_id && r.title) {
|
||||
entry.sessions.push({
|
||||
id: r.session_id,
|
||||
event_id: '',
|
||||
slot_id: r.slot_id,
|
||||
title: r.title,
|
||||
description: r.description,
|
||||
slot_id: r.slot_id,
|
||||
room: r.room,
|
||||
capacity: r.capacity,
|
||||
average_feedback: r.average_feedback,
|
||||
ai_generated_feedback: r.ai_generated_feedback,
|
||||
material_path: r.material_path,
|
||||
speakers: r.speakers,
|
||||
created_at: '',
|
||||
});
|
||||
}
|
||||
}
|
||||
return [...map.values()].sort((a, b) => a.slot.id - b.slot.id);
|
||||
}
|
||||
|
||||
/** The signed-in contact's own row (filter by email — admins can see all rows). */
|
||||
export async function getMyContact(email: string): Promise<Contact | null> {
|
||||
const { data, error } = await supabase.from('contacts').select('*').eq('email', email).maybeSingle();
|
||||
if (error) throw new ApiError(error.message);
|
||||
return (data as Contact) ?? null;
|
||||
}
|
||||
|
||||
/** The signed-in contact's registration for the active event. */
|
||||
export async function getMyRegistration(email: string): Promise<Registration | null> {
|
||||
const { data, error } = await supabase.from('registrations').select('*').eq('contact_email', email).maybeSingle();
|
||||
if (error) throw new ApiError(error.message);
|
||||
return (data as Registration) ?? null;
|
||||
}
|
||||
|
||||
export async function getActiveEvent(): Promise<Event | null> {
|
||||
const { data, error } = await supabase.from('events').select('*').eq('is_active', true).maybeSingle();
|
||||
if (error) throw new ApiError(error.message);
|
||||
return (data as Event) ?? null;
|
||||
}
|
||||
|
||||
export async function getMyPreferences(): Promise<Preference[]> {
|
||||
const { data, error } = await supabase.from('preferences').select('*').order('slot_id');
|
||||
if (error) throw new ApiError(error.message);
|
||||
@@ -83,6 +120,7 @@ export async function getMyConnections(): Promise<Connection[]> {
|
||||
}
|
||||
|
||||
export async function createConnectionRequest(targetQr: string): Promise<Connection> {
|
||||
// create_connection_request returns a single composite row (a JSON object).
|
||||
return rpc<Connection>('create_connection_request', { p_target_qr: targetQr });
|
||||
}
|
||||
|
||||
@@ -94,8 +132,9 @@ 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');
|
||||
/** Session ids the signed-in contact is checked into. */
|
||||
export async function getMyCheckins(email: string): Promise<string[]> {
|
||||
const { data, error } = await supabase.from('checkins').select('session_id').eq('contact_email', email);
|
||||
if (error) throw new ApiError(error.message);
|
||||
return (data as { session_id: string }[]).map((c) => c.session_id);
|
||||
}
|
||||
@@ -105,8 +144,8 @@ export async function checkinAttendee(sessionId: string, attendeeQr: string): Pr
|
||||
return rows[0];
|
||||
}
|
||||
|
||||
export async function getMyFeedback(): Promise<Feedback[]> {
|
||||
const { data, error } = await supabase.from('feedback').select('*');
|
||||
export async function getMyFeedback(email: string): Promise<Feedback[]> {
|
||||
const { data, error } = await supabase.from('feedback').select('*').eq('contact_email', email);
|
||||
if (error) throw new ApiError(error.message);
|
||||
return data as Feedback[];
|
||||
}
|
||||
@@ -117,13 +156,46 @@ export async function submitFeedback(sessionId: string, rating: number, comment:
|
||||
}
|
||||
|
||||
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[];
|
||||
return rpc<LeaderboardRow[]>('get_leaderboard', {});
|
||||
}
|
||||
|
||||
export async function getMyPointsLog(): Promise<PointsLogRow[]> {
|
||||
const { data, error } = await supabase.from('points_log').select('*').order('created_at', { ascending: false });
|
||||
export async function getMyPointsLog(email: string): Promise<PointsLogRow[]> {
|
||||
const { data, error } = await supabase
|
||||
.from('points_log')
|
||||
.select('*')
|
||||
.eq('contact_email', email)
|
||||
.order('created_at', { ascending: false });
|
||||
if (error) throw new ApiError(error.message);
|
||||
return data as PointsLogRow[];
|
||||
}
|
||||
|
||||
/** Public URL for a session material stored in the `materials` bucket. */
|
||||
export function sessionMaterialUrl(path: string): string {
|
||||
const { data } = supabase.storage.from('materials').getPublicUrl(path);
|
||||
return data.publicUrl;
|
||||
}
|
||||
|
||||
/** Session ids the signed-in contact is a speaker of (for material upload). */
|
||||
export async function getMySpeakerSessions(email: string): Promise<string[]> {
|
||||
const { data, error } = await supabase
|
||||
.from('session_speakers')
|
||||
.select('session_id')
|
||||
.eq('contact_email', email);
|
||||
if (error) throw new ApiError(error.message);
|
||||
return (data as { session_id: string }[]).map((s) => s.session_id);
|
||||
}
|
||||
|
||||
/** Upload a session material file to the `materials` bucket and set material_path.
|
||||
* The path is persisted via the `set_session_material` RPC (the sessions table
|
||||
* is admin-write only, so speakers need the security-definer RPC). */
|
||||
export async function uploadSessionMaterial(sessionId: string, file: File): Promise<string> {
|
||||
const path = `sessions/${sessionId}/${Date.now()}-${file.name.replace(/[^a-zA-Z0-9._-]/g, '_')}`;
|
||||
const { error: upErr } = await supabase.storage.from('materials').upload(path, file, { upsert: true });
|
||||
if (upErr) throw new ApiError(upErr.message);
|
||||
const { error: dbErr } = await supabase.rpc('set_session_material', {
|
||||
p_session_id: sessionId,
|
||||
p_material_path: path,
|
||||
});
|
||||
if (dbErr) throw new ApiError(dbErr.message);
|
||||
return path;
|
||||
}
|
||||
@@ -1,27 +1,49 @@
|
||||
export type Role = 'attendee' | 'staff' | 'admin';
|
||||
export type RegistrationType = 'attendee' | 'speaker' | 'staff' | 'sponsor';
|
||||
|
||||
export interface Profile {
|
||||
id: string;
|
||||
export type SlotType = 'session' | 'lunch_break' | 'coffee_break' | 'keynote' | 'close_up';
|
||||
|
||||
/** The signed-in contact (own row, readable via RLS). */
|
||||
export interface Contact {
|
||||
email: string;
|
||||
full_name: string;
|
||||
company: string | null;
|
||||
role: Role;
|
||||
linkedin_url: string | null;
|
||||
show_email: boolean;
|
||||
show_linkedin: boolean;
|
||||
is_admin: boolean;
|
||||
qr_token: string | null;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
/** The signed-in contact's registration for the active event. */
|
||||
export interface Registration {
|
||||
id: string;
|
||||
event_id: string;
|
||||
contact_email: string;
|
||||
type: RegistrationType;
|
||||
checked_in: boolean;
|
||||
points: number;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
/** Public projection of a profile (no email / qr_token). */
|
||||
export interface PublicProfile {
|
||||
export interface Event {
|
||||
id: string;
|
||||
full_name: string;
|
||||
company: string | null;
|
||||
role: Role;
|
||||
points: number;
|
||||
name: string;
|
||||
start_date: string;
|
||||
end_date: string;
|
||||
location: string | null;
|
||||
is_active: boolean;
|
||||
avg_feedback: number | null;
|
||||
num_sessions: number;
|
||||
num_speakers: number;
|
||||
num_registrations: number;
|
||||
num_checked_in_registrations: number;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface Slot {
|
||||
id: number;
|
||||
event_id: string;
|
||||
type: SlotType;
|
||||
name: string;
|
||||
slot_date: string;
|
||||
start_time: string;
|
||||
@@ -30,12 +52,18 @@ export interface Slot {
|
||||
|
||||
export interface Session {
|
||||
id: string;
|
||||
event_id: string;
|
||||
slot_id: number;
|
||||
title: string;
|
||||
description: string | null;
|
||||
slot_id: number;
|
||||
room: string | null;
|
||||
capacity: number | null;
|
||||
average_feedback: number | null;
|
||||
ai_generated_feedback: string | null;
|
||||
material_path: string | null;
|
||||
/** Comma-separated speaker names (from the get_agenda RPC). */
|
||||
speakers: string | null;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
/** Row shape returned by the get_agenda() RPC (slots with nested sessions). */
|
||||
@@ -45,17 +73,22 @@ export interface AgendaRow {
|
||||
slot_date: string;
|
||||
start_time: string;
|
||||
end_time: string;
|
||||
slot_type: SlotType;
|
||||
session_id: string | null;
|
||||
title: string | null;
|
||||
description: string | null;
|
||||
room: string | null;
|
||||
capacity: number | null;
|
||||
average_feedback: number | null;
|
||||
ai_generated_feedback: string | null;
|
||||
material_path: string | null;
|
||||
speakers: string | null;
|
||||
}
|
||||
|
||||
export interface Preference {
|
||||
id: string;
|
||||
profile_id: string;
|
||||
event_id: string;
|
||||
contact_email: string;
|
||||
session_id: string;
|
||||
slot_id: number;
|
||||
}
|
||||
@@ -64,8 +97,9 @@ export type ConnectionStatus = 'pending' | 'accepted' | 'rejected';
|
||||
|
||||
export interface Connection {
|
||||
id: string;
|
||||
from_id: string;
|
||||
to_id: string;
|
||||
event_id: string;
|
||||
from_email: string;
|
||||
to_email: string;
|
||||
status: ConnectionStatus;
|
||||
created_at: string;
|
||||
resolved_at: string | null;
|
||||
@@ -73,15 +107,17 @@ export interface Connection {
|
||||
|
||||
export interface Checkin {
|
||||
id: string;
|
||||
profile_id: string;
|
||||
event_id: string;
|
||||
contact_email: string;
|
||||
session_id: string;
|
||||
staff_id: string;
|
||||
staff_email: string;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface Feedback {
|
||||
id: string;
|
||||
profile_id: string;
|
||||
event_id: string;
|
||||
contact_email: string;
|
||||
session_id: string;
|
||||
rating: number;
|
||||
comment: string | null;
|
||||
@@ -89,24 +125,33 @@ export interface Feedback {
|
||||
}
|
||||
|
||||
export interface LeaderboardRow {
|
||||
profile_id: string;
|
||||
event_id: string;
|
||||
contact_email: string;
|
||||
full_name: string;
|
||||
company: string | null;
|
||||
points: number;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface PointsLogRow {
|
||||
id: string;
|
||||
profile_id: string;
|
||||
event_id: string;
|
||||
contact_email: string;
|
||||
delta: number;
|
||||
category: 'checkin' | 'connection' | 'feedback' | 'admin';
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
/** Public projection of a contact (visibility toggles respected). */
|
||||
export interface PublicContact {
|
||||
email: string;
|
||||
full_name: string;
|
||||
linkedin_url: string | null;
|
||||
show_email: boolean;
|
||||
registration_type: RegistrationType | null;
|
||||
}
|
||||
|
||||
export interface CheckinResult {
|
||||
checkin_id: string;
|
||||
attendee_id: string;
|
||||
attendee_email: string;
|
||||
attendee_name: string;
|
||||
points: number;
|
||||
already: boolean;
|
||||
|
||||
@@ -1,29 +1,34 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { getAgenda, groupAgenda } from './api';
|
||||
import { getActiveEvent, getAgenda, groupAgenda } from './api';
|
||||
import { DEFAULT_NOW } from './time';
|
||||
import type { Session, Slot } from './types';
|
||||
import type { Event, Session, Slot } from './types';
|
||||
|
||||
export interface EventData {
|
||||
event: Event | null;
|
||||
slots: { slot: Slot; sessions: Session[] }[];
|
||||
sessionById: Map<string, Session>;
|
||||
slotById: Map<number, Slot>;
|
||||
now: Date;
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
reload: () => void;
|
||||
}
|
||||
|
||||
/** Loads the agenda once and exposes it grouped by slot, plus the event clock. */
|
||||
/** Loads the active event + agenda, exposes them grouped by slot, plus the event clock. */
|
||||
export function useEvent(): EventData {
|
||||
const [event, setEvent] = useState<Event | null>(null);
|
||||
const [slots, setSlots] = useState<{ slot: Slot; sessions: Session[] }[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [nonce, setNonce] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
(async () => {
|
||||
try {
|
||||
const rows = await getAgenda();
|
||||
const [ev, rows] = await Promise.all([getActiveEvent(), getAgenda()]);
|
||||
if (!active) return;
|
||||
setEvent(ev);
|
||||
setSlots(groupAgenda(rows));
|
||||
} catch (e) {
|
||||
if (active) setError(e instanceof Error ? e.message : 'Failed to load agenda');
|
||||
@@ -34,7 +39,7 @@ export function useEvent(): EventData {
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
}, []);
|
||||
}, [nonce]);
|
||||
|
||||
const sessionById = new Map<string, Session>();
|
||||
const slotById = new Map<number, Slot>();
|
||||
@@ -43,5 +48,14 @@ export function useEvent(): EventData {
|
||||
for (const s of sessions) sessionById.set(s.id, s);
|
||||
}
|
||||
|
||||
return { slots, sessionById, slotById, now: DEFAULT_NOW, loading, error };
|
||||
return {
|
||||
event,
|
||||
slots,
|
||||
sessionById,
|
||||
slotById,
|
||||
now: DEFAULT_NOW,
|
||||
loading,
|
||||
error,
|
||||
reload: () => setNonce((n) => n + 1),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
|
||||
/**
|
||||
* Runs `fn` every `ms` milliseconds, but ONLY while the tab is visible
|
||||
* (document.visibilityState === 'visible'). Also re-runs immediately when the
|
||||
* tab becomes visible again. No background polling.
|
||||
*/
|
||||
export function usePolling(fn: () => void, ms: number, enabled = true): void {
|
||||
const saved = useRef(fn);
|
||||
saved.current = fn;
|
||||
|
||||
useEffect(() => {
|
||||
if (!enabled) return;
|
||||
let timer: number | undefined;
|
||||
|
||||
const tick = () => {
|
||||
if (document.visibilityState === 'visible') saved.current();
|
||||
};
|
||||
|
||||
timer = window.setInterval(tick, ms);
|
||||
const onVis = () => {
|
||||
if (document.visibilityState === 'visible') tick();
|
||||
};
|
||||
document.addEventListener('visibilitychange', onVis);
|
||||
|
||||
return () => {
|
||||
if (timer !== undefined) window.clearInterval(timer);
|
||||
document.removeEventListener('visibilitychange', onVis);
|
||||
};
|
||||
}, [ms, enabled]);
|
||||
}
|
||||
Reference in new issue
Block a user