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
This commit is contained in:
1 parent
5adb5785aa
commit
22f5f1d317
64 files changed
+4593
-1371
No files matched your search
+165
-18
@@ -2,13 +2,17 @@ import { supabase } from './supabase';
|
||||
import type {
|
||||
Checkin,
|
||||
Connection,
|
||||
Contact,
|
||||
Event,
|
||||
Feedback,
|
||||
LeaderboardRow,
|
||||
PointsLogRow,
|
||||
Profile,
|
||||
Registration,
|
||||
ResetQrResult,
|
||||
Session,
|
||||
SessionSpeaker,
|
||||
Slot,
|
||||
Sponsor,
|
||||
} from './types';
|
||||
|
||||
export class ApiError extends Error {}
|
||||
@@ -29,33 +33,176 @@ async function all<T>(table: string, order?: { col: string; asc?: boolean }): Pr
|
||||
|
||||
// ---- Reads (admin can read all rows via RLS) --------------------------------
|
||||
|
||||
export const getAllProfiles = () => all<Profile>('profiles', { col: 'points', asc: false });
|
||||
export const getAllSlots = () => all<Slot>('slots', { col: 'id' });
|
||||
export const getAllSessions = () => all<Session>('sessions', { col: 'slot_id' });
|
||||
export const getAllContacts = () => all<Contact>('contacts', { col: 'full_name' });
|
||||
export const getAllEvents = () => all<Event>('events', { col: 'start_date', asc: false });
|
||||
export const getActiveEvent = async (): 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 const getRegistrations = (eventId: string) =>
|
||||
all<Registration>('registrations', { col: 'points', asc: false }).then((rows) =>
|
||||
rows.filter((r) => r.event_id === eventId),
|
||||
);
|
||||
export const getSponsors = (eventId: string) =>
|
||||
all<Sponsor>('sponsors', { col: 'name' }).then((rows) => rows.filter((s) => s.event_id === eventId));
|
||||
export const getSlots = (eventId: string) =>
|
||||
all<Slot>('slots', { col: 'id' }).then((rows) => rows.filter((s) => s.event_id === eventId));
|
||||
export const getSessions = (eventId: string) =>
|
||||
all<Session>('sessions', { col: 'slot_id' }).then((rows) => rows.filter((s) => s.event_id === eventId));
|
||||
// session_speakers has no event_id; callers filter by the event's session ids.
|
||||
export const getAllSessionSpeakers = () => all<SessionSpeaker>('session_speakers');
|
||||
export const getAllConnections = () => all<Connection>('connections', { col: 'created_at', asc: false });
|
||||
export const getAllCheckins = () => all<Checkin>('checkins', { col: 'created_at', asc: false });
|
||||
export const getAllFeedback = () => all<Feedback>('feedback', { col: 'created_at', asc: false });
|
||||
export const getAllPointsLog = () => all<PointsLogRow>('points_log', { col: 'created_at', asc: false });
|
||||
export const getLeaderboard = () => all<LeaderboardRow>('leaderboard', { col: 'points', asc: false });
|
||||
|
||||
// ---- Writes (admin only) ----------------------------------------------------
|
||||
// ---- Contacts ----------------------------------------------------------------
|
||||
|
||||
/** Update an attendee's editable fields (name, company, role). */
|
||||
export async function updateProfile(
|
||||
id: string,
|
||||
patch: { full_name?: string; company?: string | null; role?: Profile['role'] },
|
||||
export async function upsertContact(input: {
|
||||
email: string;
|
||||
full_name: string;
|
||||
linkedin_url?: string | null;
|
||||
is_admin?: boolean;
|
||||
qr_token?: string | null;
|
||||
}): Promise<Contact> {
|
||||
// upsert_contact returns a single composite row (a JSON object, not an array).
|
||||
return await rpc<Contact>('upsert_contact', {
|
||||
p_email: input.email,
|
||||
p_full_name: input.full_name,
|
||||
p_linkedin_url: input.linkedin_url ?? null,
|
||||
p_is_admin: input.is_admin ?? false,
|
||||
p_qr_token: input.qr_token ?? null,
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateContact(
|
||||
email: string,
|
||||
patch: Partial<Pick<Contact, 'full_name' | 'linkedin_url' | 'show_email' | 'show_linkedin' | 'is_admin'>>,
|
||||
): Promise<void> {
|
||||
const { error } = await supabase.from('profiles').update(patch).eq('id', id);
|
||||
const { error } = await supabase.from('contacts').update(patch).eq('email', email);
|
||||
if (error) throw new ApiError(error.message);
|
||||
}
|
||||
|
||||
/** Admin manual points adjustment (audited as 'admin'). */
|
||||
export async function adjustPoints(profileId: string, delta: number, reason: string): Promise<void> {
|
||||
await rpc('adjust_points', { p_profile_id: profileId, p_delta: delta, p_reason: reason });
|
||||
}
|
||||
|
||||
/** Regenerate an attendee's QR token (syncs the auth password, forces re-login). */
|
||||
export async function resetQrToken(profileId: string): Promise<ResetQrResult> {
|
||||
const rows = await rpc<ResetQrResult[]>('reset_qr_token', { p_profile_id: profileId });
|
||||
/** Regenerate a contact's QR token (syncs the auth password, forces re-login). */
|
||||
export async function resetQrToken(email: string): Promise<ResetQrResult> {
|
||||
const rows = await rpc<ResetQrResult[]>('reset_qr_token', { p_contact_email: email });
|
||||
return rows[0];
|
||||
}
|
||||
|
||||
// ---- Registrations -----------------------------------------------------------
|
||||
|
||||
export async function createRegistration(contactEmail: string, type: Registration['type']): Promise<void> {
|
||||
await rpc('create_registration', { p_contact_email: contactEmail, p_type: type });
|
||||
}
|
||||
|
||||
export async function setRegistrationType(contactEmail: string, type: Registration['type']): Promise<void> {
|
||||
await rpc('set_registration_type', { p_contact_email: contactEmail, p_type: type });
|
||||
}
|
||||
|
||||
export async function setCheckedIn(registrationId: string, checkedIn: boolean): Promise<void> {
|
||||
const { error } = await supabase.from('registrations').update({ checked_in: checkedIn }).eq('id', registrationId);
|
||||
if (error) throw new ApiError(error.message);
|
||||
}
|
||||
|
||||
// ---- Sponsors ----------------------------------------------------------------
|
||||
|
||||
export async function upsertSponsor(
|
||||
id: string | null,
|
||||
input: {
|
||||
event_id: string;
|
||||
type: Sponsor['type'];
|
||||
name: string;
|
||||
email?: string | null;
|
||||
phone?: string | null;
|
||||
paid?: boolean;
|
||||
amount_eur?: number | null;
|
||||
contact_email?: string | null;
|
||||
},
|
||||
): Promise<void> {
|
||||
if (id) {
|
||||
const { error } = await supabase.from('sponsors').update(input).eq('id', id);
|
||||
if (error) throw new ApiError(error.message);
|
||||
} else {
|
||||
const { error } = await supabase.from('sponsors').insert(input);
|
||||
if (error) throw new ApiError(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteSponsor(id: string): Promise<void> {
|
||||
const { error } = await supabase.from('sponsors').delete().eq('id', id);
|
||||
if (error) throw new ApiError(error.message);
|
||||
}
|
||||
|
||||
// ---- Events ------------------------------------------------------------------
|
||||
|
||||
export async function upsertEvent(
|
||||
id: string | null,
|
||||
input: { name: string; start_date: string; end_date: string; location?: string | null },
|
||||
): Promise<void> {
|
||||
if (id) {
|
||||
const { error } = await supabase.from('events').update(input).eq('id', id);
|
||||
if (error) throw new ApiError(error.message);
|
||||
} else {
|
||||
const { error } = await supabase.from('events').insert(input);
|
||||
if (error) throw new ApiError(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
/** Set an event active (deactivates all others via trigger). */
|
||||
export async function activateEvent(id: string): Promise<void> {
|
||||
const { error } = await supabase.from('events').update({ is_active: true }).eq('id', id);
|
||||
if (error) throw new ApiError(error.message);
|
||||
}
|
||||
|
||||
// ---- Points ------------------------------------------------------------------
|
||||
|
||||
/** Admin manual points adjustment for the active event (audited as 'admin'). */
|
||||
export async function adjustPoints(contactEmail: string, delta: number, reason: string): Promise<void> {
|
||||
await rpc('adjust_points', { p_contact_email: contactEmail, p_delta: delta, p_reason: reason });
|
||||
}
|
||||
|
||||
// ---- Sessions: speakers, material, AI feedback -------------------------------
|
||||
|
||||
export async function setSessionSpeakers(sessionId: string, emails: string[]): Promise<void> {
|
||||
// Replace the speaker set: delete all, then insert the new set.
|
||||
const { error: delErr } = await supabase.from('session_speakers').delete().eq('session_id', sessionId);
|
||||
if (delErr) throw new ApiError(delErr.message);
|
||||
if (emails.length > 0) {
|
||||
const rows = emails.map((contact_email) => ({ session_id: sessionId, contact_email }));
|
||||
const { error: insErr } = await supabase.from('session_speakers').insert(rows);
|
||||
if (insErr) throw new ApiError(insErr.message);
|
||||
}
|
||||
}
|
||||
|
||||
/** Upload a session material file to the `materials` bucket and store the path. */
|
||||
export async function uploadSessionMaterial(sessionId: string, file: File): Promise<string> {
|
||||
const path = `sessions/${sessionId}/${Date.now()}-${file.name}`;
|
||||
const { error } = await supabase.storage.from('materials').upload(path, file, { upsert: true });
|
||||
if (error) throw new ApiError(error.message);
|
||||
const { error: upErr } = await supabase.from('sessions').update({ material_path: path }).eq('id', sessionId);
|
||||
if (upErr) throw new ApiError(upErr.message);
|
||||
return path;
|
||||
}
|
||||
|
||||
export async function removeSessionMaterial(sessionId: string): Promise<void> {
|
||||
const { data } = await supabase.from('sessions').select('material_path').eq('id', sessionId).maybeSingle();
|
||||
const path = (data as Session | null)?.material_path;
|
||||
if (path) {
|
||||
await supabase.storage.from('materials').remove([path]);
|
||||
}
|
||||
const { error } = await supabase.from('sessions').update({ material_path: null }).eq('id', sessionId);
|
||||
if (error) throw new ApiError(error.message);
|
||||
}
|
||||
|
||||
export function sessionMaterialUrl(path: string): string {
|
||||
const { data } = supabase.storage.from('materials').getPublicUrl(path);
|
||||
return data.publicUrl;
|
||||
}
|
||||
|
||||
/** Trigger the (stub) AI feedback evaluation for a session. */
|
||||
export async function evaluateSessionFeedback(sessionId: string): Promise<Session> {
|
||||
// evaluate_session_feedback returns a single composite row (a JSON object, not an array).
|
||||
return await rpc<Session>('evaluate_session_feedback', { p_session_id: sessionId });
|
||||
}
|
||||
+80
-16
@@ -1,18 +1,70 @@
|
||||
export type Role = 'attendee' | 'staff' | 'admin';
|
||||
export type RegistrationType = 'attendee' | 'speaker' | 'staff' | 'sponsor';
|
||||
|
||||
export interface Profile {
|
||||
id: string;
|
||||
export type SponsorType =
|
||||
| 'headline'
|
||||
| 'platinum'
|
||||
| 'gold'
|
||||
| 'silver'
|
||||
| 'community'
|
||||
| 'swag'
|
||||
| 'catering'
|
||||
| 'diversity';
|
||||
|
||||
export type SlotType = 'session' | 'lunch_break' | 'coffee_break' | 'keynote' | 'close_up';
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
export interface Event {
|
||||
id: string;
|
||||
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 Registration {
|
||||
id: string;
|
||||
event_id: string;
|
||||
contact_email: string;
|
||||
type: RegistrationType;
|
||||
checked_in: boolean;
|
||||
points: number;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface Sponsor {
|
||||
id: string;
|
||||
event_id: string;
|
||||
type: SponsorType;
|
||||
name: string;
|
||||
email: string | null;
|
||||
phone: string | null;
|
||||
paid: boolean;
|
||||
amount_eur: number | null;
|
||||
contact_email: string | null;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface Slot {
|
||||
id: number;
|
||||
event_id: string;
|
||||
type: SlotType;
|
||||
name: string;
|
||||
slot_date: string;
|
||||
start_time: string;
|
||||
@@ -21,21 +73,30 @@ 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;
|
||||
speakers: string | null;
|
||||
average_feedback: number | null;
|
||||
ai_generated_feedback: string | null;
|
||||
material_path: string | null;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface SessionSpeaker {
|
||||
session_id: string;
|
||||
contact_email: string;
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -43,15 +104,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;
|
||||
@@ -59,22 +122,23 @@ 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;
|
||||
}
|
||||
|
||||
export interface ResetQrResult {
|
||||
profile_id: string;
|
||||
email: string;
|
||||
qr_token: string;
|
||||
}
|
||||
Reference in new issue
Block a user