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.
This commit is contained in:
Lago committed 2026-08-22 19:47:22 +02:00
1 parent 0cbfb25714
commit cf70f39903
45 files changed
+4425 -87

No files matched your search

+196
View File
@@ -0,0 +1,196 @@
import { useEffect, useState } from 'react';
import {
getAllCheckins,
getAllConnections,
getAllFeedback,
getAllProfiles,
getAllSessions,
getLeaderboard,
} from '../lib/api';
import type { Checkin, Connection, Feedback, LeaderboardRow, Profile, Session } from '../lib/types';
import { Avatar, Empty, Spinner } from '../components/ui';
type View = 'dashboard' | 'attendees' | 'schedule' | 'activity';
export function Dashboard({ onNavigate }: { onNavigate: (v: View) => void }) {
const [profiles, setProfiles] = useState<Profile[] | null>(null);
const [checkins, setCheckins] = useState<Checkin[]>([]);
const [connections, setConnections] = useState<Connection[]>([]);
const [feedback, setFeedback] = useState<Feedback[]>([]);
const [sessions, setSessions] = useState<Session[]>([]);
const [lb, setLb] = useState<LeaderboardRow[]>([]);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
let cancelled = false;
(async () => {
try {
const [p, c, conn, f, s, l] = await Promise.all([
getAllProfiles(),
getAllCheckins(),
getAllConnections(),
getAllFeedback(),
getAllSessions(),
getLeaderboard(),
]);
if (cancelled) return;
setProfiles(p);
setCheckins(c);
setConnections(conn);
setFeedback(f);
setSessions(s);
setLb(l);
} catch (e) {
if (!cancelled) setError(e instanceof Error ? e.message : 'Failed to load');
}
})();
return () => {
cancelled = true;
};
}, []);
if (error) return <Empty icon="⚠️" text={error} />;
if (!profiles)
return (
<div className="loading-screen">
<Spinner />
</div>
);
const attendees = profiles.filter((p) => p.role === 'attendee');
const accepted = connections.filter((c) => c.status === 'accepted').length;
const avgRating = feedback.length
? (feedback.reduce((s, f) => s + f.rating, 0) / feedback.length).toFixed(1)
: '—';
const top = lb.slice(0, 5);
return (
<div>
<div className="page-head">
<div>
<h1>Dashboard</h1>
<div className="sub">Live overview of the event.</div>
</div>
</div>
<div className="stat-grid">
<div className="stat">
<span className="ico">👥</span>
<span className="val">{attendees.length}</span>
<span className="lbl">Attendees</span>
</div>
<div className="stat">
<span className="ico">✅</span>
<span className="val">{checkins.length}</span>
<span className="lbl">Check-ins</span>
</div>
<div className="stat">
<span className="ico">🤝</span>
<span className="val">{accepted}</span>
<span className="lbl">Connections accepted</span>
</div>
<div className="stat">
<span className="ico">⭐</span>
<span className="val">{avgRating}</span>
<span className="lbl">Avg. session rating</span>
</div>
<div className="stat accent">
<span className="ico">🏆</span>
<span className="val">{sessions.length}</span>
<span className="lbl">Sessions scheduled</span>
</div>
</div>
<div className="grid-2">
<div className="card">
<div className="row between" style={{ marginBottom: 14 }}>
<h2 className="h2">🏆 Top points</h2>
<button className="btn small ghost" onClick={() => onNavigate('attendees')}>
View all →
</button>
</div>
{top.length === 0 ? (
<Empty icon="🏆" text="No points yet" />
) : (
<div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
{top.map((r, i) => (
<div key={r.profile_id} className="row" style={{ gap: 12 }}>
<span style={{ width: 22, fontWeight: 900, color: 'var(--muted)' }}>{i + 1}</span>
<Avatar name={r.full_name} id={r.profile_id} size={36} fs={13} />
<div className="grow">
<div style={{ fontWeight: 700, fontSize: 14 }}>{r.full_name}</div>
{r.company && <div className="muted small">{r.company}</div>}
</div>
<span className="pts">{r.points}</span>
</div>
))}
</div>
)}
</div>
<div className="card">
<div className="row between" style={{ marginBottom: 14 }}>
<h2 className="h2">⚡ Recent activity</h2>
<button className="btn small ghost" onClick={() => onNavigate('activity')}>
View all →
</button>
</div>
<ActivityFeed checkins={checkins} connections={connections} feedback={feedback} profiles={profiles} limit={6} />
</div>
</div>
</div>
);
}
function ActivityFeed({
checkins,
connections,
feedback,
profiles,
limit,
}: {
checkins: Checkin[];
connections: Connection[];
feedback: Feedback[];
profiles: Profile[];
limit: number;
}) {
const byId = new Map(profiles.map((p) => [p.id, p]));
type Item = { at: string; icon: string; text: string };
const items: Item[] = [
...checkins.map((c) => ({
at: c.created_at,
icon: '✅',
text: `${byId.get(c.profile_id)?.full_name ?? 'Someone'} checked in`,
})),
...connections
.filter((c) => c.status === 'accepted')
.map((c) => ({
at: c.resolved_at ?? c.created_at,
icon: '🤝',
text: `${byId.get(c.from_id)?.full_name ?? 'Someone'} connected with ${byId.get(c.to_id)?.full_name ?? 'someone'}`,
})),
...feedback.map((f) => ({
at: f.created_at,
icon: '⭐',
text: `${byId.get(f.profile_id)?.full_name ?? 'Someone'} rated a session ${f.rating}★`,
})),
]
.sort((a, b) => (a.at < b.at ? 1 : -1))
.slice(0, limit);
if (items.length === 0) return <Empty icon="⚡" text="No activity yet" />;
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
{items.map((it, i) => (
<div key={i} className="row" style={{ gap: 10 }}>
<span style={{ fontSize: 18 }}>{it.icon}</span>
<div className="grow" style={{ fontSize: 13.5 }}>
{it.text}
</div>
<span className="muted small">{new Date(it.at).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}</span>
</div>
))}
</div>
);
}