- registrations.type is now a Postgres ENUM (registration_type) - session_speakers trigger auto-promotes attendee -> speaker (never overrides staff/sponsor) - new welcome_checkin RPC: staff marks an attendee present at the event - admin Registrations: QR token is final (no reset); failed sponsor change opens in-place sponsor lookup - Convivo Home: Now/Next cards always render; red pending-material pill + popup for speakers - Convivo Agenda: speakers can delete their material to re-upload - Convivo Scan: staff Session/Welcome check-in toggle (uiverse switch) - seed: staff (Bruno/Rita) get a password so staff QR login works after reset 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]>
252 lines
9.2 KiB
TypeScript
252 lines
9.2 KiB
TypeScript
import { useEffect, useRef, useState } from 'react';
|
||
import { useAuth } from '../context/AuthContext';
|
||
import { useEvent } from '../lib/useEvent';
|
||
import {
|
||
clearPreference,
|
||
getMyCheckins,
|
||
getMyPreferences,
|
||
getMySpeakerSessions,
|
||
removeSessionMaterial,
|
||
sessionMaterialUrl,
|
||
setPreference,
|
||
uploadSessionMaterial,
|
||
} 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 { contact } = useAuth();
|
||
const { event, slots, now, loading, reload } = useEvent();
|
||
const [prefs, setPrefs] = useState<Preference[]>([]);
|
||
const [checkins, setCheckins] = useState<string[]>([]);
|
||
const [mySpeakerSessions, setMySpeakerSessions] = useState<string[]>([]);
|
||
const [selected, setSelected] = useState<Session | null>(null);
|
||
const fileRef = useRef<HTMLInputElement>(null);
|
||
const { toast } = useToast();
|
||
|
||
const email = contact?.email ?? '';
|
||
|
||
useEffect(() => {
|
||
let active = true;
|
||
(async () => {
|
||
try {
|
||
const [p, c, sp] = await Promise.all([
|
||
getMyPreferences(),
|
||
getMyCheckins(email),
|
||
getMySpeakerSessions(email),
|
||
]);
|
||
if (!active) return;
|
||
setPrefs(p);
|
||
setCheckins(c);
|
||
setMySpeakerSessions(sp);
|
||
} catch {
|
||
/* non-fatal */
|
||
}
|
||
})();
|
||
return () => {
|
||
active = false;
|
||
};
|
||
}, [email]);
|
||
|
||
if (loading) {
|
||
return (
|
||
<section className="screen">
|
||
<div className="center" style={{ flex: 1 }}>
|
||
<Spinner />
|
||
</div>
|
||
</section>
|
||
);
|
||
}
|
||
|
||
if (!event) {
|
||
return (
|
||
<section className="screen">
|
||
<div className="h1">Agenda</div>
|
||
<div className="card" style={{ marginTop: 16 }}>
|
||
<div className="empty">
|
||
<div className="big">📅</div>
|
||
No active event right now.
|
||
</div>
|
||
</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;
|
||
const selISpeaker = selected ? mySpeakerSessions.includes(selected.id) : false;
|
||
const selNeedsMaterial = selISpeaker && !selected?.material_path;
|
||
|
||
async function handleUpload(e: React.ChangeEvent<HTMLInputElement>) {
|
||
const file = e.target.files?.[0];
|
||
if (!file || !selected) return;
|
||
try {
|
||
await uploadSessionMaterial(selected.id, file);
|
||
toast('Material uploaded ✓', 'ok');
|
||
setSelected(null);
|
||
// Refresh agenda so material_path updates.
|
||
reload();
|
||
} catch (err) {
|
||
toast(err instanceof Error ? err.message : 'Upload failed', 'err');
|
||
} finally {
|
||
if (fileRef.current) fileRef.current.value = '';
|
||
}
|
||
}
|
||
|
||
async function handleDeleteMaterial() {
|
||
if (!selected) return;
|
||
if (!confirm('Remove this material? You can upload a new one.')) return;
|
||
try {
|
||
await removeSessionMaterial(selected.id);
|
||
toast('Material removed', 'ok');
|
||
setSelected(null);
|
||
reload();
|
||
} catch (err) {
|
||
toast(err instanceof Error ? err.message : 'Could not remove material', 'err');
|
||
}
|
||
}
|
||
|
||
return (
|
||
<section className="screen">
|
||
<div className="row between">
|
||
<div>
|
||
<div className="h1">Agenda</div>
|
||
<div className="muted small">{event.name}</div>
|
||
</div>
|
||
<span className="pill violet">{slots.length} slots</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} <span className={`pill slot-type-${slot.type}`}>{slot.type.replace('_', ' ')}</span>
|
||
</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;
|
||
const isMySession = mySpeakerSessions.includes(s.id);
|
||
return (
|
||
<button key={s.id} className={`sess ${picked ? 'picked' : ''}`} onClick={() => setSelected(s)}>
|
||
<div className="grow">
|
||
<div className="title">
|
||
{s.title}
|
||
{isMySession && <span className="pill speaker-tag" style={{ marginLeft: 6 }}>🎤 you</span>}
|
||
</div>
|
||
<div className="meta">
|
||
{s.room} · {s.speakers}
|
||
{s.material_path && <span style={{ marginLeft: 6 }}>📎</span>}
|
||
</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, flexWrap: 'wrap' }}>
|
||
<span className="pill">🎤 {selected.speakers}</span>
|
||
{selected.capacity && <span className="pill">👥 {selected.capacity}</span>}
|
||
{selCheckedIn && <span className="pill green">✓ Checked in</span>}
|
||
</div>
|
||
|
||
{/* Speaker material: non-dismissible notification until uploaded. */}
|
||
{selNeedsMaterial && (
|
||
<div className="material-notice">
|
||
<div className="mn-title">📎 Upload your session material</div>
|
||
<div className="muted small" style={{ marginBottom: 10 }}>
|
||
Attendees can download your slides/notes from this session.
|
||
</div>
|
||
<input ref={fileRef} type="file" className="input" onChange={handleUpload} />
|
||
</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>
|
||
{/* Material download (all attendees) — pinned to the bottom. */}
|
||
{selected.material_path && (
|
||
<a className="btn primary" href={sessionMaterialUrl(selected.material_path)} target="_blank" rel="noreferrer">
|
||
📎 Download material
|
||
</a>
|
||
)}
|
||
{/* Speakers can remove their own material to re-upload. */}
|
||
{selISpeaker && selected.material_path && (
|
||
<button className="btn danger" onClick={handleDeleteMaterial}>
|
||
🗑 Remove material
|
||
</button>
|
||
)}
|
||
</div>
|
||
</>
|
||
)}
|
||
</Sheet>
|
||
</section>
|
||
);
|
||
}
|