Files
Convivo/apps/convivo/src/screens/Scan.tsx
T
bd67debeef Service sessions + Home redesign + feedback loop
Service sessions (new slot semantics):
- Sidecar maps isServiceSession OR isPlenumSession -> service_session
  (Excel path also matches 'plenum' in Session Format).
- checkin_attendee rejects service sessions; Scan check-in dropdown
  excludes them.
- New _assign_service_session_speakers helper links every registered
  staff member as a speaker of a service session; both sync RPCs call
  it (and the API sync now actually types slots from is_service_session).
- No material requirement + no mic emoji for service sessions.

Home redesign:
- Now/Next cards show all concurrent sessions as sub-sections when
  there's no pick (1/2/3 sessions -> 1/2/3 sub-sections), with a
  "Nothing scheduled" fallback for empty slots.
- My picks today lists every pick (slot order) + empty state.
- Demo clock EVENT_DATE fixed to 2026-02-20 (matches seed) so a slot
  is live at 10:20.

Feedback loop:
- Attendee pending-feedback pill on Home (checked into an over session,
  not its speaker, no feedback yet); clears on submit.
- Speaker sees rating + AI summary for their own session in the Agenda
  sheet only after it's over.

Migration 20260833000000_service_sessions_feedback.sql. Docs updated.

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-08-25 08:58:16 +02:00

