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,332 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { supabase } from '../lib/supabase';
|
||||
import { getAllSessions, getAllSlots } from '../lib/api';
|
||||
import type { Session, Slot } from '../lib/types';
|
||||
import { useToast } from '../context/ToastContext';
|
||||
import { Empty, Modal, Spinner } from '../components/ui';
|
||||
|
||||
export function Schedule() {
|
||||
const { push } = useToast();
|
||||
const [slots, setSlots] = useState<Slot[] | null>(null);
|
||||
const [sessions, setSessions] = useState<Session[]>([]);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const [slotModal, setSlotModal] = useState<{ slot: Slot | null } | null>(null);
|
||||
const [sessModal, setSessModal] = useState<{ session: Session | null; slotId: number } | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
const [s, ss] = await Promise.all([getAllSlots(), getAllSessions()]);
|
||||
setSlots(s);
|
||||
setSessions(ss);
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : 'Failed to load');
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, []);
|
||||
|
||||
async function deleteSlot(slot: Slot) {
|
||||
if (!confirm(`Delete "${slot.name}" and all its sessions?`)) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
const { error: err } = await supabase.from('slots').delete().eq('id', slot.id);
|
||||
if (err) throw err;
|
||||
await load();
|
||||
push('success', `Deleted ${slot.name}`);
|
||||
} catch (e) {
|
||||
push('error', e instanceof Error ? e.message : 'Delete failed');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteSession(sess: Session) {
|
||||
if (!confirm(`Delete session "${sess.title}"?`)) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
const { error: err } = await supabase.from('sessions').delete().eq('id', sess.id);
|
||||
if (err) throw err;
|
||||
await load();
|
||||
push('success', `Deleted ${sess.title}`);
|
||||
} catch (e) {
|
||||
push('error', e instanceof Error ? e.message : 'Delete failed');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (error) return <Empty icon="⚠️" text={error} />;
|
||||
if (!slots)
|
||||
return (
|
||||
<div className="loading-screen">
|
||||
<Spinner />
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="page-head">
|
||||
<div>
|
||||
<h1>Schedule</h1>
|
||||
<div className="sub">{slots.length} slots · {sessions.length} sessions.</div>
|
||||
</div>
|
||||
<button className="btn primary" onClick={() => setSlotModal({ slot: null })}>
|
||||
+ New slot
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
|
||||
{slots.map((slot) => {
|
||||
const slotSessions = sessions.filter((s) => s.slot_id === slot.id);
|
||||
return (
|
||||
<div key={slot.id} className="card">
|
||||
<div className="row between" style={{ marginBottom: 12 }}>
|
||||
<div className="row" style={{ gap: 12 }}>
|
||||
<div>
|
||||
<div style={{ fontWeight: 800, fontSize: 16 }}>{slot.name}</div>
|
||||
<div className="muted small">
|
||||
{fmtDate(slot.slot_date)} · {fmtTime(slot.start_time)}–{fmtTime(slot.end_time)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="row-actions">
|
||||
<button className="btn small" onClick={() => setSessModal({ session: null, slotId: slot.id })}>
|
||||
+ Session
|
||||
</button>
|
||||
<button className="btn small" onClick={() => setSlotModal({ slot })}>
|
||||
Edit
|
||||
</button>
|
||||
<button className="btn small danger" disabled={busy} onClick={() => deleteSlot(slot)}>
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{slotSessions.length === 0 ? (
|
||||
<div className="muted small" style={{ padding: '4px 0' }}>
|
||||
No sessions in this slot.
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
||||
{slotSessions.map((s) => (
|
||||
<div key={s.id} className="row between" style={{ padding: '10px 12px', background: 'var(--surface-2)', borderRadius: 12 }}>
|
||||
<div style={{ minWidth: 0 }}>
|
||||
<div style={{ fontWeight: 700, fontSize: 14 }}>{s.title}</div>
|
||||
<div className="muted small">
|
||||
{[s.room, s.speakers, s.capacity ? `cap ${s.capacity}` : null].filter(Boolean).join(' · ') || '—'}
|
||||
</div>
|
||||
</div>
|
||||
<div className="row-actions">
|
||||
<button className="btn small" onClick={() => setSessModal({ session: s, slotId: slot.id })}>
|
||||
Edit
|
||||
</button>
|
||||
<button className="btn small danger" disabled={busy} onClick={() => deleteSession(s)}>
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{slotModal && (
|
||||
<SlotModal
|
||||
slot={slotModal.slot}
|
||||
onClose={() => setSlotModal(null)}
|
||||
onSaved={async (msg) => {
|
||||
setSlotModal(null);
|
||||
await load();
|
||||
push('success', msg);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{sessModal && (
|
||||
<SessionModal
|
||||
session={sessModal.session}
|
||||
slotId={sessModal.slotId}
|
||||
onClose={() => setSessModal(null)}
|
||||
onSaved={async (msg) => {
|
||||
setSessModal(null);
|
||||
await load();
|
||||
push('success', msg);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function SlotModal({
|
||||
slot,
|
||||
onClose,
|
||||
onSaved,
|
||||
}: {
|
||||
slot: Slot | null;
|
||||
onClose: () => void;
|
||||
onSaved: (msg: string) => void;
|
||||
}) {
|
||||
const [name, setName] = useState(slot?.name ?? '');
|
||||
const [date, setDate] = useState(slot ? slot.slot_date.slice(0, 10) : '');
|
||||
const [start, setStart] = useState(slot ? slot.start_time.slice(0, 5) : '09:00');
|
||||
const [end, setEnd] = useState(slot ? slot.end_time.slice(0, 5) : '10:00');
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function save() {
|
||||
if (!name.trim() || !date) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
const payload = { name: name.trim(), slot_date: date, start_time: start, end_time: end };
|
||||
if (slot) {
|
||||
const { error: err } = await supabase.from('slots').update(payload).eq('id', slot.id);
|
||||
if (err) throw err;
|
||||
} else {
|
||||
const { error: err } = await supabase.from('slots').insert(payload);
|
||||
if (err) throw err;
|
||||
}
|
||||
onSaved(slot ? 'Slot updated' : 'Slot created');
|
||||
} catch (e) {
|
||||
onSaved(e instanceof Error ? e.message : 'Save failed');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open
|
||||
title={slot ? 'Edit slot' : 'New slot'}
|
||||
onClose={onClose}
|
||||
footer={
|
||||
<>
|
||||
<button className="btn" onClick={onClose}>
|
||||
Cancel
|
||||
</button>
|
||||
<button className="btn primary" disabled={busy || !name.trim() || !date} onClick={save}>
|
||||
{busy ? 'Saving…' : 'Save'}
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="field">
|
||||
<label>Name</label>
|
||||
<input className="input" value={name} onChange={(e) => setName(e.target.value)} placeholder="e.g. Morning keynote" />
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Date</label>
|
||||
<input className="input" type="date" value={date} onChange={(e) => setDate(e.target.value)} />
|
||||
</div>
|
||||
<div className="grid-2">
|
||||
<div className="field">
|
||||
<label>Start</label>
|
||||
<input className="input" type="time" value={start} onChange={(e) => setStart(e.target.value)} />
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>End</label>
|
||||
<input className="input" type="time" value={end} onChange={(e) => setEnd(e.target.value)} />
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
function SessionModal({
|
||||
session,
|
||||
slotId,
|
||||
onClose,
|
||||
onSaved,
|
||||
}: {
|
||||
session: Session | null;
|
||||
slotId: number;
|
||||
onClose: () => void;
|
||||
onSaved: (msg: string) => void;
|
||||
}) {
|
||||
const [title, setTitle] = useState(session?.title ?? '');
|
||||
const [room, setRoom] = useState(session?.room ?? '');
|
||||
const [speakers, setSpeakers] = useState(session?.speakers ?? '');
|
||||
const [capacity, setCapacity] = useState(session?.capacity?.toString() ?? '');
|
||||
const [description, setDescription] = useState(session?.description ?? '');
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function save() {
|
||||
if (!title.trim()) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
const payload = {
|
||||
title: title.trim(),
|
||||
room: room.trim() || null,
|
||||
speakers: speakers.trim() || null,
|
||||
capacity: capacity ? parseInt(capacity, 10) : null,
|
||||
description: description.trim() || null,
|
||||
slot_id: slotId,
|
||||
};
|
||||
if (session) {
|
||||
const { error: err } = await supabase.from('sessions').update(payload).eq('id', session.id);
|
||||
if (err) throw err;
|
||||
} else {
|
||||
const { error: err } = await supabase.from('sessions').insert(payload);
|
||||
if (err) throw err;
|
||||
}
|
||||
onSaved(session ? 'Session updated' : 'Session created');
|
||||
} catch (e) {
|
||||
onSaved(e instanceof Error ? e.message : 'Save failed');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open
|
||||
title={session ? 'Edit session' : 'New session'}
|
||||
onClose={onClose}
|
||||
footer={
|
||||
<>
|
||||
<button className="btn" onClick={onClose}>
|
||||
Cancel
|
||||
</button>
|
||||
<button className="btn primary" disabled={busy || !title.trim()} onClick={save}>
|
||||
{busy ? 'Saving…' : 'Save'}
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="field">
|
||||
<label>Title</label>
|
||||
<input className="input" value={title} onChange={(e) => setTitle(e.target.value)} placeholder="e.g. The future of networking" />
|
||||
</div>
|
||||
<div className="grid-2">
|
||||
<div className="field">
|
||||
<label>Room</label>
|
||||
<input className="input" value={room} onChange={(e) => setRoom(e.target.value)} placeholder="—" />
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Capacity</label>
|
||||
<input className="input" type="number" value={capacity} onChange={(e) => setCapacity(e.target.value)} placeholder="—" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Speakers</label>
|
||||
<input className="input" value={speakers} onChange={(e) => setSpeakers(e.target.value)} placeholder="—" />
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Description</label>
|
||||
<textarea className="input" value={description} onChange={(e) => setDescription(e.target.value)} placeholder="—" />
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
function fmtDate(d: string): string {
|
||||
return new Date(d + 'T00:00:00').toLocaleDateString([], { weekday: 'short', month: 'short', day: 'numeric' });
|
||||
}
|
||||
function fmtTime(t: string): string {
|
||||
return t.slice(0, 5);
|
||||
}
|
||||
Reference in new issue
Block a user