Phase 2: Admin console (admin.appe.at)
A desktop-first React app for organizers, guarded to the admin role. Backend (supabase/migrations/20260823000000_admin_app.sql): - Admin-only SELECT policies on preferences, connections, feedback - reset_qr_token RPC: regenerates a lanyard token, re-hashes it as the Auth password (old token stops working), and clears the attendee's sessions to force re-login App (apps/admin, port 3001): - Login: same QR+email flow, but non-admin sessions are rejected - Dashboard: live stats + top points + recent activity - Attendees: search, edit name/company/role, reset QR, adjust points - Schedule: manage slots + sessions (create/edit/delete) - Activity: check-ins / connections / feedback tables - Same-origin proxy (Vite dev / nginx in Docker), same design tokens Docker + scripts: - convivo-admin service in docker-compose.yml (:3001) - admin:dev / admin:build root scripts - fixed db:reset script (supabase reset -> supabase db reset) Docs: new frontend/admin-app.md; updated architecture, rls, rpcs, docker, next-steps, and READMEs. Verified: build clean, all views + flows browser-tested, Docker build + proxy + login + admin guard confirmed. DB reset to clean seed. 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
015c0a3a06
commit
32c86767ef
45 files changed
+4425
-87
No files matched your search
@@ -0,0 +1,61 @@
|
||||
import { supabase } from './supabase';
|
||||
import type {
|
||||
Checkin,
|
||||
Connection,
|
||||
Feedback,
|
||||
LeaderboardRow,
|
||||
PointsLogRow,
|
||||
Profile,
|
||||
ResetQrResult,
|
||||
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;
|
||||
}
|
||||
|
||||
async function all<T>(table: string, order?: { col: string; asc?: boolean }): Promise<T[]> {
|
||||
let q = supabase.from(table).select('*');
|
||||
if (order) q = q.order(order.col, { ascending: order.asc ?? true });
|
||||
const { data, error } = await q;
|
||||
if (error) throw new ApiError(error.message);
|
||||
return data as T[];
|
||||
}
|
||||
|
||||
// ---- 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 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) ----------------------------------------------------
|
||||
|
||||
/** 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'] },
|
||||
): Promise<void> {
|
||||
const { error } = await supabase.from('profiles').update(patch).eq('id', id);
|
||||
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 });
|
||||
return rows[0];
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
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) {
|
||||
console.warn('[convivo-admin] VITE_SUPABASE_ANON_KEY is not set.');
|
||||
}
|
||||
|
||||
export const supabase = createClient(url, anonKey, {
|
||||
auth: {
|
||||
persistSession: true,
|
||||
autoRefreshToken: true,
|
||||
detectSessionInUrl: false,
|
||||
},
|
||||
realtime: {
|
||||
params: { eventsPerSecond: 10 },
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,80 @@
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
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 ResetQrResult {
|
||||
profile_id: string;
|
||||
qr_token: string;
|
||||
}
|
||||
Reference in new issue
Block a user