223 lines
8.8 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 { useEffect, useState } from 'react';
import { useAuth } from '../context/AuthContext';
import { useEvent } from '../lib/useEvent';
import { checkinAttendee, createConnectionRequest, lanyardLookup, welcomeCheckin } from '../lib/api';
import { capWords } from '../lib/time';
import type { CheckinResult, PublicContact, WelcomeCheckinResult } from '../lib/types';
import { Avatar, Scanner, Sheet, Spinner } from '../components/ui';
import { useToast } from '../context/ToastContext';
export function Scan() {
const { contact } = useAuth();
const { slots, loading } = useEvent();
const isStaff = !!contact?.is_admin;
const [mode, setMode] = useState<'attendee' | 'staff'>(isStaff ? 'staff' : 'attendee');
const [sessionId, setSessionId] = useState<string>('');
const [welcomeMode, setWelcomeMode] = useState(false);
const [connectTarget, setConnectTarget] = useState<{ contact: PublicContact; qr: string } | null>(null);
const [checkin, setCheckin] = useState<CheckinResult | null>(null);
const [welcome, setWelcome] = useState<WelcomeCheckinResult | null>(null);
const [busy, setBusy] = useState(false);
const { toast } = useToast();
useEffect(() => {
if (slots.length > 0 && !sessionId) {
// Default to the first checkable (non-service) session.
const first = slots.flatMap((s) => s.sessions).find((s) => s.slot_type !== 'service_session');
if (first) setSessionId(first.id);
}
}, [slots, sessionId]);
if (loading || !contact) {
return (
<section className="screen">
<div className="center" style={{ flex: 1 }}>
<Spinner />
</div>
</section>
);
}
const meEmail = contact.email;
const activeStaff = mode === 'staff' && isStaff;
async function handleScan(token: string) {
setBusy(true);
try {
if (activeStaff) {
if (welcomeMode) {
const res = await welcomeCheckin(token);
setWelcome(res);
} else {
if (!sessionId) {
toast('Pick a session first', 'err');
return;
}
const res = await checkinAttendee(sessionId, token);
setCheckin(res);
}
} else {
const found = await lanyardLookup(token);
if (!found) {
toast('No attendee found for that code', 'err');
return;
}
if (found.email === meEmail) {
toast('That’s your own lanyard 🙂', 'err');
return;
}
setConnectTarget({ contact: found, qr: token });
}
} catch (e) {
toast(e instanceof Error ? e.message : 'Something went wrong', 'err');
} finally {
setBusy(false);
}
}
async function confirmConnect() {
if (!connectTarget) return;
setBusy(true);
try {
const conn = await createConnectionRequest(connectTarget.qr);
if (conn.status === 'accepted') toast('You’re connected! 🤝', 'ok');
else if (conn.status === 'pending') toast('Connection request sent', 'ok');
else toast('Request already resolved');
window.dispatchEvent(new Event('connections-changed'));
setConnectTarget(null);
} catch (e) {
toast(e instanceof Error ? e.message : 'Could not send request', 'err');
} finally {
setBusy(false);
}
}
const selSession = slots.flatMap((s) => s.sessions).find((s) => s.id === sessionId);
return (
<section className="screen">
<div className="row between">
<div>
<div className="h1">{activeStaff ? 'Check-in' : 'Scan'}</div>
<div className="muted small">{activeStaff ? 'Scan attendees to check them in' : 'Scan a peer’s lanyard to connect'}</div>
</div>
{isStaff && (
<div className="seg" style={{ width: 170 }}>
<button className={mode === 'attendee' ? 'active' : ''} onClick={() => setMode('attendee')}>Attendee</button>
<button className={mode === 'staff' ? 'active' : ''} onClick={() => setMode('staff')}>Staff</button>
</div>
)}
</div>
{activeStaff && (
<div>
<div className="row between" style={{ marginBottom: 10 }}>
<span className="muted small" style={{ fontWeight: 700 }}>Check-in type</span>
<label className="uiverse-toggle" title={welcomeMode ? 'Welcome check-in' : 'Session check-in'}>
<input
type="checkbox"
checked={welcomeMode}
onChange={(e) => setWelcomeMode(e.target.checked)}
/>
</label>
</div>
{welcomeMode ? (
<div className="muted small" style={{ padding: '10px 12px', background: 'var(--surface)', border: '1px solid var(--line)', borderRadius: 12 }}>
🏷 <b>Welcome check-in</b> — marks the attendee present at the event.
</div>
) : (
<>
<div className="muted small" style={{ marginBottom: 7 }}>Checking in to session</div>
<select className="input" value={sessionId} onChange={(e) => setSessionId(e.target.value)}>
{slots
.filter(({ slot }) => slot.type !== 'service_session')
.map(({ slot, sessions }) => (
<optgroup key={slot.id} label={`${slot.name} · ${slot.start_time.slice(0, 5)}`}>
{sessions.map((s) => (
<option key={s.id} value={s.id}>{s.title}</option>
))}
</optgroup>
))}
</select>
</>
)}
</div>
)}
<Scanner onResult={handleScan} label={activeStaff ? 'Point at an attendee’s lanyard' : 'Point at a peer’s lanyard'} />
{busy && <div className="center"><Spinner /></div>}
{activeStaff && !welcomeMode && selSession && (
<div className="muted small" style={{ textAlign: 'center', opacity: 0.6 }}>
{selSession.room} · {selSession.speakers}
</div>
)}
{/* Connect sheet */}
<Sheet open={!!connectTarget} onClose={() => setConnectTarget(null)}>
{connectTarget && (
<div style={{ textAlign: 'center' }}>
<Avatar name={connectTarget.contact.full_name} id={connectTarget.contact.email} size={72} fs={26} />
<h3 style={{ marginTop: 12 }}>{connectTarget.contact.full_name}</h3>
{connectTarget.contact.registration_type && (
<span className={`pill reg-${connectTarget.contact.registration_type}`} style={{ marginTop: 8 }}>
{capWords(connectTarget.contact.registration_type)}
</span>
)}
{connectTarget.contact.linkedin_url && (
<div className="sub" style={{ marginTop: 6 }}>
<a href={connectTarget.contact.linkedin_url} target="_blank" rel="noreferrer">LinkedIn</a>
</div>
)}
<div style={{ marginTop: 16 }}>
<button className="btn primary" disabled={busy} onClick={confirmConnect}>
{busy ? 'Sending…' : 'Connect 🤝'}
</button>
<button className="btn ghost" style={{ marginTop: 8 }} onClick={() => setConnectTarget(null)}>
Not now
</button>
</div>
</div>
)}
</Sheet>
{/* Check-in result sheet */}
<Sheet open={!!checkin} onClose={() => setCheckin(null)}>
{checkin && (
<div style={{ textAlign: 'center' }}>
<div style={{ fontSize: 52 }}>{checkin.already ? '⚠️' : '✅'}</div>
<h3 style={{ marginTop: 10 }}>{checkin.attendee_name}</h3>
<div className="sub">{checkin.already ? 'Already checked in' : 'Checked in'}</div>
<div style={{ marginTop: 14 }}>
{checkin.already ? (
<span className="pill amber">No extra points</span>
) : (
<span className="pill green">+10 pts · now {checkin.points}</span>
)}
</div>
<button className="btn primary" style={{ marginTop: 18 }} onClick={() => setCheckin(null)}>
Scan next
</button>
</div>
)}
</Sheet>
{/* Welcome check-in result sheet */}
<Sheet open={!!welcome} onClose={() => setWelcome(null)}>
{welcome && (
<div style={{ textAlign: 'center' }}>
<div style={{ fontSize: 52 }}>{welcome.already ? '⚠️' : '👋'}</div>
<h3 style={{ marginTop: 10 }}>{welcome.attendee_name}</h3>
<div className="sub">{welcome.already ? 'Already checked in to the event' : 'Welcome to the event!'}</div>
<div style={{ marginTop: 14 }}>
<span className="pill green">✓ Checked in</span>
</div>
<button className="btn primary" style={{ marginTop: 18 }} onClick={() => setWelcome(null)}>
Scan next
</button>
</div>
)}
</Sheet>
</section>
);
}