- groupAgenda drops orphan service slots (no session row), so every Service Session card consistently shows header + session row; list, slot count and Home Now/Next agree - Extract the session detail bottom sheet into shared components/SessionDetail.tsx; Home's My-picks chips now open it in place instead of routing to the Agenda (App passes openFeedback so Give-feedback works there too) - Sheet subtitle shows the slot name only when it adds information: auto-named 'Slot 10:15-11:00' no longer repeats the time range, and service names equal to the session title are skipped - e2e: orphan-slot test + Home session picks test (exact subtitle assertion) in convivo-admin-entry.spec.ts, 41/41 green; speaker-portal 19/19; docs + release record 2026-10-16.md
200 lines
7.2 KiB
TypeScript
200 lines
7.2 KiB
TypeScript
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';
|
||
import { isSpeakerPortal } from './lib/speakerPortal';
|
||
import { SpeakerPortal } from './screens/SpeakerPortal';
|
||
|
||
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)} openFeedback={(id) => setFeedbackSession(id)} />}
|
||
{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() {
|
||
if (isSpeakerPortal) return <SpeakerPortal />;
|
||
return (
|
||
<ToastProvider>
|
||
<AuthProvider>
|
||
<Shell />
|
||
</AuthProvider>
|
||
</ToastProvider>
|
||
);
|
||
}
|