Post-event reporting + talk networking incentives
- Talk networking: per-event talk_networking_bonus awarded when two people who shared a checked-in talk accept a connection (accept_connection re-created, shared_talk flag, get_talk_cohort RPC, points_log category check widened); Convivo Networking sub-tab inside the Connect screen (Home quick action deep-links in; Connect button reflects existing connection state and is disabled for sent/connected/declined); admin Events view bonus input (0-10). - Reports: sidecar POST /export (CSV / multi-sheet XLSX / PDF report via new pdfkit dep); APPE Admin Reports view (any event: on-screen summary, session feedback summary, top-5, CSV/Excel/PDF downloads); Activity session-feedback per-session aggregate header. - Also carried: @appe.at admin trigger + default password, bulk contact delete, session level/area + event-level feedback, agenda level/area filters, admin password self-service, schedule level/area fields. - 18/18 RPC tests; both apps build; exports verified end-to-end.
This commit is contained in:
1 parent
08ab41898b
commit
3adc0fd58f
35 files changed
+3973
-54
No files matched your search
+101
-4
@@ -1,6 +1,6 @@
|
||||
import { useState } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { AuthProvider, useAuth } from './context/AuthContext';
|
||||
import { ToastProvider } from './context/ToastContext';
|
||||
import { ToastProvider, useToast } from './context/ToastContext';
|
||||
import { Login } from './screens/Login';
|
||||
import { Dashboard } from './views/Dashboard';
|
||||
import { Contacts } from './views/Contacts';
|
||||
@@ -10,7 +10,9 @@ import { Schedule } from './views/Schedule';
|
||||
import { Activity } from './views/Activity';
|
||||
import { Events } from './views/Events';
|
||||
import { Interfaces } from './views/Interfaces';
|
||||
import { Spinner } from './components/ui';
|
||||
import { Reports } from './views/Reports';
|
||||
import { Spinner, Modal } from './components/ui';
|
||||
import { DEFAULT_ADMIN_PASSWORD } from './lib/api';
|
||||
|
||||
export type View =
|
||||
| 'dashboard'
|
||||
@@ -20,7 +22,8 @@ export type View =
|
||||
| 'schedule'
|
||||
| 'activity'
|
||||
| 'events'
|
||||
| 'interfaces';
|
||||
| 'interfaces'
|
||||
| 'reports';
|
||||
|
||||
const NAV: { id: View; label: string; ico: string }[] = [
|
||||
{ id: 'dashboard', label: 'Dashboard', ico: '📊' },
|
||||
@@ -31,8 +34,100 @@ const NAV: { id: View; label: string; ico: string }[] = [
|
||||
{ id: 'activity', label: 'Activity', ico: '⚡' },
|
||||
{ id: 'events', label: 'Events', ico: '📅' },
|
||||
{ id: 'interfaces', label: 'Interfaces', ico: '🔌' },
|
||||
{ id: 'reports', label: 'Reports', ico: '📤' },
|
||||
];
|
||||
|
||||
/**
|
||||
* Shown once per session when an admin signs in with the default password
|
||||
* (`appe-admin-2026`). Prompts them to set a personal password. Dismissable
|
||||
* ("Not now"); the prompt re-appears on the next sign-in while the default is
|
||||
* in use.
|
||||
*/
|
||||
function ChangePasswordPrompt() {
|
||||
const { contact, changePassword } = useAuth();
|
||||
const { push } = useToast();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [newPassword, setNewPassword] = useState('');
|
||||
const [confirmPassword, setConfirmPassword] = useState('');
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
// Open the prompt when the signed-in admin is using the default password.
|
||||
useEffect(() => {
|
||||
if (contact && contact.password === DEFAULT_ADMIN_PASSWORD) setOpen(true);
|
||||
}, [contact]);
|
||||
|
||||
async function onSubmit() {
|
||||
if (newPassword.length < 6) {
|
||||
setError('Password must be at least 6 characters.');
|
||||
return;
|
||||
}
|
||||
if (newPassword !== confirmPassword) {
|
||||
setError('Passwords do not match.');
|
||||
return;
|
||||
}
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
await changePassword(newPassword);
|
||||
push('success', 'Password updated');
|
||||
setOpen(false);
|
||||
setNewPassword('');
|
||||
setConfirmPassword('');
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to change password');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open={open}
|
||||
onClose={() => setOpen(false)}
|
||||
title="Change your password"
|
||||
footer={
|
||||
<>
|
||||
<button className="btn ghost" onClick={() => setOpen(false)}>
|
||||
Not now
|
||||
</button>
|
||||
<button className="btn primary" onClick={onSubmit} disabled={busy}>
|
||||
{busy ? 'Saving…' : 'Save password'}
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<p style={{ margin: 0, fontSize: 13.5, color: 'var(--muted)' }}>
|
||||
You signed in with the default admin password. Set a personal password
|
||||
so only you can access this account.
|
||||
</p>
|
||||
<div className="field">
|
||||
<label>New password</label>
|
||||
<input
|
||||
className="input"
|
||||
type="password"
|
||||
placeholder="••••••••••"
|
||||
value={newPassword}
|
||||
onChange={(e) => setNewPassword(e.target.value)}
|
||||
autoComplete="new-password"
|
||||
/>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Confirm new password</label>
|
||||
<input
|
||||
className="input"
|
||||
type="password"
|
||||
placeholder="••••••••••"
|
||||
value={confirmPassword}
|
||||
onChange={(e) => setConfirmPassword(e.target.value)}
|
||||
autoComplete="new-password"
|
||||
/>
|
||||
</div>
|
||||
{error && <div className="login-err">{error}</div>}
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
function Shell() {
|
||||
const { contact, loading, signOut } = useAuth();
|
||||
const [view, setView] = useState<View>('dashboard');
|
||||
@@ -49,6 +144,7 @@ function Shell() {
|
||||
|
||||
return (
|
||||
<div className="app">
|
||||
<ChangePasswordPrompt />
|
||||
<aside className="sidebar">
|
||||
<div className="brand">
|
||||
<div className="logo"><img src="/icon-192.png" alt="APPE" /></div>
|
||||
@@ -99,6 +195,7 @@ function Shell() {
|
||||
{view === 'activity' && <Activity />}
|
||||
{view === 'events' && <Events />}
|
||||
{view === 'interfaces' && <Interfaces />}
|
||||
{view === 'reports' && <Reports />}
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { createContext, useContext, useEffect, useState, type ReactNode } from 'react';
|
||||
import { supabase } from '../lib/supabase';
|
||||
import { changeMyPassword } from '../lib/api';
|
||||
import type { Contact } from '../lib/types';
|
||||
|
||||
interface AuthState {
|
||||
@@ -8,6 +9,8 @@ interface AuthState {
|
||||
/** Sign in with the admin's email + password (event-independent). */
|
||||
signIn: (email: string, password: string) => Promise<void>;
|
||||
signOut: () => Promise<void>;
|
||||
/** Change the current admin's own login password (re-authenticates). */
|
||||
changePassword: (newPassword: string) => Promise<void>;
|
||||
}
|
||||
|
||||
const AuthContext = createContext<AuthState | null>(null);
|
||||
@@ -100,8 +103,16 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
setContact(null);
|
||||
}
|
||||
|
||||
async function changePassword(newPassword: string) {
|
||||
if (!contact) throw new Error('Not signed in');
|
||||
await changeMyPassword(contact.email, newPassword);
|
||||
// Re-load the contact so the (now changed) password is reflected.
|
||||
const c = await loadAdminContact(contact.email);
|
||||
if (c) setContact(c);
|
||||
}
|
||||
|
||||
return (
|
||||
<AuthContext.Provider value={{ contact, loading, signIn, signOut }}>
|
||||
<AuthContext.Provider value={{ contact, loading, signIn, signOut, changePassword }}>
|
||||
{children}
|
||||
</AuthContext.Provider>
|
||||
);
|
||||
|
||||
@@ -4,6 +4,7 @@ import type {
|
||||
Connection,
|
||||
Contact,
|
||||
Event,
|
||||
EventFeedback,
|
||||
ExcelSyncResult,
|
||||
Feedback,
|
||||
LeaderboardRow,
|
||||
@@ -23,6 +24,9 @@ import type {
|
||||
|
||||
export class ApiError extends Error {}
|
||||
|
||||
/** The default admin password for @appe.at contacts (set by the DB trigger). */
|
||||
export const DEFAULT_ADMIN_PASSWORD = 'appe-admin-2026';
|
||||
|
||||
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);
|
||||
@@ -61,6 +65,7 @@ export const getAllSessionSpeakers = () => all<SessionSpeaker>('session_speakers
|
||||
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 getAllEventFeedback = () => all<EventFeedback>('event_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 });
|
||||
|
||||
@@ -96,11 +101,34 @@ export async function deleteContact(email: string): Promise<void> {
|
||||
if (error) throw new ApiError(error.message);
|
||||
}
|
||||
|
||||
/** Delete many contacts at once (admin-only RLS). */
|
||||
/**
|
||||
* Delete many contacts at once (admin-only). Uses the `bulk_delete_contacts`
|
||||
* RPC, which bypasses the "a session must have at least one speaker" guard —
|
||||
* a direct PostgREST delete would fail (P0001) if the batch includes a contact
|
||||
* who is the sole speaker of a session.
|
||||
*/
|
||||
export async function deleteContacts(emails: string[]): Promise<void> {
|
||||
if (emails.length === 0) return;
|
||||
const { error } = await supabase.from('contacts').delete().in('email', emails);
|
||||
if (error) throw new ApiError(error.message);
|
||||
await rpc<number>('bulk_delete_contacts', { p_emails: emails });
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the current admin's own login password. Sets `contacts.password`
|
||||
* (the `trg_contact_password_sync` trigger re-hashes it into
|
||||
* `auth.users.encrypted_password`), then re-authenticates with the new
|
||||
* password so the session reflects the change.
|
||||
*/
|
||||
export async function changeMyPassword(email: string, newPassword: string): Promise<void> {
|
||||
const { error: updateError } = await supabase
|
||||
.from('contacts')
|
||||
.update({ password: newPassword })
|
||||
.eq('email', email);
|
||||
if (updateError) throw new ApiError(updateError.message);
|
||||
const { error: signInError } = await supabase.auth.signInWithPassword({
|
||||
email,
|
||||
password: newPassword,
|
||||
});
|
||||
if (signInError) throw new ApiError(signInError.message);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,6 +199,7 @@ export async function upsertEvent(
|
||||
pretix_event_slug?: string | null;
|
||||
pretix_api_key?: string | null;
|
||||
use_realtime_clock?: boolean;
|
||||
talk_networking_bonus?: number;
|
||||
},
|
||||
): Promise<void> {
|
||||
if (id) {
|
||||
@@ -240,6 +269,34 @@ export async function importSessionizeExcel(eventId: string, file: File): Promis
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Request an event report from the sidecar (`POST /export`). Returns the
|
||||
* filename, mime type, and base64 content; the caller decodes and downloads.
|
||||
*/
|
||||
export const exportEventReport = (
|
||||
eventId: string,
|
||||
format: 'csv' | 'xlsx' | 'pdf',
|
||||
tables?: string[],
|
||||
) =>
|
||||
sidecarFetch<{ filename: string; mime: string; content_base64: string }>('/export', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ event_id: eventId, format, tables }),
|
||||
});
|
||||
|
||||
/** Decode a base64 report body and trigger a browser download. */
|
||||
export function downloadReport(res: { filename: string; mime: string; content_base64: string }): void {
|
||||
const bytes = Uint8Array.from(atob(res.content_base64), (c) => c.charCodeAt(0));
|
||||
const blob = new Blob([bytes], { type: res.mime });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = res.filename;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
||||
}
|
||||
|
||||
/** Recent sync_runs rows for an event (newest first). */
|
||||
export const getSyncRuns = (eventId: string) =>
|
||||
all<SyncRun>('sync_runs', { col: 'started_at', asc: false }).then((rows) =>
|
||||
|
||||
@@ -43,6 +43,8 @@ export interface Event {
|
||||
pretix_api_key?: string | null;
|
||||
/** When the Sessionize sync last ran for this event. */
|
||||
last_synced_at: string | null;
|
||||
/** Bonus points each party earns for a connection when they shared a checked-in talk (0 = off). */
|
||||
talk_networking_bonus: number;
|
||||
avg_feedback: number | null;
|
||||
num_sessions: number;
|
||||
num_speakers: number;
|
||||
@@ -214,6 +216,20 @@ export interface Session {
|
||||
average_feedback: number | null;
|
||||
ai_generated_feedback: string | null;
|
||||
material_path: string | null;
|
||||
/** Free-text level classification (e.g. 100/200/300 or Beginner/Intermediate). */
|
||||
level: string | null;
|
||||
/** Free-text area/topic classification (e.g. Power Apps, Power Automate). */
|
||||
area: string | null;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
/** Event-level feedback (distinct from the per-session `feedback` table). */
|
||||
export interface EventFeedback {
|
||||
id: string;
|
||||
event_id: string;
|
||||
contact_email: string;
|
||||
rating: number;
|
||||
comment: string | null;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
@@ -266,7 +282,7 @@ export interface PointsLogRow {
|
||||
event_id: string;
|
||||
contact_email: string;
|
||||
delta: number;
|
||||
category: 'checkin' | 'connection' | 'feedback' | 'admin';
|
||||
category: 'checkin' | 'connection' | 'feedback' | 'admin' | 'talk_networking';
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,14 +3,15 @@ import {
|
||||
getAllCheckins,
|
||||
getAllConnections,
|
||||
getAllContacts,
|
||||
getAllEventFeedback,
|
||||
getAllFeedback,
|
||||
getActiveEvent,
|
||||
getSessions,
|
||||
} from '../lib/api';
|
||||
import type { Checkin, Connection, Contact, Event, Feedback, Session } from '../lib/types';
|
||||
import type { Checkin, Connection, Contact, Event, EventFeedback, Feedback, Session } from '../lib/types';
|
||||
import { Avatar, Empty, Spinner } from '../components/ui';
|
||||
|
||||
type Tab = 'checkins' | 'connections' | 'feedback';
|
||||
type Tab = 'checkins' | 'connections' | 'feedback' | 'event_feedback';
|
||||
|
||||
export function Activity() {
|
||||
const [event, setEvent] = useState<Event | null>(null);
|
||||
@@ -21,17 +22,19 @@ export function Activity() {
|
||||
const [checkins, setCheckins] = useState<Checkin[]>([]);
|
||||
const [connections, setConnections] = useState<Connection[]>([]);
|
||||
const [feedback, setFeedback] = useState<Feedback[]>([]);
|
||||
const [eventFeedback, setEventFeedback] = useState<EventFeedback[]>([]);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
const ev = await getActiveEvent();
|
||||
setEvent(ev);
|
||||
const [c, ck, cn, fb] = await Promise.all([
|
||||
const [c, ck, cn, fb, efb] = await Promise.all([
|
||||
getAllContacts(),
|
||||
getAllCheckins(),
|
||||
getAllConnections(),
|
||||
getAllFeedback(),
|
||||
getAllEventFeedback(),
|
||||
]);
|
||||
setContacts(c);
|
||||
if (ev) {
|
||||
@@ -40,6 +43,7 @@ export function Activity() {
|
||||
setCheckins(ck.filter((x) => x.event_id === ev.id));
|
||||
setConnections(cn.filter((x) => x.event_id === ev.id));
|
||||
setFeedback(fb.filter((x) => x.event_id === ev.id));
|
||||
setEventFeedback(efb.filter((x) => x.event_id === ev.id));
|
||||
}
|
||||
setLoaded(true);
|
||||
} catch (e) {
|
||||
@@ -61,6 +65,26 @@ export function Activity() {
|
||||
return (id: string) => m.get(id) ?? id;
|
||||
}, [sessions]);
|
||||
|
||||
// Per-session feedback aggregate (avg rating + response count), for the
|
||||
// post-event session feedback summary.
|
||||
const sessionFeedbackSummary = useMemo(() => {
|
||||
const bySession = new Map<string, { count: number; sum: number }>();
|
||||
for (const f of feedback) {
|
||||
const e = bySession.get(f.session_id) ?? { count: 0, sum: 0 };
|
||||
e.count += 1;
|
||||
e.sum += f.rating;
|
||||
bySession.set(f.session_id, e);
|
||||
}
|
||||
return [...bySession.entries()]
|
||||
.map(([session_id, e]) => ({
|
||||
session_id,
|
||||
title: sessionTitle(session_id),
|
||||
avg: e.sum / e.count,
|
||||
count: e.count,
|
||||
}))
|
||||
.sort((a, b) => b.avg - a.avg);
|
||||
}, [feedback, sessionTitle]);
|
||||
|
||||
if (error) return <Empty icon="⚠️" text={error} />;
|
||||
if (!loaded)
|
||||
return (
|
||||
@@ -91,7 +115,7 @@ export function Activity() {
|
||||
<div>
|
||||
<h1>Activity</h1>
|
||||
<div className="sub">
|
||||
{event.name} · {checkins.length} check-ins · {connections.length} connections · {feedback.length} feedback.
|
||||
{event.name} · {checkins.length} check-ins · {connections.length} connections · {feedback.length} session feedback · {eventFeedback.length} event feedback.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -104,7 +128,10 @@ export function Activity() {
|
||||
Connections
|
||||
</button>
|
||||
<button className={tab === 'feedback' ? 'active' : ''} onClick={() => setTab('feedback')}>
|
||||
Feedback
|
||||
Session feedback
|
||||
</button>
|
||||
<button className={tab === 'event_feedback' ? 'active' : ''} onClick={() => setTab('event_feedback')}>
|
||||
Event feedback
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -185,6 +212,23 @@ export function Activity() {
|
||||
{feedback.length === 0 ? (
|
||||
<Empty icon="⭐" text="No feedback yet." />
|
||||
) : (
|
||||
<>
|
||||
{/* Per-session aggregate header (the post-event session feedback summary). */}
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<div className="muted small" style={{ fontWeight: 700, marginBottom: 6 }}>
|
||||
Per-session summary
|
||||
</div>
|
||||
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
|
||||
{sessionFeedbackSummary.map((s) => (
|
||||
<span key={s.session_id} className="pill amber" title={s.title}>
|
||||
{s.title} · {s.avg.toFixed(1)}★ · {s.count}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{feedback.length > 0 && (
|
||||
<div className="table-wrap">
|
||||
<table className="data">
|
||||
<thead>
|
||||
@@ -216,6 +260,41 @@ export function Activity() {
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{tab === 'event_feedback' && (
|
||||
<div className="card">
|
||||
{eventFeedback.length === 0 ? (
|
||||
<Empty icon="⭐" text="No event-level feedback yet." />
|
||||
) : (
|
||||
<div className="table-wrap">
|
||||
<table className="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>From</th>
|
||||
<th>Rating</th>
|
||||
<th>Comment</th>
|
||||
<th>When</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{eventFeedback.map((f) => (
|
||||
<tr key={f.id}>
|
||||
<td>
|
||||
<PersonCell name={nameOf(f.contact_email)} email={f.contact_email} />
|
||||
</td>
|
||||
<td>
|
||||
<span className="pill amber">{'★'.repeat(f.rating)}</span>
|
||||
</td>
|
||||
<td className="muted">{f.comment || '—'}</td>
|
||||
<td className="muted">{fmt(f.created_at)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -293,6 +293,7 @@ function EventModal({
|
||||
const [pretixLoading, setPretixLoading] = useState(false);
|
||||
const [pretixError, setPretixError] = useState<string | null>(null);
|
||||
const [realtimeClock, setRealtimeClock] = useState(event?.use_realtime_clock ?? false);
|
||||
const [talkBonus, setTalkBonus] = useState(event?.talk_networking_bonus ?? 2);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const lastFetchedKey = useRef<string | null>(null);
|
||||
|
||||
@@ -339,6 +340,7 @@ function EventModal({
|
||||
pretix_event_slug: pretixEventSlug.trim() || null,
|
||||
pretix_api_key: pretixApiKey.trim() || null,
|
||||
use_realtime_clock: realtimeClock,
|
||||
talk_networking_bonus: Math.max(0, Math.min(10, Math.round(talkBonus) || 0)),
|
||||
});
|
||||
onSaved(event ? 'Event updated' : 'Event created');
|
||||
} catch (e) {
|
||||
@@ -491,6 +493,27 @@ function EventModal({
|
||||
<Toggle checked={realtimeClock} onChange={setRealtimeClock} label={realtimeClock ? 'On' : 'Off'} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="field">
|
||||
<div className="row between" style={{ alignItems: 'center' }}>
|
||||
<div>
|
||||
<label>Talk networking bonus</label>
|
||||
<div className="muted small" style={{ marginTop: 2, maxWidth: 420 }}>
|
||||
Points each party earns when two people who were checked into the same talk accept a
|
||||
connection. <b>0 disables</b> the bonus (the +5 connection award still applies).
|
||||
</div>
|
||||
</div>
|
||||
<input
|
||||
className="input mono"
|
||||
type="number"
|
||||
min={0}
|
||||
max={10}
|
||||
step={1}
|
||||
style={{ width: 84, textAlign: 'center' }}
|
||||
value={Number.isFinite(talkBonus) ? talkBonus : 0}
|
||||
onChange={(e) => setTalkBonus(parseInt(e.target.value, 10) || 0)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,404 @@
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import {
|
||||
downloadReport,
|
||||
exportEventReport,
|
||||
getAllCheckins,
|
||||
getAllConnections,
|
||||
getAllContacts,
|
||||
getAllEventFeedback,
|
||||
getAllEvents,
|
||||
getAllFeedback,
|
||||
getAllPointsLog,
|
||||
getLeaderboard,
|
||||
getRegistrations,
|
||||
getSessions,
|
||||
} from '../lib/api';
|
||||
import type {
|
||||
Checkin,
|
||||
Connection,
|
||||
Contact,
|
||||
Event,
|
||||
EventFeedback,
|
||||
Feedback,
|
||||
LeaderboardRow,
|
||||
PointsLogRow,
|
||||
Registration,
|
||||
Session,
|
||||
} from '../lib/types';
|
||||
import { useToast } from '../context/ToastContext';
|
||||
import { Empty, Spinner } from '../components/ui';
|
||||
|
||||
const TABLES = [
|
||||
'registrations',
|
||||
'checkins',
|
||||
'connections',
|
||||
'session_feedback',
|
||||
'event_feedback',
|
||||
'leaderboard',
|
||||
'points_log',
|
||||
] as const;
|
||||
|
||||
const CATEGORY_LABEL: Record<string, string> = {
|
||||
checkin: 'Session check-ins',
|
||||
connection: 'Connections',
|
||||
feedback: 'Feedback',
|
||||
talk_networking: 'Talk networking',
|
||||
admin: 'Other',
|
||||
};
|
||||
|
||||
/**
|
||||
* Post-event reporting & export. For any event (active or past): an on-screen
|
||||
* summary (session-feedback summary + aggregates) and CSV / Excel / PDF report
|
||||
* downloads (served by the sidecar's `POST /export`).
|
||||
*/
|
||||
export function Reports() {
|
||||
const { push } = useToast();
|
||||
const [events, setEvents] = useState<Event[]>([]);
|
||||
const [selectedId, setSelectedId] = useState('');
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const [contacts, setContacts] = useState<Contact[]>([]);
|
||||
const [registrations, setRegistrations] = useState<Registration[]>([]);
|
||||
const [checkins, setCheckins] = useState<Checkin[]>([]);
|
||||
const [connections, setConnections] = useState<Connection[]>([]);
|
||||
const [feedback, setFeedback] = useState<Feedback[]>([]);
|
||||
const [eventFeedback, setEventFeedback] = useState<EventFeedback[]>([]);
|
||||
const [leaderboard, setLeaderboard] = useState<LeaderboardRow[]>([]);
|
||||
const [pointsLog, setPointsLog] = useState<PointsLogRow[]>([]);
|
||||
const [sessions, setSessions] = useState<Session[]>([]);
|
||||
|
||||
const [tables, setTables] = useState<Set<string>>(new Set(TABLES));
|
||||
const [exporting, setExporting] = useState<'csv' | 'xlsx' | 'pdf' | null>(null);
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
const evs = await getAllEvents();
|
||||
setEvents(evs);
|
||||
const active = evs.find((e) => e.is_active);
|
||||
const first = active ?? evs[0];
|
||||
if (first) setSelectedId((cur) => cur || first.id);
|
||||
setLoaded(true);
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : 'Failed to load');
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, []);
|
||||
|
||||
// Load the selected event's data (any event, not just the active one).
|
||||
useEffect(() => {
|
||||
if (!selectedId) return;
|
||||
let active = true;
|
||||
(async () => {
|
||||
try {
|
||||
const [c, reg, ck, cn, fb, efb, lb, pl, ss] = await Promise.all([
|
||||
getAllContacts(),
|
||||
getRegistrations(selectedId),
|
||||
getAllCheckins(),
|
||||
getAllConnections(),
|
||||
getAllFeedback(),
|
||||
getAllEventFeedback(),
|
||||
getLeaderboard(),
|
||||
getAllPointsLog(),
|
||||
getSessions(selectedId),
|
||||
]);
|
||||
if (!active) return;
|
||||
setContacts(c);
|
||||
setRegistrations(reg);
|
||||
setCheckins(ck.filter((x) => x.event_id === selectedId));
|
||||
setConnections(cn.filter((x) => x.event_id === selectedId));
|
||||
setFeedback(fb.filter((x) => x.event_id === selectedId));
|
||||
setEventFeedback(efb.filter((x) => x.event_id === selectedId));
|
||||
setLeaderboard(lb.filter((x) => x.event_id === selectedId));
|
||||
setPointsLog(pl.filter((x) => x.event_id === selectedId));
|
||||
setSessions(ss);
|
||||
} catch (e) {
|
||||
if (active) setError(e instanceof Error ? e.message : 'Failed to load event data');
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
}, [selectedId]);
|
||||
|
||||
const nameOf = useMemo(() => {
|
||||
const m = new Map(contacts.map((c) => [c.email, c.full_name]));
|
||||
return (email: string) => m.get(email) ?? email;
|
||||
}, [contacts]);
|
||||
|
||||
// ---- Aggregates -----------------------------------------------------------
|
||||
const byType = useMemo(() => {
|
||||
const t: Record<string, number> = {};
|
||||
for (const r of registrations) t[r.type] = (t[r.type] ?? 0) + 1;
|
||||
return t;
|
||||
}, [registrations]);
|
||||
|
||||
const acceptedConnections = useMemo(
|
||||
() => connections.filter((c) => c.status === 'accepted').length,
|
||||
[connections],
|
||||
);
|
||||
|
||||
const sessionFeedbackAvg = useMemo(() => {
|
||||
if (feedback.length === 0) return null;
|
||||
return feedback.reduce((s, f) => s + f.rating, 0) / feedback.length;
|
||||
}, [feedback]);
|
||||
|
||||
const eventFeedbackAvg = useMemo(() => {
|
||||
if (eventFeedback.length === 0) return null;
|
||||
return eventFeedback.reduce((s, f) => s + f.rating, 0) / eventFeedback.length;
|
||||
}, [eventFeedback]);
|
||||
|
||||
// Per-session feedback summary (the "post-event session feedback summary").
|
||||
const sessionSummary = useMemo(() => {
|
||||
const bySession = new Map<string, { count: number; sum: number }>();
|
||||
for (const f of feedback) {
|
||||
const e = bySession.get(f.session_id) ?? { count: 0, sum: 0 };
|
||||
e.count += 1;
|
||||
e.sum += f.rating;
|
||||
bySession.set(f.session_id, e);
|
||||
}
|
||||
return sessions
|
||||
.map((s) => {
|
||||
const e = bySession.get(s.id);
|
||||
return {
|
||||
title: s.title,
|
||||
room: s.room,
|
||||
avg: e ? e.sum / e.count : null,
|
||||
count: e ? e.count : 0,
|
||||
};
|
||||
})
|
||||
.filter((s) => s.count > 0)
|
||||
.sort((a, b) => (b.avg ?? 0) - (a.avg ?? 0));
|
||||
}, [sessions, feedback]);
|
||||
|
||||
const topLeaderboard = useMemo(
|
||||
() => [...leaderboard].sort((a, b) => b.points - a.points).slice(0, 5),
|
||||
[leaderboard],
|
||||
);
|
||||
|
||||
const pointsByCategory = useMemo(() => {
|
||||
const t: Record<string, number> = {};
|
||||
for (const l of pointsLog) t[l.category] = (t[l.category] ?? 0) + l.delta;
|
||||
return t;
|
||||
}, [pointsLog]);
|
||||
|
||||
// ---- Export -------------------------------------------------------------
|
||||
async function doExport(format: 'csv' | 'xlsx' | 'pdf') {
|
||||
if (!selectedId) return;
|
||||
setExporting(format);
|
||||
try {
|
||||
const res = await exportEventReport(selectedId, format, format === 'pdf' ? undefined : [...tables]);
|
||||
downloadReport(res);
|
||||
push('success', `Downloaded ${format.toUpperCase()} report`);
|
||||
} catch (e) {
|
||||
push('error', e instanceof Error ? e.message : 'Export failed');
|
||||
} finally {
|
||||
setExporting(null);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleTable(t: string) {
|
||||
setTables((prev) => {
|
||||
const next = new Set(prev);
|
||||
if (next.has(t)) next.delete(t);
|
||||
else next.add(t);
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
if (error) return <Empty icon="⚠️" text={error} />;
|
||||
if (!loaded)
|
||||
return (
|
||||
<div className="loading-screen">
|
||||
<Spinner />
|
||||
</div>
|
||||
);
|
||||
|
||||
const selected = events.find((e) => e.id === selectedId);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="page-head">
|
||||
<div>
|
||||
<h1>Reports</h1>
|
||||
<div className="sub">Post-event summary + CSV / Excel / PDF export. Works for any event.</div>
|
||||
</div>
|
||||
<select
|
||||
className="input"
|
||||
style={{ maxWidth: 320 }}
|
||||
value={selectedId}
|
||||
onChange={(e) => setSelectedId(e.target.value)}
|
||||
>
|
||||
{events.map((e) => (
|
||||
<option key={e.id} value={e.id}>
|
||||
{e.name} {e.is_active ? '(active)' : ''}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{!selected ? (
|
||||
<div className="card">
|
||||
<Empty icon="📅" text="No events yet. Create one in the Events view first." />
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
{/* On-screen summary */}
|
||||
<div className="card" style={{ marginBottom: 18 }}>
|
||||
<h2 className="h2">📊 Summary — {selected.name}</h2>
|
||||
<div className="muted small" style={{ marginBottom: 12 }}>
|
||||
{selected.start_date} – {selected.end_date}
|
||||
{selected.location ? ` · ${selected.location}` : ''}
|
||||
</div>
|
||||
<div className="stat-grid">
|
||||
<Stat label="Registrations" value={registrations.length} />
|
||||
<Stat label="Check-ins" value={checkins.length} />
|
||||
<Stat label="Connections" value={connections.length} sub={`${acceptedConnections} accepted`} />
|
||||
<Stat label="Session feedback" value={feedback.length} sub={sessionFeedbackAvg != null ? `avg ${sessionFeedbackAvg.toFixed(1)}★` : undefined} />
|
||||
<Stat label="Event feedback" value={eventFeedback.length} sub={eventFeedbackAvg != null ? `avg ${eventFeedbackAvg.toFixed(1)}★` : undefined} />
|
||||
</div>
|
||||
<div style={{ display: 'flex', gap: 18, flexWrap: 'wrap', marginTop: 14 }}>
|
||||
<div>
|
||||
<div className="muted small" style={{ fontWeight: 700, marginBottom: 6 }}>Registrations by type</div>
|
||||
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
|
||||
{Object.entries(byType).map(([t, n]) => (
|
||||
<span key={t} className="pill">{t}: {n}</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="muted small" style={{ fontWeight: 700, marginBottom: 6 }}>Points by category</div>
|
||||
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
|
||||
{Object.entries(pointsByCategory).map(([c, n]) => (
|
||||
<span key={c} className="pill">{CATEGORY_LABEL[c] ?? c}: +{n}</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Session feedback summary */}
|
||||
<div className="card" style={{ marginBottom: 18 }}>
|
||||
<h2 className="h2">⭐ Session feedback summary</h2>
|
||||
{sessionSummary.length === 0 ? (
|
||||
<Empty icon="⭐" text="No session feedback yet." />
|
||||
) : (
|
||||
<div className="table-wrap">
|
||||
<table className="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Session</th>
|
||||
<th>Room</th>
|
||||
<th>Avg rating</th>
|
||||
<th>Responses</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{sessionSummary.map((s) => (
|
||||
<tr key={s.title}>
|
||||
<td style={{ fontWeight: 600 }}>{s.title}</td>
|
||||
<td className="muted">{s.room ?? '—'}</td>
|
||||
<td>
|
||||
<span className="pill amber">
|
||||
{s.avg != null ? `${s.avg.toFixed(1)}★` : '—'}
|
||||
</span>
|
||||
</td>
|
||||
<td className="muted">{s.count}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Top leaderboard */}
|
||||
<div className="card" style={{ marginBottom: 18 }}>
|
||||
<h2 className="h2">🏆 Top points</h2>
|
||||
{topLeaderboard.length === 0 ? (
|
||||
<Empty icon="🏆" text="No points yet." />
|
||||
) : (
|
||||
<div className="table-wrap">
|
||||
<table className="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Attendee</th>
|
||||
<th>Points</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{topLeaderboard.map((r, i) => (
|
||||
<tr key={r.contact_email}>
|
||||
<td className="muted">{i + 1}</td>
|
||||
<td style={{ fontWeight: 600 }}>{nameOf(r.contact_email)}</td>
|
||||
<td>
|
||||
<span className="pill amber">⚡ {r.points}</span>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Export */}
|
||||
<div className="card">
|
||||
<h2 className="h2">📤 Export</h2>
|
||||
<div style={{ display: 'flex', gap: 10, flexWrap: 'wrap', marginBottom: 14 }}>
|
||||
<button
|
||||
className="btn primary"
|
||||
disabled={exporting !== null || tables.size === 0}
|
||||
onClick={() => void doExport('csv')}
|
||||
>
|
||||
{exporting === 'csv' ? 'Preparing…' : 'Download CSV'}
|
||||
</button>
|
||||
<button
|
||||
className="btn primary"
|
||||
disabled={exporting !== null || tables.size === 0}
|
||||
onClick={() => void doExport('xlsx')}
|
||||
>
|
||||
{exporting === 'xlsx' ? 'Preparing…' : 'Download Excel'}
|
||||
</button>
|
||||
<button className="btn primary" disabled={exporting !== null} onClick={() => void doExport('pdf')}>
|
||||
{exporting === 'pdf' ? 'Preparing…' : 'Download PDF report'}
|
||||
</button>
|
||||
</div>
|
||||
<div className="muted small" style={{ marginBottom: 8 }}>
|
||||
Tables included in CSV / Excel:
|
||||
</div>
|
||||
<div style={{ display: 'flex', gap: 14, flexWrap: 'wrap' }}>
|
||||
{TABLES.map((t) => (
|
||||
<label key={t} style={{ display: 'inline-flex', alignItems: 'center', gap: 6, cursor: 'pointer' }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={tables.has(t)}
|
||||
onChange={() => toggleTable(t)}
|
||||
style={{ width: 16, height: 16, accentColor: 'var(--accent)' }}
|
||||
/>
|
||||
<span className="muted small">{t.replace('_', ' ')}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Stat({ label, value, sub }: { label: string; value: number; sub?: string }) {
|
||||
return (
|
||||
<div className="stat">
|
||||
<div className="val">{value}</div>
|
||||
<div className="lbl">
|
||||
{label}
|
||||
{sub ? ` · ${sub}` : ''}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -193,7 +193,7 @@ export function Schedule() {
|
||||
<div style={{ minWidth: 0 }}>
|
||||
<div style={{ fontWeight: 700, fontSize: 14 }}>{s.title}</div>
|
||||
<div className="muted small">
|
||||
{[s.room, spk || 'no speakers', s.capacity ? `cap ${s.capacity}` : null].filter(Boolean).join(' · ')}
|
||||
{[s.room, spk || 'no speakers', s.capacity ? `cap ${s.capacity}` : null, s.level ? `📶 ${s.level}` : null, s.area ? `🗂 ${s.area}` : null].filter(Boolean).join(' · ')}
|
||||
</div>
|
||||
<div className="muted small" style={{ marginTop: 4 }}>
|
||||
{s.average_feedback != null && <span>⭐ {s.average_feedback.toFixed(1)}</span>}
|
||||
@@ -364,6 +364,8 @@ function SessionModal({
|
||||
const [room, setRoom] = useState(session?.room ?? '');
|
||||
const [capacity, setCapacity] = useState(session?.capacity?.toString() ?? '');
|
||||
const [description, setDescription] = useState(session?.description ?? '');
|
||||
const [level, setLevel] = useState(session?.level ?? '');
|
||||
const [area, setArea] = useState(session?.area ?? '');
|
||||
const [speakerEmails, setSpeakerEmails] = useState<string[]>(currentSpeakers);
|
||||
const [material, setMaterial] = useState<File | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
@@ -377,6 +379,8 @@ function SessionModal({
|
||||
room: room.trim() || null,
|
||||
capacity: capacity ? parseInt(capacity, 10) : null,
|
||||
description: description.trim() || null,
|
||||
level: level.trim() || null,
|
||||
area: area.trim() || null,
|
||||
slot_id: slotId,
|
||||
event_id: eventId,
|
||||
};
|
||||
@@ -445,6 +449,16 @@ function SessionModal({
|
||||
<label>Description</label>
|
||||
<textarea className="input" value={description} onChange={(e) => setDescription(e.target.value)} placeholder="—" />
|
||||
</div>
|
||||
<div className="grid-2">
|
||||
<div className="field">
|
||||
<label>Level</label>
|
||||
<input className="input" value={level} onChange={(e) => setLevel(e.target.value)} placeholder="e.g. 100 / Beginner" />
|
||||
</div>
|
||||
<div className="field">
|
||||
<label>Area / Topic</label>
|
||||
<input className="input" value={area} onChange={(e) => setArea(e.target.value)} placeholder="e.g. Power Apps" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="field">
|
||||
<label>Speakers ({speakerEmails.length})</label>
|
||||
|
||||
Reference in new issue
Block a user