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:
45 files changed
+6922

No files matched your search

+159
View File
@@ -0,0 +1,159 @@
import { useEffect, useState } from 'react';
import { useEvent } from '../lib/useEvent';
import { clearPreference, getMyCheckins, getMyPreferences, setPreference } from '../lib/api';
import { fmtRange, slotStatus } from '../lib/time';
import type { Preference, Session } from '../lib/types';
import { Sheet, Spinner } from '../components/ui';
import { useToast } from '../context/ToastContext';
export function Agenda({ openFeedback }: { openFeedback: (sessionId: string) => void }) {
const { slots, now, loading } = useEvent();
const [prefs, setPrefs] = useState<Preference[]>([]);
const [checkins, setCheckins] = useState<string[]>([]);
const [selected, setSelected] = useState<Session | null>(null);
const { toast } = useToast();
useEffect(() => {
let active = true;
(async () => {
try {
const [p, c] = await Promise.all([getMyPreferences(), getMyCheckins()]);
if (!active) return;
setPrefs(p);
setCheckins(c);
} catch {
/* non-fatal */
}
})();
return () => {
active = false;
};
}, []);
if (loading) {
return (
<section className="screen">
<div className="center" style={{ flex: 1 }}>
<Spinner />
</div>
</section>
);
}
const pickFor = (slotId: number) => prefs.find((p) => p.slot_id === slotId)?.session_id;
async function togglePick(slotId: number, sessionId: string) {
const current = pickFor(slotId);
try {
if (current === sessionId) {
await clearPreference(slotId);
toast('Pick removed');
} else {
await setPreference(sessionId);
toast('Pick saved ✓', 'ok');
}
const p = await getMyPreferences();
setPrefs(p);
} catch (e) {
toast(e instanceof Error ? e.message : 'Could not update pick', 'err');
}
}
const selSlot = selected ? slots.find((s) => s.slot.id === selected.slot_id)?.slot : undefined;
const selStatus = selSlot ? slotStatus(selSlot, now) : 'next';
const selCheckedIn = selected ? checkins.includes(selected.id) : false;
return (
<section className="screen">
<div className="row between">
<div>
<div className="h1">Agenda</div>
<div className="muted small">Wed 23 Oct · 09:00–17:00</div>
</div>
<span className="pill violet">6 slots · 3 tracks</span>
</div>
<div className="muted small" style={{ marginTop: -4 }}>
Pick <b>one session per slot</b> — you can change until the slot starts.
</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
{slots.map(({ slot, sessions }) => {
const status = slotStatus(slot, now);
return (
<div className="slot-card" key={slot.id}>
<div className="slot-head">
<div className="grow">
<div className="name">{slot.name}</div>
<div className="time">{fmtRange(slot)}</div>
</div>
{status === 'done' && <span className="pill">Done</span>}
{status === 'now' && <span className="pill violet">● Live</span>}
{status === 'next' && <span className="pill cyan">Up next</span>}
</div>
{sessions.map((s) => {
const picked = pickFor(slot.id) === s.id;
return (
<button
key={s.id}
className={`sess ${picked ? 'picked' : ''}`}
onClick={() => setSelected(s)}
>
<div className="grow">
<div className="title">{s.title}</div>
<div className="meta">
{s.room} · {s.speakers}
</div>
</div>
<span className="check">✓</span>
</button>
);
})}
</div>
);
})}
</div>
<Sheet open={!!selected} onClose={() => setSelected(null)}>
{selected && selSlot && (
<>
<div className="row between">
<div>
<h3>{selected.title}</h3>
<div className="sub">
{selSlot.name} · {fmtRange(selSlot)} · {selected.room}
</div>
</div>
<button className="btn ghost small" onClick={() => setSelected(null)}>✕</button>
</div>
<div className="muted small" id="sd-desc" style={{ margin: '12px 0', lineHeight: 1.55 }}>
{selected.description}
</div>
<div className="row" style={{ gap: 8, marginBottom: 14 }}>
<span className="pill">🎤 {selected.speakers}</span>
{selected.capacity && <span className="pill">👥 {selected.capacity}</span>}
{selCheckedIn && <span className="pill green">✓ Checked in</span>}
</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
{selStatus === 'done' && selCheckedIn && (
<button className="btn primary" onClick={() => openFeedback(selected.id)}>
Give feedback ⭐
</button>
)}
{selStatus === 'done' && !selCheckedIn && (
<div className="muted small" style={{ textAlign: 'center' }}>
You weren’t checked in to this session.
</div>
)}
<button
className={`btn ${pickFor(selected.slot_id) === selected.id ? 'danger' : 'primary'}`}
onClick={() => togglePick(selected.slot_id, selected.id)}
>
{pickFor(selected.slot_id) === selected.id ? 'Remove my pick' : 'Pick this session'}
</button>
</div>
</>
)}
</Sheet>
</section>
);
}
+131
View File
@@ -0,0 +1,131 @@
import { useCallback, useEffect, useState } from 'react';
import { useAuth } from '../context/AuthContext';
import { acceptConnection, getMyConnections, getPublicProfiles, rejectConnection } from '../lib/api';
import type { Connection, PublicProfile } from '../lib/types';
import { Avatar, Empty, Spinner } from '../components/ui';
import { useToast } from '../context/ToastContext';
export function Connections() {
const { profile } = useAuth();
const [tab, setTab] = useState<'mine' | 'req'>('mine');
const [conns, setConns] = useState<Connection[]>([]);
const [people, setPeople] = useState<Map<string, PublicProfile>>(new Map());
const [loading, setLoading] = useState(true);
const { toast } = useToast();
const load = useCallback(async () => {
try {
const [c, p] = await Promise.all([getMyConnections(), getPublicProfiles()]);
setConns(c);
setPeople(new Map(p.map((x) => [x.id, x])));
} catch {
/* non-fatal */
} finally {
setLoading(false);
}
}, []);
useEffect(() => {
void load();
}, [load]);
if (!profile) return null;
const me = profile.id;
const nameOf = (id: string) => people.get(id)?.full_name ?? '…';
const companyOf = (id: string) => people.get(id)?.company ?? '';
const accepted = conns.filter((c) => c.status === 'accepted');
const incoming = conns.filter((c) => c.status === 'pending' && c.to_id === me);
const outgoing = conns.filter((c) => c.status === 'pending' && c.from_id === me);
async function resolve(id: string, accept: boolean) {
try {
if (accept) await acceptConnection(id);
else await rejectConnection(id);
toast(accept ? 'Connected! +5 pts 🤝' : 'Request declined', accept ? 'ok' : '');
await load();
} catch (e) {
toast(e instanceof Error ? e.message : 'Could not update request', 'err');
}
}
if (loading) {
return (
<section className="screen">
<div className="center" style={{ flex: 1 }}>
<Spinner />
</div>
</section>
);
}
return (
<section className="screen">
<div className="h1">Connections</div>
<div className="seg">
<button className={tab === 'mine' ? 'active' : ''} onClick={() => setTab('mine')}>My connections</button>
<button className={tab === 'req' ? 'active' : ''} onClick={() => setTab('req')}>
Requests {incoming.length + outgoing.length > 0 && <span className="pill violet" style={{ marginLeft: 4 }}>{incoming.length + outgoing.length}</span>}
</button>
</div>
{tab === 'mine' &&
(accepted.length === 0 ? (
<Empty icon="🤝" text="No connections yet. Scan a peer’s lanyard to start one." />
) : (
accepted.map((c) => {
const otherId = c.from_id === me ? c.to_id : c.from_id;
return (
<div className="conn" key={c.id}>
<Avatar name={nameOf(otherId)} id={otherId} size={44} />
<div className="grow">
<div className="name">{nameOf(otherId)}</div>
<div className="meta">{companyOf(otherId)}</div>
</div>
<span className="pill green">Connected</span>
</div>
);
})
))}
{tab === 'req' && (
<div style={{ display: 'flex', flexDirection: 'column', gap: 14 }}>
{incoming.length === 0 && outgoing.length === 0 && (
<Empty icon="📭" text="No pending requests." />
)}
{incoming.length > 0 && (
<div>
<div className="muted small" style={{ marginBottom: 8, fontWeight: 700 }}>Incoming</div>
{incoming.map((c) => (
<div className="conn" key={c.id}>
<Avatar name={nameOf(c.from_id)} id={c.from_id} size={44} />
<div className="grow">
<div className="name">{nameOf(c.from_id)}</div>
<div className="meta">{companyOf(c.from_id)}</div>
</div>
<button className="btn primary small" onClick={() => resolve(c.id, true)}>Accept</button>
<button className="btn small" onClick={() => resolve(c.id, false)}>Decline</button>
</div>
))}
</div>
)}
{outgoing.length > 0 && (
<div>
<div className="muted small" style={{ marginBottom: 8, fontWeight: 700 }}>Sent</div>
{outgoing.map((c) => (
<div className="conn" key={c.id}>
<Avatar name={nameOf(c.to_id)} id={c.to_id} size={44} />
<div className="grow">
<div className="name">{nameOf(c.to_id)}</div>
<div className="meta">{companyOf(c.to_id)}</div>
</div>
<span className="pill amber">Pending</span>
</div>
))}
</div>
)}
</div>
)}
</section>
);
}
+105
View File
@@ -0,0 +1,105 @@
import { useEffect, useState } from 'react';
import { useAuth } from '../context/AuthContext';
import { useEvent } from '../lib/useEvent';
import { getMyFeedback, submitFeedback } from '../lib/api';
import { fmtRange } from '../lib/time';
import { Spinner } from '../components/ui';
import { useToast } from '../context/ToastContext';
export function Feedback({ sessionId, onDone }: { sessionId: string; onDone: () => void }) {
const { refreshProfile } = useAuth();
const { sessionById, slotById, loading } = useEvent();
const [rating, setRating] = useState(0);
const [comment, setComment] = useState('');
const [existing, setExisting] = useState<{ rating: number; comment: string | null } | null>(null);
const [busy, setBusy] = useState(false);
const [done, setDone] = useState<{ earned: number } | null>(null);
const { toast } = useToast();
const session = sessionById.get(sessionId);
const slot = session ? slotById.get(session.slot_id) : undefined;
useEffect(() => {
let active = true;
(async () => {
try {
const fb = await getMyFeedback();
const mine = fb.find((f) => f.session_id === sessionId);
if (active && mine) setExisting({ rating: mine.rating, comment: mine.comment });
} catch {
/* non-fatal */
}
})();
return () => {
active = false;
};
}, [sessionId]);
if (loading || !session || !slot) {
return (
<section className="screen no-tab">
<div className="center" style={{ flex: 1 }}>
<Spinner />
</div>
</section>
);
}
async function submit() {
if (rating < 1) return;
setBusy(true);
try {
const res = await submitFeedback(sessionId, rating, comment.trim());
await refreshProfile();
setDone({ earned: res.earned });
} catch (e) {
toast(e instanceof Error ? e.message : 'Could not submit feedback', 'err');
} finally {
setBusy(false);
}
}
if (done) {
return (
<section className="screen no-tab">
<div className="card success-box">
<div className="emoji">🎉</div>
<h3>{done.earned > 0 ? `+${done.earned} pts earned!` : 'Feedback updated!'}</h3>
<p>Thanks for the feedback — it helps everyone pick better sessions.</p>
<button className="btn primary" style={{ marginTop: 20 }} onClick={onDone}>Back to Home</button>
</div>
</section>
);
}
return (
<section className="screen no-tab">
<button className="btn ghost small" style={{ alignSelf: 'flex-start' }} onClick={onDone}>← Back</button>
<div className="card" style={{ textAlign: 'center' }}>
<div className="muted small">{slot.name} · {fmtRange(slot)} · {session.room}</div>
<div className="h2" style={{ marginTop: 4 }}>{session.title}</div>
<div className="h1" style={{ marginTop: 18, fontSize: 22 }}>How was it? ⭐</div>
<div className="stars">
{[1, 2, 3, 4, 5].map((n) => (
<button key={n} className={`star ${rating >= n ? 'on' : ''}`} onClick={() => setRating(n)}>★</button>
))}
</div>
<div className="muted small" style={{ marginBottom: 10 }}>
{rating > 0 ? `${rating} star${rating > 1 ? 's' : ''}` : 'Tap a star'}
</div>
<textarea
className="input"
placeholder="What did you think? (bonus points for details)"
value={comment}
onChange={(e) => setComment(e.target.value)}
/>
<div className="muted small" style={{ marginTop: 10, textAlign: 'center' }}>
Rating: <b>+5 pts</b> · With comments: <b>+10 pts</b>
</div>
</div>
<button className="btn primary" disabled={busy || rating < 1} onClick={submit}>
{busy ? 'Submitting…' : existing ? 'Update feedback' : 'Submit feedback'}
</button>
</section>
);
}
+138
View File
@@ -0,0 +1,138 @@
import { useEffect, useState } from 'react';
import { useAuth } from '../context/AuthContext';
import { useEvent } from '../lib/useEvent';
import { getMyCheckins, getMyPreferences } from '../lib/api';
import { fmtRange, greeting, slotStatus } from '../lib/time';
import type { Preference } from '../lib/types';
import { Avatar, Spinner } from '../components/ui';
export function Home({ go }: { go: (tab: string) => void }) {
const { profile } = useAuth();
const { slots, sessionById, now, loading } = useEvent();
const [prefs, setPrefs] = useState<Preference[]>([]);
const [checkins, setCheckins] = useState<string[]>([]);
useEffect(() => {
let active = true;
(async () => {
try {
const [p, c] = await Promise.all([getMyPreferences(), getMyCheckins()]);
if (!active) return;
setPrefs(p);
setCheckins(c);
} catch {
/* non-fatal */
}
})();
return () => {
active = false;
};
}, []);
if (loading || !profile) {
return (
<section className="screen">
<div className="center" style={{ flex: 1 }}>
<Spinner />
</div>
</section>
);
}
const pickFor = (slotId: number) => prefs.find((p) => p.slot_id === slotId)?.session_id;
const current = slots.find(({ slot }) => slotStatus(slot, now) === 'now');
const next = slots.find(({ slot }) => slotStatus(slot, now) === 'next');
const nowSession = current ? sessionById.get(pickFor(current.slot.id) ?? '') : undefined;
const nextSession = next ? sessionById.get(pickFor(next.slot.id) ?? '') : undefined;
const firstName = profile.full_name.split(' ')[0];
return (
<section className="screen">
<div className="row between">
<div>
<div className="h1">{greeting(now)}, {firstName} 👋</div>
<div className="muted small">Wed 23 Oct · Convivo Conf</div>
</div>
<div className="points-pill" onClick={() => go('leaderboard')}>⚡ {profile.points}</div>
</div>
{nowSession && current && (
<div className="card now-card">
<div className="row between">
<span className="pill violet">● Now</span>
<span className="muted small">{fmtRange(current.slot)}</span>
</div>
<div className="h2" style={{ marginTop: 10 }}>{nowSession.title}</div>
<div className="muted small" style={{ marginTop: 3 }}>
{nowSession.room} · {nowSession.speakers}
</div>
{checkins.includes(nowSession.id) ? (
<span className="pill green" style={{ marginTop: 10 }}>✓ Checked in</span>
) : (
<span className="pill amber" style={{ marginTop: 10 }}>Show your QR to staff to check in</span>
)}
</div>
)}
{nextSession && next && (
<div className="card">
<div className="row between">
<span className="pill cyan">Next</span>
<span className="muted small">{fmtRange(next.slot)}</span>
</div>
<div className="h2" style={{ marginTop: 10 }}>{nextSession.title}</div>
<div className="muted small" style={{ marginTop: 3 }}>
{nextSession.room} · {nextSession.speakers}
</div>
</div>
)}
<div>
<div className="row between" style={{ marginBottom: 9 }}>
<span className="h2">My picks today</span>
<span className="muted small">tap to change</span>
</div>
<div style={{ display: 'flex', flexDirection: 'column' }}>
{slots.map(({ slot }) => {
const sid = pickFor(slot.id);
const s = sid ? sessionById.get(sid) : undefined;
return (
<button key={slot.id} className="pick-chip" onClick={() => go('agenda')}>
<span className="t">{fmtRange(slot)}</span>
<span className="grow" style={{ fontWeight: 600, textAlign: 'left' }}>
{s ? s.title : 'No pick yet'}
</span>
{s && <span className="muted small">{s.room}</span>}
</button>
);
})}
</div>
</div>
<div className="qa-grid">
<div className="qa" onClick={() => go('scan')}>
<span className="ico">📷</span>
<span className="lbl">{profile.role === 'staff' ? 'Check-in' : 'Scan & connect'}</span>
</div>
<div className="qa" onClick={() => go('agenda')}>
<span className="ico">📅</span>
<span className="lbl">Agenda</span>
</div>
<div className="qa" onClick={() => go('connections')}>
<span className="ico">🤝</span>
<span className="lbl">Connections</span>
</div>
<div className="qa" onClick={() => go('leaderboard')}>
<span className="ico">🏆</span>
<span className="lbl">Leaderboard</span>
</div>
</div>
<div style={{ height: 8 }} />
<div className="muted small" style={{ textAlign: 'center', opacity: 0.5 }}>
<Avatar name={profile.full_name} id={profile.id} size={22} fs={9} /> {profile.company ?? ''}
</div>
</section>
);
}
+108
View File
@@ -0,0 +1,108 @@
import { useEffect, useState } from 'react';
import { useAuth } from '../context/AuthContext';
import { supabase } from '../lib/supabase';
import { getLeaderboard } from '../lib/api';
import type { LeaderboardRow } from '../lib/types';
import { Avatar, Spinner } from '../components/ui';
export function Leaderboard() {
const { profile } = useAuth();
const [rows, setRows] = useState<LeaderboardRow[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
let active = true;
(async () => {
try {
const data = await getLeaderboard();
if (active) setRows(data);
} catch {
/* non-fatal */
} finally {
if (active) setLoading(false);
}
})();
// Live updates: re-fetch on any leaderboard change (points are synced
// transactionally by the RPCs, so the table is always consistent).
const channel = supabase
.channel('leaderboard-live')
.on('postgres_changes', { event: '*', schema: 'public', table: 'leaderboard' }, () => {
getLeaderboard().then((d) => active && setRows(d)).catch(() => {});
})
.subscribe();
return () => {
active = false;
supabase.removeChannel(channel);
};
}, []);
if (loading) {
return (
<section className="screen">
<div className="center" style={{ flex: 1 }}>
<Spinner />
</div>
</section>
);
}
const me = profile?.id;
const top3 = rows.slice(0, 3);
const rest = rows.slice(3);
const myRank = rows.findIndex((r) => r.profile_id === me) + 1;
return (
<section className="screen">
<div className="row between">
<div>
<div className="h1">Leaderboard</div>
<div className="muted small">All attendees · by points</div>
</div>
<span className="pill green">● Live</span>
</div>
{top3.length > 0 && (
<div className="podium">
{[1, 0, 2].map((idx) => {
const r = top3[idx];
if (!r) return <div key={idx} style={{ width: 96 }} />;
const cls = idx === 0 ? 'b1' : idx === 1 ? 'b2' : 'b3';
return (
<div className="pod" key={r.profile_id}>
<div className={`bar ${cls}`}>{r.points}</div>
<div className="pname">{r.full_name.split(' ')[0]}</div>
<div className="ppoints">#{idx + 1}</div>
</div>
);
})}
</div>
)}
<div style={{ display: 'flex', flexDirection: 'column' }}>
{rest.map((r, i) => {
const rank = i + 4;
const isMe = r.profile_id === me;
return (
<div className={`lb-row ${isMe ? 'me' : ''}`} key={r.profile_id}>
<span className="rank">{rank}</span>
<Avatar name={r.full_name} id={r.profile_id} size={38} fs={13} />
<div className="grow">
<div style={{ fontWeight: 700, fontSize: 14 }}>{r.full_name} {isMe && <span className="muted small">(you)</span>}</div>
<div className="muted small">{r.company ?? ''}</div>
</div>
<span className="pts">{r.points}</span>
</div>
);
})}
</div>
{myRank > 0 && (
<div className="muted small" style={{ textAlign: 'center', marginTop: 6 }}>
You’re ranked <b>#{myRank}</b> of {rows.length}
</div>
)}
</section>
);
}
+120
View File
@@ -0,0 +1,120 @@
import { useState } from 'react';
import { supabase } from '../lib/supabase';
import { lanyardLookup } from '../lib/api';
import type { PublicProfile } from '../lib/types';
import { Avatar, Scanner } from '../components/ui';
import { useToast } from '../context/ToastContext';
type Step = 'splash' | 'scan' | 'confirm';
export function Login() {
const [step, setStep] = useState<Step>('splash');
const [qrToken, setQrToken] = useState('');
const [found, setFound] = useState<PublicProfile | null>(null);
const [email, setEmail] = useState('');
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const { toast } = useToast();
async function handleScan(text: string) {
const token = text.trim();
if (!token) return;
setQrToken(token);
setError(null);
try {
const profile = await lanyardLookup(token);
setFound(profile);
if (!profile) toast('No attendee found for that code', 'err');
} catch {
setFound(null);
}
setStep('confirm');
}
async function confirm() {
if (!email.trim() || !qrToken) return;
setBusy(true);
setError(null);
try {
const { data, error: err } = await supabase.auth.signInWithPassword({
email: email.trim(),
password: qrToken,
});
if (err) {
setError('Email and QR code do not match. Please try again.');
toast('Login failed', 'err');
} else if (data.session) {
toast('Welcome back! 🎉', 'ok');
}
} catch (e) {
setError(e instanceof Error ? e.message : 'Login failed');
} finally {
setBusy(false);
}
}
if (step === 'splash') {
return (
<section className="screen no-tab splash" onClick={() => setStep('scan')}>
<div className="logo">C</div>
<div className="splash-title">Convivo</div>
<div className="splash-tag">Break the ice. Earn the points.</div>
<div className="tap-hint">Tap anywhere to continue</div>
</section>
);
}
if (step === 'scan') {
return (
<section className="screen no-tab">
<div className="h1">Welcome back 👋</div>
<div className="muted small">Scan the QR code on your lanyard to log in.</div>
<Scanner onResult={handleScan} label="Point your camera at your lanyard QR" />
<div className="muted small" style={{ textAlign: 'center', opacity: 0.6 }}>
Demo: type <b>CVV-ANA-4821</b> (Ana) or <b>CVV-BRU-1177</b> (Bruno, staff)
</div>
</section>
);
}
return (
<section className="screen no-tab">
<div className="row" style={{ gap: 14 }}>
{found ? (
<Avatar name={found.full_name} id={found.id} size={64} fs={22} />
) : (
<span className="avatar" style={{ width: 64, height: 64, fontSize: 22, background: '#8a8484' }}>?</span>
)}
<div>
<div className="h2">{found ? found.full_name : 'Lanyard found'}</div>
<div className="muted small">{found ? found.company ?? '' : 'Confirm it’s you'}</div>
</div>
</div>
<div className="card">
<div className="h2" style={{ marginBottom: 6 }}>Confirm it’s you</div>
<div className="muted small" style={{ marginBottom: 12 }}>
Enter the email address you used when you bought your ticket.
</div>
<input
className="input"
type="email"
placeholder="[email protected]"
value={email}
onChange={(e) => setEmail(e.target.value)}
onKeyDown={(e) => e.key === 'Enter' && confirm()}
autoComplete="off"
/>
</div>
{error && <div className="muted small" style={{ color: 'var(--red)' }}>{error}</div>}
<button className="btn primary" disabled={busy || !email.trim()} onClick={confirm}>
{busy ? 'Checking…' : 'Confirm & enter →'}
</button>
<button className="btn ghost small" style={{ alignSelf: 'flex-start' }} onClick={() => setStep('scan')}>
← Different lanyard
</button>
<div className="muted small" style={{ textAlign: 'center', opacity: 0.6 }}>
Demo: <b>ana.silva@nubank.com</b> · <b>bruno.costa@acme.com</b>
</div>
</section>
);
}
+91
View File
@@ -0,0 +1,91 @@
import { useEffect, useState } from 'react';
import { useAuth } from '../context/AuthContext';
import { getMyPointsLog } from '../lib/api';
import type { PointsLogRow } from '../lib/types';
import { Avatar, QrImage, Spinner } from '../components/ui';
const CATEGORY_LABEL: Record<PointsLogRow['category'], string> = {
checkin: 'Session check-ins',
connection: 'Connections',
feedback: 'Feedback',
admin: 'Other',
};
export function Profile() {
const { profile, signOut } = useAuth();
const [log, setLog] = useState<PointsLogRow[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
let active = true;
(async () => {
try {
const data = await getMyPointsLog();
if (active) setLog(data);
} catch {
/* non-fatal */
} finally {
if (active) setLoading(false);
}
})();
return () => {
active = false;
};
}, []);
if (!profile) return null;
const totals: Record<string, number> = {};
for (const l of log) totals[l.category] = (totals[l.category] ?? 0) + l.delta;
return (
<section className="screen">
<div className="h1">Profile</div>
<div className="card" style={{ textAlign: 'center' }}>
<Avatar name={profile.full_name} id={profile.id} size={72} fs={26} />
<div className="h2" style={{ marginTop: 10 }}>{profile.full_name}</div>
<div className="muted small">{profile.company ?? ''}</div>
<div className="row" style={{ justifyContent: 'center', marginTop: 10, gap: 8 }}>
<span className="pill violet">{profile.role}</span>
<span className="pill amber">⚡ {profile.points} pts</span>
</div>
</div>
<div className="card qr-wrap">
<div className="h2">My QR code</div>
{profile.qr_token ? (
<QrImage value={profile.qr_token} size={180} />
) : (
<div className="muted small">No QR token assigned.</div>
)}
<div className="muted small" style={{ textAlign: 'center' }}>
Show this to <b>staff</b> for session check-in<br />and to <b>peers</b> to make a connection.
</div>
</div>
<div className="card">
<div className="h2" style={{ marginBottom: 6 }}>Points breakdown</div>
{loading ? (
<div className="center" style={{ padding: 12 }}>
<Spinner />
</div>
) : (
<>
{Object.entries(totals).map(([cat, val]) => (
<div className="break-row" key={cat}>
<span>{CATEGORY_LABEL[cat as PointsLogRow['category']] ?? cat}</span>
<span className="v">+{val}</span>
</div>
))}
<div className="break-row">
<span style={{ fontWeight: 700 }}>Total</span>
<span className="v">{profile.points}</span>
</div>
</>
)}
</div>
<button className="btn danger" onClick={() => void signOut()}>Log out</button>
</section>
);
}
+163
View File
@@ -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>
);
}