Files
Convivo/apps/convivo/src/screens/Agenda.tsx
T
d5ec009cb5 Add Playwright E2E suite (46 tests) + app testids + test_cases.md
- e2e/: full Playwright suite covering every spec case (staff auth/UI,
  welcome + session check-in, attendee access/gating, connections,
  profile visibility, speaker material, sponsor, feedback, E2E journeys,
  role security matrix). 46/46 passing.
- apps/convivo: add data-testid attributes (gate, tabs, scanner, toggles)
  to support the E2E suite.
- test_cases.md: spec-case-to-test coverage map (all cases fully covered).
- .gitignore: ignore e2e node_modules/reports/test-results.

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-09-09 10:13:26 +02:00

289 lines
11 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, 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 { capWords, 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 selIsService = selSlot?.type === 'service_session';
// Service sessions have no material requirement (and no mic), so the
// pending-material notice never applies to them.
const selNeedsMaterial = selISpeaker && !selected?.material_path && !selIsService;
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}`}>{capWords(slot.type)}</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);
const isService = slot.type === 'service_session';
return (
<button key={s.id} className={`sess ${picked ? 'picked' : ''}`} onClick={() => setSelected(s)}>
<div className="grow">
<div className="title">
{s.title}
{isMySession && !isService && (
<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>
{!isService && <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">{selIsService ? '' : '🎤 '}{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" data-testid="material-upload-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" data-testid="material-upload" className="input" onChange={handleUpload} />
</div>
)}
{/* Speaker feedback: visible only after the session is over. */}
{selISpeaker && selStatus === 'done' && (
<div className="feedback-review">
<div className="fr-title">⭐ Your session feedback</div>
{selected.average_feedback != null ? (
<div className="fr-rating">
<span className="fr-stars">
{[1, 2, 3, 4, 5].map((n) => (
<span key={n} className={n <= Math.round(selected.average_feedback!) ? 'on' : ''}>★</span>
))}
</span>
<span className="fr-num">{selected.average_feedback.toFixed(1)}</span>
</div>
) : (
<div className="muted small">No feedback yet.</div>
)}
{selected.ai_generated_feedback && (
<div className="fr-summary">
<div className="muted small" style={{ fontWeight: 700, marginBottom: 4 }}>AI summary</div>
<div style={{ lineHeight: 1.5 }}>{selected.ai_generated_feedback}</div>
</div>
)}
</div>
)}
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
{selStatus === 'done' && selCheckedIn && (
<button className="btn primary" data-testid="give-feedback" 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>
)}
{selSlot.type === 'service_session' ? (
<div className="muted small" style={{ textAlign: 'center' }}>
No pick needed for this slot.
</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>
);
}