Files
Convivo/apps/convivo/src/App.tsx
T
0b6d1f2b6f 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.

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]>
2026-09-21 22:34:25 +02:00

197 lines
7.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useCallback, useEffect, useState } from 'react';
import { AuthProvider, useAuth } from './context/AuthContext';
import { ToastProvider } from './context/ToastContext';
import { Login } from './screens/Login';
import { Home } from './screens/Home';
import { Agenda } from './screens/Agenda';
import { Scan } from './screens/Scan';
import { Connections } from './screens/Connections';
import { Leaderboard } from './screens/Leaderboard';
import { Profile } from './screens/Profile';
import { Feedback } from './screens/Feedback';
import { EventFeedback } from './screens/EventFeedback';
import { QrImage, Spinner } from './components/ui';
import { getMyConnections } from './lib/api';
import { usePolling } from './lib/usePolling';
type Tab = 'home' | 'agenda' | 'scan' | 'connections' | 'profile' | 'leaderboard';
const TABS: { id: Tab; ico: string; label: string }[] = [
{ id: 'home', ico: '🏠', label: 'Home' },
{ id: 'agenda', ico: '📅', label: 'Agenda' },
{ id: 'scan', ico: '📷', label: 'Scan' },
{ id: 'connections', ico: '🤝', label: 'Connect' },
{ id: 'profile', ico: '👤', label: 'Profile' },
];
function Shell() {
const { session, contact, registration, loading, refresh, signOut } = useAuth();
const [tab, setTab] = useState<Tab>('home');
const [feedbackSession, setFeedbackSession] = useState<string | null>(null);
const [eventFeedbackOpen, setEventFeedbackOpen] = useState(false);
const [pendingIncoming, setPendingIncoming] = useState(0);
// Which sub-tab the Connect screen opens on (default 'mine'; 'networking'
// when reached via the Home "Networking" quick action).
const [connectionsTab, setConnectionsTab] = useState<'mine' | 'req' | 'networking'>('mine');
// Home's `go` handles the tab ids; 'networking' routes into the Connect
// screen's networking sub-tab.
const go = (t: string) => {
if (t === 'networking') {
setConnectionsTab('networking');
setTab('connections');
return;
}
setTab(t as Tab);
};
const email = contact?.email ?? '';
const loadPending = useCallback(async () => {
try {
const conns = await getMyConnections();
setPendingIncoming(conns.filter((c) => c.status === 'pending' && c.to_email === email).length);
} catch {
/* non-fatal */
}
}, [email]);
useEffect(() => {
if (email) void loadPending();
}, [email, loadPending]);
// Keep the Connect red-dot fresh: poll every 5s while visible.
usePolling(() => void loadPending(), 5000, !!email);
// Gate: a non-staff member must be checked in by staff before using the app.
// (Staff are never gated — they're the ones doing the checking in.)
const isGated = !!contact && !contact.is_admin && !registration?.checked_in;
// While gated, poll so the gate lifts as soon as staff checks them in.
usePolling(() => { if (isGated) void refresh(); }, 4000, isGated);
// Recalc immediately when a connection is accepted/declined/sent.
useEffect(() => {
const onChanged = () => void loadPending();
window.addEventListener('connections-changed', onChanged);
return () => window.removeEventListener('connections-changed', onChanged);
}, [loadPending]);
if (loading) {
return (
<div className="app">
<div className="center" style={{ flex: 1 }}>
<Spinner />
</div>
</div>
);
}
if (!session || !contact) {
return (
<div className="app">
<Login />
</div>
);
}
// Not checked in yet: a non-staff member must be checked in by staff before
// they can use the app. The gate lifts automatically (4s poll) once staff
// checks them in.
if (isGated) {
return (
<div className="app">
<div className="center" data-testid="checkin-required-gate" style={{ flex: 1, flexDirection: 'column', gap: 14, padding: 24, textAlign: 'center' }}>
<div style={{ fontSize: 56 }}>🏷️</div>
<div className="h1" style={{ textAlign: 'center' }}>Please see a staff member</div>
<div className="muted" style={{ textAlign: 'center', maxWidth: 320 }}>
You haven’t been checked in yet. Find a staff member and have them
scan your lanyard to get checked in — then you can start using the app.
</div>
{registration?.qr_token && (
<div className="card qr-wrap" style={{ marginTop: 4 }}>
<div className="h2" style={{ textAlign: 'center' }}>Your QR code</div>
<QrImage value={registration.qr_token} size={180} />
<div className="muted small" style={{ textAlign: 'center' }}>
Show this to <b>staff</b> to get checked in.
</div>
</div>
)}
<div className="muted small" style={{ opacity: 0.6 }}>
Checking in… this screen updates automatically.
</div>
<button className="btn ghost" onClick={() => void refresh()}>
I’ve been checked in — refresh
</button>
<button className="btn ghost" onClick={() => void signOut()}>
Log out
</button>
</div>
</div>
);
}
// Feedback is a full-screen takeover (no tab bar).
if (feedbackSession) {
return (
<div className="app">
<Feedback sessionId={feedbackSession} onDone={() => { setFeedbackSession(null); setTab('home'); }} />
</div>
);
}
// Event-level feedback is also a full-screen takeover (no tab bar).
if (eventFeedbackOpen) {
return (
<div className="app">
<EventFeedback onDone={() => { setEventFeedbackOpen(false); setTab('home'); }} />
</div>
);
}
// The home page (incl. the tab bar) is identical for every role. Staff keep
// their check-in capability inside the Scan screen (Attendee/Staff toggle).
const scanLabel = 'Scan';
return (
<div className="app">
{tab === 'home' && <Home go={go} onEventFeedback={() => setEventFeedbackOpen(true)} />}
{tab === 'agenda' && <Agenda openFeedback={(id) => setFeedbackSession(id)} />}
{tab === 'scan' && <Scan />}
{tab === 'connections' && <Connections initialTab={connectionsTab} />}
{tab === 'profile' && <Profile />}
{tab === 'leaderboard' && <Leaderboard />}
<nav className="tabbar">
{TABS.map((t) => (
<button
key={t.id}
data-testid={`tab-${t.id}`}
className={`tab ${t.id === 'scan' ? 'tab-scan' : ''} ${tab === t.id ? 'active' : ''}`}
onClick={() => setTab(t.id)}
>
{t.id === 'scan' ? (
<span className="scan-btn">📷</span>
) : (
<span className="ico">
{t.ico}
{t.id === 'connections' && pendingIncoming > 0 && <span className="dot" />}
</span>
)}
<span>{t.id === 'scan' ? scanLabel : t.label}</span>
</button>
))}
</nav>
</div>
);
}
export default function App() {
return (
<ToastProvider>
<AuthProvider>
<Shell />
</AuthProvider>
</ToastProvider>
);
}