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,186 @@
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { getAllCheckins, getAllConnections, getAllFeedback, getAllProfiles, getAllSessions } from '../lib/api';
|
||||
import type { Checkin, Connection, Feedback, Profile, Session } from '../lib/types';
|
||||
import { Avatar, Empty, Spinner } from '../components/ui';
|
||||
|
||||
type Tab = 'checkins' | 'connections' | 'feedback';
|
||||
|
||||
export function Activity() {
|
||||
const [profiles, setProfiles] = useState<Profile[] | null>(null);
|
||||
const [sessions, setSessions] = useState<Session[]>([]);
|
||||
const [checkins, setCheckins] = useState<Checkin[]>([]);
|
||||
const [connections, setConnections] = useState<Connection[]>([]);
|
||||
const [feedback, setFeedback] = useState<Feedback[]>([]);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [tab, setTab] = useState<Tab>('checkins');
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
(async () => {
|
||||
try {
|
||||
const [p, s, c, conn, f] = await Promise.all([
|
||||
getAllProfiles(),
|
||||
getAllSessions(),
|
||||
getAllCheckins(),
|
||||
getAllConnections(),
|
||||
getAllFeedback(),
|
||||
]);
|
||||
if (cancelled) return;
|
||||
setProfiles(p);
|
||||
setSessions(s);
|
||||
setCheckins(c);
|
||||
setConnections(conn);
|
||||
setFeedback(f);
|
||||
} catch (e) {
|
||||
if (!cancelled) setError(e instanceof Error ? e.message : 'Failed to load');
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, []);
|
||||
|
||||
const byId = useMemo(() => new Map((profiles ?? []).map((p) => [p.id, p])), [profiles]);
|
||||
const sessById = useMemo(() => new Map(sessions.map((s) => [s.id, s])), [sessions]);
|
||||
|
||||
if (error) return <Empty icon="⚠️" text={error} />;
|
||||
if (!profiles)
|
||||
return (
|
||||
<div className="loading-screen">
|
||||
<Spinner />
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="page-head">
|
||||
<div>
|
||||
<h1>Activity</h1>
|
||||
<div className="sub">Check-ins, connections, and feedback.</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="seg" style={{ maxWidth: 420, marginBottom: 18 }}>
|
||||
<button className={tab === 'checkins' ? 'active' : ''} onClick={() => setTab('checkins')}>
|
||||
Check-ins ({checkins.length})
|
||||
</button>
|
||||
<button className={tab === 'connections' ? 'active' : ''} onClick={() => setTab('connections')}>
|
||||
Connections ({connections.length})
|
||||
</button>
|
||||
<button className={tab === 'feedback' ? 'active' : ''} onClick={() => setTab('feedback')}>
|
||||
Feedback ({feedback.length})
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{tab === 'checkins' && (
|
||||
<div className="table-wrap">
|
||||
<table className="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Attendee</th>
|
||||
<th>Session</th>
|
||||
<th>Checked in by</th>
|
||||
<th>When</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{checkins.map((c) => (
|
||||
<tr key={c.id}>
|
||||
<td>
|
||||
<PersonCell p={byId.get(c.profile_id)} />
|
||||
</td>
|
||||
<td>{sessById.get(c.session_id)?.title ?? '—'}</td>
|
||||
<td className="muted small">{byId.get(c.staff_id)?.full_name ?? '—'}</td>
|
||||
<td className="muted small">{fmt(c.created_at)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
{checkins.length === 0 && <div style={{ padding: 16 }}><Empty icon="✅" text="No check-ins yet" /></div>}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{tab === 'connections' && (
|
||||
<div className="table-wrap">
|
||||
<table className="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>From</th>
|
||||
<th>To</th>
|
||||
<th>Status</th>
|
||||
<th>When</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{connections.map((c) => (
|
||||
<tr key={c.id}>
|
||||
<td>
|
||||
<PersonCell p={byId.get(c.from_id)} />
|
||||
</td>
|
||||
<td>
|
||||
<PersonCell p={byId.get(c.to_id)} />
|
||||
</td>
|
||||
<td>
|
||||
<span className={`pill ${c.status === 'accepted' ? 'green' : c.status === 'rejected' ? 'violet' : 'amber'}`}>
|
||||
{c.status}
|
||||
</span>
|
||||
</td>
|
||||
<td className="muted small">{fmt(c.resolved_at ?? c.created_at)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
{connections.length === 0 && <div style={{ padding: 16 }}><Empty icon="🤝" text="No connections yet" /></div>}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{tab === 'feedback' && (
|
||||
<div className="table-wrap">
|
||||
<table className="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Attendee</th>
|
||||
<th>Session</th>
|
||||
<th>Rating</th>
|
||||
<th>Comment</th>
|
||||
<th>When</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{feedback.map((f) => (
|
||||
<tr key={f.id}>
|
||||
<td>
|
||||
<PersonCell p={byId.get(f.profile_id)} />
|
||||
</td>
|
||||
<td>{sessById.get(f.session_id)?.title ?? '—'}</td>
|
||||
<td>
|
||||
<span className="pill amber">{'★'.repeat(f.rating)}</span>
|
||||
</td>
|
||||
<td className="muted small" style={{ maxWidth: 260 }}>
|
||||
{f.comment ?? '—'}
|
||||
</td>
|
||||
<td className="muted small">{fmt(f.created_at)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
{feedback.length === 0 && <div style={{ padding: 16 }}><Empty icon="⭐" text="No feedback yet" /></div>}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function PersonCell({ p }: { p: Profile | undefined }) {
|
||||
if (!p) return <span className="muted small">—</span>;
|
||||
return (
|
||||
<div className="cell-person">
|
||||
<Avatar name={p.full_name} id={p.id} size={32} fs={12} />
|
||||
<div className="n">{p.full_name}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function fmt(iso: string): string {
|
||||
return new Date(iso).toLocaleString([], { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' });
|
||||
}
|
||||
@@ -0,0 +1,332 @@
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { adjustPoints, getAllProfiles, resetQrToken, updateProfile } from '../lib/api';
|
||||
import type { Profile, Role } from '../lib/types';
|
||||
import { useToast } from '../context/ToastContext';
|
||||
import { Avatar, Empty, Modal, QrImage, RoleBadge, Spinner } from '../components/ui';
|
||||
|
||||
export function Attendees() {
|
||||
const { push } = useToast();
|
||||
const [profiles, setProfiles] = useState<Profile[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [query, setQuery] = useState('');
|
||||
|
||||
// Modal state
|
||||
const [editing, setEditing] = useState<Profile | null>(null);
|
||||
const [qrFor, setQrFor] = useState<Profile | null>(null);
|
||||
const [newToken, setNewToken] = useState<string | null>(null);
|
||||
const [pointsFor, setPointsFor] = useState<Profile | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
setProfiles(await getAllProfiles());
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : 'Failed to load');
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, []);
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
if (!profiles) return [];
|
||||
const q = query.trim().toLowerCase();
|
||||
if (!q) return profiles;
|
||||
return profiles.filter(
|
||||
(p) =>
|
||||
p.full_name.toLowerCase().includes(q) ||
|
||||
(p.company ?? '').toLowerCase().includes(q) ||
|
||||
p.email.toLowerCase().includes(q) ||
|
||||
(p.qr_token ?? '').toLowerCase().includes(q),
|
||||
);
|
||||
}, [profiles, query]);
|
||||
|
||||
async function doResetQr(p: Profile) {
|
||||
setBusy(true);
|
||||
try {
|
||||
const res = await resetQrToken(p.id);
|
||||
setNewToken(res.qr_token);
|
||||
setQrFor(p);
|
||||
// refresh the list so the token column updates
|
||||
await load();
|
||||
push('success', `New QR token issued for ${p.full_name}`);
|
||||
} catch (e) {
|
||||
push('error', e instanceof Error ? e.message : 'Reset failed');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (error) return <Empty icon="⚠️" text={error} />;
|
||||
if (!profiles)
|
||||
return (
|
||||
<div className="loading-screen">
|
||||
<Spinner />
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="page-head">
|
||||
<div>
|
||||
<h1>Attendees</h1>
|
||||
<div className="sub">{profiles.length} people · manage profiles, QR tokens, and points.</div>
|
||||
</div>
|
||||
<input
|
||||
className="input"
|
||||
style={{ maxWidth: 280 }}
|
||||
placeholder="Search name, company, email, token…"
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="table-wrap">
|
||||
<table className="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Role</th>
|
||||
<th>QR token</th>
|
||||
<th style={{ textAlign: 'right' }}>Points</th>
|
||||
<th style={{ textAlign: 'right' }}>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{filtered.map((p) => (
|
||||
<tr key={p.id}>
|
||||
<td>
|
||||
<div className="cell-person">
|
||||
<Avatar name={p.full_name} id={p.id} size={38} fs={13} />
|
||||
<div>
|
||||
<div className="n">{p.full_name}</div>
|
||||
<div className="e">{p.email}</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<RoleBadge role={p.role} />
|
||||
</td>
|
||||
<td>
|
||||
<span className="mono small">{p.qr_token ?? '—'}</span>
|
||||
</td>
|
||||
<td style={{ textAlign: 'right' }}>
|
||||
<span className="pts">{p.points}</span>
|
||||
</td>
|
||||
<td>
|
||||
<div className="row-actions">
|
||||
<button className="btn small" onClick={() => setEditing(p)}>
|
||||
Edit
|
||||
</button>
|
||||
<button className="btn small" onClick={() => { setNewToken(null); setQrFor(p); }}>
|
||||
QR
|
||||
</button>
|
||||
<button className="btn small" onClick={() => setPointsFor(p)}>
|
||||
Points
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
{filtered.length === 0 && <div style={{ padding: 16 }}><Empty icon="🔍" text="No matches" /></div>}
|
||||
</div>
|
||||
|
||||
{editing && (
|
||||
<EditProfileModal
|
||||
profile={editing}
|
||||
onClose={() => setEditing(null)}
|
||||
onSaved={async (msg) => {
|
||||
setEditing(null);
|
||||
await load();
|
||||
push('success', msg);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{qrFor && (
|
||||
<Modal
|
||||
open
|
||||
title={`QR — ${qrFor.full_name}`}
|
||||
onClose={() => setQrFor(null)}
|
||||
footer={
|
||||
<>
|
||||
<button
|
||||
className="btn danger"
|
||||
disabled={busy}
|
||||
onClick={() => doResetQr(qrFor)}
|
||||
>
|
||||
{busy ? 'Resetting…' : 'Reset token'}
|
||||
</button>
|
||||
<button className="btn primary" onClick={() => setQrFor(null)}>
|
||||
Done
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="qr-wrap">
|
||||
{newToken ? (
|
||||
<>
|
||||
<QrImage value={newToken} size={190} />
|
||||
<div className="token-big">{newToken}</div>
|
||||
<p className="muted small">
|
||||
New token issued. The old token no longer works — the attendee must re-scan.
|
||||
</p>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<QrImage value={qrFor.qr_token ?? ''} size={190} />
|
||||
<div className="token-big">{qrFor.qr_token ?? '—'}</div>
|
||||
<p className="muted small">Current token. Reset to issue a new one.</p>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</Modal>
|
||||
)}
|
||||
|
||||
{pointsFor && (
|
||||
<AdjustPointsModal
|
||||
profile={pointsFor}
|
||||
onClose={() => setPointsFor(null)}
|
||||
onSaved={async (msg) => {
|
||||
setPointsFor(null);
|
||||
await load();
|
||||
push('success', msg);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function EditProfileModal({
|
||||
profile,
|
||||
onClose,
|
||||
onSaved,
|
||||
}: {
|
||||
profile: Profile;
|
||||
onClose: () => void;
|
||||
onSaved: (msg: string) => void;
|
||||
}) {
|
||||
const [name, setName] = useState(profile.full_name);
|
||||
const [company, setCompany] = useState(profile.company ?? '');
|
||||
const [role, setRole] = useState<Role>(profile.role);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function save() {
|
||||
setBusy(true);
|
||||
try {
|
||||
await updateProfile(profile.id, {
|
||||
full_name: name.trim(),
|
||||
company: company.trim() || null,
|
||||
role,
|
||||
});
|
||||
onSaved(`Updated ${name.trim()}`);
|
||||
} catch (e) {
|
||||
onSaved(e instanceof Error ? e.message : 'Update failed');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open
|
||||
title={`Edit — ${profile.full_name}`}
|
||||
onClose={onClose}
|
||||
footer={
|
||||
<>
|
||||
<button className="btn" onClick={onClose}>
|
||||
Cancel
|
||||
</button>
|
||||
<button className="btn primary" disabled={busy || !name.trim()} onClick={save}>
|
||||
{busy ? 'Saving…' : 'Save'}
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="field">
|
||||
<label>Full name</label>
|
||||
<input className="input" value={name} onChange={(e) => setName(e.target.value)} />
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Company</label>
|
||||
<input className="input" value={company} onChange={(e) => setCompany(e.target.value)} placeholder="—" />
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Role</label>
|
||||
<select className="input" value={role} onChange={(e) => setRole(e.target.value as Role)}>
|
||||
<option value="attendee">attendee</option>
|
||||
<option value="staff">staff</option>
|
||||
<option value="admin">admin</option>
|
||||
</select>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
function AdjustPointsModal({
|
||||
profile,
|
||||
onClose,
|
||||
onSaved,
|
||||
}: {
|
||||
profile: Profile;
|
||||
onClose: () => void;
|
||||
onSaved: (msg: string) => void;
|
||||
}) {
|
||||
const [delta, setDelta] = useState('10');
|
||||
const [reason, setReason] = useState('');
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function save() {
|
||||
const d = parseInt(delta, 10);
|
||||
if (Number.isNaN(d) || d === 0) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await adjustPoints(profile.id, d, reason.trim() || 'manual adjustment');
|
||||
onSaved(`${d > 0 ? '+' : ''}${d} points for ${profile.full_name}`);
|
||||
} catch (e) {
|
||||
onSaved(e instanceof Error ? e.message : 'Adjustment failed');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open
|
||||
title={`Points — ${profile.full_name}`}
|
||||
onClose={onClose}
|
||||
footer={
|
||||
<>
|
||||
<button className="btn" onClick={onClose}>
|
||||
Cancel
|
||||
</button>
|
||||
<button className="btn primary" disabled={busy} onClick={save}>
|
||||
{busy ? 'Applying…' : 'Apply'}
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="row" style={{ justifyContent: 'center', gap: 16 }}>
|
||||
<Avatar name={profile.full_name} id={profile.id} size={52} fs={18} />
|
||||
<div>
|
||||
<div style={{ fontWeight: 700 }}>{profile.full_name}</div>
|
||||
<div className="muted small">
|
||||
Current: <span className="pts">{profile.points}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Adjustment (use a negative number to subtract)</label>
|
||||
<input className="input mono" type="number" value={delta} onChange={(e) => setDelta(e.target.value)} />
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Reason (optional)</label>
|
||||
<input className="input" value={reason} onChange={(e) => setReason(e.target.value)} placeholder="e.g. prize, correction" />
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -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