- 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]>
280 lines
10 KiB
TypeScript
280 lines
10 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import { useAuth } from '../context/AuthContext';
|
|
import { useEvent } from '../lib/useEvent';
|
|
import { getMyCheckins, getMyFeedback, getMyPreferences, getMySpeakerSessions } from '../lib/api';
|
|
import { fmtRange, greeting, slotStatus } from '../lib/time';
|
|
import type { Feedback, Preference, Session } from '../lib/types';
|
|
import { Sheet, Spinner } from '../components/ui';
|
|
|
|
/** A single session block inside the Now/Next card (title + room + speaker). */
|
|
function SessionBlock({ session, checkedIn }: { session: Session; checkedIn?: boolean }) {
|
|
return (
|
|
<>
|
|
<div className="h2" style={{ marginTop: 10 }}>{session.title}</div>
|
|
<div className="muted small" style={{ marginTop: 3 }}>
|
|
{session.room} · {session.speakers}
|
|
</div>
|
|
{checkedIn !== undefined && (
|
|
checkedIn ? (
|
|
<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>
|
|
)
|
|
)}
|
|
</>
|
|
);
|
|
}
|
|
|
|
/** The list of concurrent sessions shown when the user has no pick for the slot. */
|
|
function ConcurrentList({ sessions }: { sessions: Session[] }) {
|
|
return (
|
|
<div className="now-list">
|
|
{sessions.map((s) => (
|
|
<div key={s.id} className="now-item">
|
|
<div className="t">{s.title}</div>
|
|
<div className="muted small">{s.room} · {s.speakers}</div>
|
|
</div>
|
|
))}
|
|
<div className="muted small" style={{ marginTop: 10 }}>
|
|
No pick yet — tap a session in the Agenda to choose.
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function Home({ go }: { go: (tab: string) => void }) {
|
|
const { contact, registration } = useAuth();
|
|
const { event, slots, sessionById, slotById, now, clockMode, loading } = useEvent();
|
|
const [prefs, setPrefs] = useState<Preference[]>([]);
|
|
const [checkins, setCheckins] = useState<string[]>([]);
|
|
const [mySpeakerSessions, setMySpeakerSessions] = useState<string[]>([]);
|
|
const [myFeedback, setMyFeedback] = useState<Feedback[]>([]);
|
|
const [materialSheetOpen, setMaterialSheetOpen] = useState(false);
|
|
|
|
const email = contact?.email ?? '';
|
|
|
|
useEffect(() => {
|
|
let active = true;
|
|
(async () => {
|
|
try {
|
|
const [p, c, sp, fb] = await Promise.all([
|
|
getMyPreferences(),
|
|
getMyCheckins(email),
|
|
getMySpeakerSessions(email),
|
|
getMyFeedback(email),
|
|
]);
|
|
if (!active) return;
|
|
setPrefs(p);
|
|
setCheckins(c);
|
|
setMySpeakerSessions(sp);
|
|
setMyFeedback(fb);
|
|
} catch {
|
|
/* non-fatal */
|
|
}
|
|
})();
|
|
return () => {
|
|
active = false;
|
|
};
|
|
}, [email]);
|
|
|
|
if (loading || !contact) {
|
|
return (
|
|
<section className="screen">
|
|
<div className="center" style={{ flex: 1 }}>
|
|
<Spinner />
|
|
</div>
|
|
</section>
|
|
);
|
|
}
|
|
|
|
if (!event) {
|
|
return (
|
|
<section className="screen">
|
|
<div className="h1">APPE</div>
|
|
<div className="card" style={{ marginTop: 16 }}>
|
|
<div className="empty">
|
|
<div className="big">📅</div>
|
|
No active event right now. Check back soon!
|
|
</div>
|
|
</div>
|
|
</section>
|
|
);
|
|
}
|
|
|
|
const points = registration?.points ?? 0;
|
|
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 nowPick = current ? sessionById.get(pickFor(current.slot.id) ?? '') : undefined;
|
|
const nextPick = next ? sessionById.get(pickFor(next.slot.id) ?? '') : undefined;
|
|
|
|
// Sessions the signed-in contact speaks in that still have no material uploaded.
|
|
// Service sessions have no material requirement, so they're excluded.
|
|
const pendingMaterial = mySpeakerSessions
|
|
.map((id) => sessionById.get(id))
|
|
.filter((s): s is Session => !!s && !s.material_path && s.slot_type !== 'service_session');
|
|
|
|
// Pending feedback: sessions the contact is checked into that are over, where
|
|
// they are NOT the speaker, and they haven't submitted feedback yet.
|
|
const feedbackPending = checkins
|
|
.map((id) => sessionById.get(id))
|
|
.filter((s): s is Session => !!s)
|
|
.filter((s) => {
|
|
const sl = slotById.get(s.slot_id);
|
|
return !!sl && slotStatus(sl, now) === 'done';
|
|
})
|
|
.filter((s) => !mySpeakerSessions.includes(s.id))
|
|
.filter((s) => !myFeedback.some((f) => f.session_id === s.id));
|
|
|
|
// All of the contact's picks for today, in slot order.
|
|
const picks = prefs
|
|
.map((p) => ({ slot: slotById.get(p.slot_id), session: sessionById.get(p.session_id) }))
|
|
.filter((r): r is { slot: NonNullable<ReturnType<typeof slotById.get>>; session: Session } => !!r.slot && !!r.session)
|
|
.sort((a, b) => a.slot.id - b.slot.id);
|
|
|
|
const firstName = contact.full_name.split(' ')[0];
|
|
|
|
return (
|
|
<section className="screen">
|
|
<div className="row between">
|
|
<div>
|
|
<div className="h1">{greeting(now)}, {firstName} 👋</div>
|
|
<div className="muted small">{event.name}</div>
|
|
{clockMode === 'simulated' && (
|
|
<div className="muted small" style={{ marginTop: 2 }}>
|
|
🎬 Demo clock
|
|
</div>
|
|
)}
|
|
</div>
|
|
<div className="row" style={{ gap: 8 }}>
|
|
{pendingMaterial.length > 0 && (
|
|
<div className="material-pill" data-testid="material-pill" onClick={() => setMaterialSheetOpen(true)}>
|
|
📎 {pendingMaterial.length}
|
|
</div>
|
|
)}
|
|
<div className="points-pill" onClick={() => go('leaderboard')}>⚡ {points}</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Pending feedback: nudge to rate a session they attended. */}
|
|
{feedbackPending.length > 0 && (
|
|
<button className="feedback-pill" data-testid="feedback-pill" onClick={() => go('agenda')}>
|
|
⭐ {feedbackPending.length === 1 ? 'Rate your last session' : `Rate ${feedbackPending.length} sessions`}
|
|
</button>
|
|
)}
|
|
|
|
{/* Now: the current slot. With a pick, show it; without, show everything running. */}
|
|
{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>
|
|
{nowPick ? (
|
|
<SessionBlock session={nowPick} checkedIn={checkins.includes(nowPick.id)} />
|
|
) : current.sessions.length > 0 ? (
|
|
<ConcurrentList sessions={current.sessions} />
|
|
) : (
|
|
<div className="muted small" style={{ marginTop: 10 }}>Nothing scheduled right now.</div>
|
|
)}
|
|
</div>
|
|
)}
|
|
|
|
{/* Next: the upcoming slot. */}
|
|
{next && (
|
|
<div className="card">
|
|
<div className="row between">
|
|
<span className="pill cyan">Next</span>
|
|
<span className="muted small">{fmtRange(next.slot)}</span>
|
|
</div>
|
|
{nextPick ? (
|
|
<SessionBlock session={nextPick} />
|
|
) : next.sessions.length > 0 ? (
|
|
<ConcurrentList sessions={next.sessions} />
|
|
) : (
|
|
<div className="muted small" style={{ marginTop: 10 }}>Nothing scheduled next.</div>
|
|
)}
|
|
</div>
|
|
)}
|
|
|
|
{/* My picks today */}
|
|
<div>
|
|
<div className="row between" style={{ marginBottom: 9 }}>
|
|
<span className="h2">My picks today</span>
|
|
<a className="muted small link" onClick={() => go('agenda')}>tap to change</a>
|
|
</div>
|
|
{picks.length > 0 ? (
|
|
<div style={{ display: 'flex', flexDirection: 'column' }}>
|
|
{picks.map((r) => (
|
|
<button key={r.session.id} className="pick-chip" onClick={() => go('agenda')}>
|
|
<span className="t">{fmtRange(r.slot)}</span>
|
|
<span className="grow" style={{ fontWeight: 600, textAlign: 'left' }}>
|
|
{r.session.title}
|
|
</span>
|
|
{r.session.room && <span className="muted small">{r.session.room}</span>}
|
|
</button>
|
|
))}
|
|
</div>
|
|
) : (
|
|
<div className="muted small" style={{ padding: '10px 2px' }}>
|
|
No picks yet — tap a session in the Agenda to choose.
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
<div className="qa-grid">
|
|
<div className="qa" onClick={() => go('scan')}>
|
|
<span className="ico">📷</span>
|
|
<span className="lbl">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 }} />
|
|
|
|
{/* Pending material popup (speakers only, when a session is missing its attachment) */}
|
|
<Sheet open={materialSheetOpen} onClose={() => setMaterialSheetOpen(false)}>
|
|
<h3 style={{ marginBottom: 4 }}>📎 Pending material</h3>
|
|
<div className="muted small" style={{ marginBottom: 14 }}>
|
|
The following sessions are pending to upload their attachments.
|
|
</div>
|
|
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
|
{pendingMaterial.map((s) => {
|
|
const slot = slots.find((x) => x.slot.id === s.slot_id)?.slot;
|
|
return (
|
|
<button
|
|
key={s.id}
|
|
className="pick-chip"
|
|
onClick={() => {
|
|
setMaterialSheetOpen(false);
|
|
go('agenda');
|
|
}}
|
|
>
|
|
<span className="t">{slot ? fmtRange(slot) : ''}</span>
|
|
<span className="grow" style={{ fontWeight: 600, textAlign: 'left' }}>
|
|
{s.title}
|
|
</span>
|
|
<span className="muted small">{s.room}</span>
|
|
</button>
|
|
);
|
|
})}
|
|
</div>
|
|
<button className="btn primary" style={{ marginTop: 16 }} onClick={() => setMaterialSheetOpen(false)}>
|
|
Got it
|
|
</button>
|
|
</Sheet>
|
|
</section>
|
|
);
|
|
}
|