- 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
242 lines
7.9 KiB
TypeScript
242 lines
7.9 KiB
TypeScript
import { useEffect, useMemo, useState } from 'react';
|
||
import {
|
||
getAllCheckins,
|
||
getAllConnections,
|
||
getAllContacts,
|
||
getAllFeedback,
|
||
getActiveEvent,
|
||
getLeaderboard,
|
||
} from '../lib/api';
|
||
import type { Checkin, Connection, Contact, Event, Feedback, LeaderboardRow } from '../lib/types';
|
||
import { Avatar, Empty, Spinner } from '../components/ui';
|
||
import type { View } from '../App';
|
||
|
||
export function Dashboard({ onNavigate }: { onNavigate: (v: View) => void }) {
|
||
const [event, setEvent] = useState<Event | null>(null);
|
||
const [loaded, setLoaded] = useState(false);
|
||
const [contacts, setContacts] = useState<Contact[]>([]);
|
||
const [checkins, setCheckins] = useState<Checkin[]>([]);
|
||
const [connections, setConnections] = useState<Connection[]>([]);
|
||
const [feedback, setFeedback] = useState<Feedback[]>([]);
|
||
const [lb, setLb] = useState<LeaderboardRow[]>([]);
|
||
const [error, setError] = useState<string | null>(null);
|
||
|
||
useEffect(() => {
|
||
let cancelled = false;
|
||
(async () => {
|
||
try {
|
||
const ev = await getActiveEvent();
|
||
if (cancelled) return;
|
||
setEvent(ev);
|
||
if (!ev) {
|
||
setLoaded(true);
|
||
return;
|
||
}
|
||
const [c, ck, conn, f, l] = await Promise.all([
|
||
getAllContacts(),
|
||
getAllCheckins(),
|
||
getAllConnections(),
|
||
getAllFeedback(),
|
||
getLeaderboard(),
|
||
]);
|
||
if (cancelled) return;
|
||
setContacts(c);
|
||
setCheckins(ck.filter((x) => x.event_id === ev.id));
|
||
setConnections(conn.filter((x) => x.event_id === ev.id));
|
||
setFeedback(f.filter((x) => x.event_id === ev.id));
|
||
setLb(l.filter((x) => x.event_id === ev.id));
|
||
setLoaded(true);
|
||
} catch (e) {
|
||
if (!cancelled) setError(e instanceof Error ? e.message : 'Failed to load');
|
||
}
|
||
})();
|
||
return () => {
|
||
cancelled = true;
|
||
};
|
||
}, []);
|
||
|
||
const nameOf = useMemo(() => {
|
||
const m = new Map(contacts.map((c) => [c.email, c.full_name]));
|
||
return (email: string) => m.get(email) ?? email;
|
||
}, [contacts]);
|
||
|
||
if (error) return <Empty icon="⚠️" text={error} />;
|
||
if (!loaded)
|
||
return (
|
||
<div className="loading-screen">
|
||
<Spinner />
|
||
</div>
|
||
);
|
||
|
||
if (!event) {
|
||
return (
|
||
<div>
|
||
<div className="page-head">
|
||
<div>
|
||
<h1>Dashboard</h1>
|
||
<div className="sub">Live overview of the event.</div>
|
||
</div>
|
||
</div>
|
||
<div className="card">
|
||
<Empty icon="📅" text="No active event. Create one and set it active in the Events view." />
|
||
<div style={{ textAlign: 'center', marginTop: 12 }}>
|
||
<button className="btn primary" onClick={() => onNavigate('events')}>
|
||
Go to Events →
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
const top = lb.slice(0, 5);
|
||
|
||
return (
|
||
<div>
|
||
<div className="page-head">
|
||
<div>
|
||
<h1>Dashboard</h1>
|
||
<div className="sub">Live overview of the active event.</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="card event-card">
|
||
<div className="row between" style={{ flexWrap: 'wrap', gap: 12 }}>
|
||
<div>
|
||
<div className="event-name">{event.name}</div>
|
||
<div className="muted small">
|
||
{fmtDate(event.start_date)}
|
||
{event.end_date !== event.start_date ? ` – ${fmtDate(event.end_date)}` : ''}
|
||
{event.location ? ` · ${event.location}` : ''}
|
||
</div>
|
||
</div>
|
||
<span className="pill green">● Active</span>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="stat-grid">
|
||
<div className="stat">
|
||
<span className="ico">🎟️</span>
|
||
<span className="val">{event.num_registrations}</span>
|
||
<span className="lbl">Registrations</span>
|
||
</div>
|
||
<div className="stat">
|
||
<span className="ico">✅</span>
|
||
<span className="val">{event.num_checked_in_registrations}</span>
|
||
<span className="lbl">Checked in</span>
|
||
</div>
|
||
<div className="stat">
|
||
<span className="ico">🗓️</span>
|
||
<span className="val">{event.num_sessions}</span>
|
||
<span className="lbl">Sessions</span>
|
||
</div>
|
||
<div className="stat">
|
||
<span className="ico">🎤</span>
|
||
<span className="val">{event.num_speakers}</span>
|
||
<span className="lbl">Speakers</span>
|
||
</div>
|
||
<div className="stat accent">
|
||
<span className="ico">⭐</span>
|
||
<span className="val">{event.avg_feedback != null ? event.avg_feedback.toFixed(1) : '—'}</span>
|
||
<span className="lbl">Avg. feedback</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('registrations')}>
|
||
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.contact_email} className="row" style={{ gap: 12 }}>
|
||
<span style={{ width: 22, fontWeight: 900, color: 'var(--muted)' }}>{i + 1}</span>
|
||
<Avatar name={r.full_name} id={r.contact_email} size={36} fs={13} />
|
||
<div className="grow">
|
||
<div style={{ fontWeight: 700, fontSize: 14 }}>{r.full_name}</div>
|
||
<div className="muted small">{r.contact_email}</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} nameOf={nameOf} limit={6} />
|
||
</div>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function ActivityFeed({
|
||
checkins,
|
||
connections,
|
||
feedback,
|
||
nameOf,
|
||
limit,
|
||
}: {
|
||
checkins: Checkin[];
|
||
connections: Connection[];
|
||
feedback: Feedback[];
|
||
nameOf: (email: string) => string;
|
||
limit: number;
|
||
}) {
|
||
type Item = { at: string; icon: string; text: string };
|
||
const name = (email: string) => nameOf(email);
|
||
const items: Item[] = [
|
||
...checkins.map((c) => ({
|
||
at: c.created_at,
|
||
icon: '✅',
|
||
text: `${name(c.contact_email)} checked in`,
|
||
})),
|
||
...connections
|
||
.filter((c) => c.status === 'accepted')
|
||
.map((c) => ({
|
||
at: c.resolved_at ?? c.created_at,
|
||
icon: '🤝',
|
||
text: `${name(c.from_email)} connected with ${name(c.to_email)}`,
|
||
})),
|
||
...feedback.map((f) => ({
|
||
at: f.created_at,
|
||
icon: '⭐',
|
||
text: `${name(f.contact_email)} 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>
|
||
);
|
||
}
|
||
|
||
function fmtDate(d: string): string {
|
||
return new Date(d + 'T00:00:00').toLocaleDateString([], { weekday: 'short', month: 'short', day: 'numeric' });
|
||
}
|