Phase 0 + 1: Dockerized Supabase core + attendee PWA
Phase 0 — Supabase core (Docker via CLI): - Schema: profiles, slots, sessions, preferences, connections, checkins, feedback, leaderboard (Realtime mirror), points_log - RLS on every table; transactional security-definer points RPCs - Seed: 6 slots, 18 sessions, 13 demo users (QR token as auth password) Phase 1 — Attendee web PWA (React + Vite + TS): - Login via QR token + email (GoTrue, no email sent) - Home, Agenda, Scan/Connect, staff Check-in, Feedback, live Leaderboard, Profile - Same-origin proxy to Supabase (Vite dev / nginx in Docker) - Docker: multi-stage build -> nginx sidecar on the Supabase network 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]>
This commit is contained in:
commit
63aa4ecfc8
45 files changed
+6922
No files matched your search
@@ -0,0 +1,163 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useAuth } from '../context/AuthContext';
|
||||
import { useEvent } from '../lib/useEvent';
|
||||
import { checkinAttendee, createConnectionRequest, lanyardLookup } from '../lib/api';
|
||||
import type { CheckinResult, PublicProfile } from '../lib/types';
|
||||
import { Avatar, Scanner, Sheet, Spinner } from '../components/ui';
|
||||
import { useToast } from '../context/ToastContext';
|
||||
|
||||
export function Scan() {
|
||||
const { profile } = useAuth();
|
||||
const { slots, loading } = useEvent();
|
||||
const [mode, setMode] = useState<'attendee' | 'staff'>(profile?.role === 'staff' || profile?.role === 'admin' ? 'staff' : 'attendee');
|
||||
const [sessionId, setSessionId] = useState<string>('');
|
||||
const [connectTarget, setConnectTarget] = useState<{ profile: PublicProfile; qr: string } | null>(null);
|
||||
const [checkin, setCheckin] = useState<CheckinResult | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const { toast } = useToast();
|
||||
|
||||
useEffect(() => {
|
||||
if (slots.length > 0 && !sessionId) {
|
||||
const first = slots[0].sessions[0];
|
||||
if (first) setSessionId(first.id);
|
||||
}
|
||||
}, [slots, sessionId]);
|
||||
|
||||
if (loading || !profile) {
|
||||
return (
|
||||
<section className="screen">
|
||||
<div className="center" style={{ flex: 1 }}>
|
||||
<Spinner />
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
const isStaff = mode === 'staff' && (profile.role === 'staff' || profile.role === 'admin');
|
||||
const meId = profile.id;
|
||||
|
||||
async function handleScan(token: string) {
|
||||
setBusy(true);
|
||||
try {
|
||||
if (isStaff) {
|
||||
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.id === meId) {
|
||||
toast('That’s your own lanyard 🙂', 'err');
|
||||
return;
|
||||
}
|
||||
setConnectTarget({ profile: 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');
|
||||
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">{isStaff ? 'Check-in' : 'Scan'}</div>
|
||||
<div className="muted small">{isStaff ? 'Scan attendees to check them in' : 'Scan a peer’s lanyard to connect'}</div>
|
||||
</div>
|
||||
<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>
|
||||
|
||||
{isStaff && (
|
||||
<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.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={isStaff ? 'Point at an attendee’s lanyard' : 'Point at a peer’s lanyard'} />
|
||||
{busy && <div className="center"><Spinner /></div>}
|
||||
{isStaff && 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.profile.full_name} id={connectTarget.profile.id} size={72} fs={26} />
|
||||
<h3 style={{ marginTop: 12 }}>{connectTarget.profile.full_name}</h3>
|
||||
<div className="sub">{connectTarget.profile.company ?? ''}</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>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user