feat: finalize ticket merging and speaker-aware imports

This commit is contained in:
Lago committed 2026-10-10 13:28:18 +02:00
1 parent 648daa0794
commit 4e71e9b797
35 files changed
+1772 -348

No files matched your search

+53 -8
View File
@@ -1,29 +1,64 @@
import { useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import { supabase } from '../lib/supabase';
import { lanyardLookup } from '../lib/api';
import { capWords } from '../lib/time';
import type { PublicContact } from '../lib/types';
import { Avatar, Scanner } from '../components/ui';
import { useToast } from '../context/ToastContext';
import { useAuth } from '../context/AuthContext';
import { adminLinkFailure, adminLinkNotice, isEmailEntry, requestAdminLink } from '../lib/adminEntry';
type Step = 'splash' | 'scan' | 'confirm';
export function Login() {
const [step, setStep] = useState<Step>('splash');
const { authError } = useAuth();
const [step, setStep] = useState<Step>(authError ? 'scan' : 'splash');
const [qrToken, setQrToken] = useState('');
const [found, setFound] = useState<PublicContact | null>(null);
const [email, setEmail] = useState('');
const [staffPassword, setStaffPassword] = useState('');
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [error, setError] = useState<string | null>(authError);
const [entry, setEntry] = useState('');
const [sent, setSent] = useState(false);
const [cooldown, setCooldown] = useState(0);
const requestPending = useRef(false);
const { toast } = useToast();
useEffect(() => {
if (!cooldown) return;
const timer = window.setTimeout(() => setCooldown((remaining) => remaining - 1), 1000);
return () => window.clearTimeout(timer);
}, [cooldown]);
// Staff log in with QR + their admin password; everyone else with QR + email.
const isStaff = found?.registration_type === 'staff';
async function handleScan(text: string) {
const token = text.trim();
if (!token) return;
if (!token || requestPending.current) return;
if (isEmailEntry(token)) {
if (cooldown) return;
requestPending.current = true;
setBusy(true);
setError(null);
setSent(false);
try {
await requestAdminLink(token);
setSent(true);
setCooldown(60);
} catch {
setError(adminLinkFailure);
} finally {
requestPending.current = false;
setBusy(false);
}
return;
}
if (token.includes('@')) {
setError('Enter a valid email address.');
return;
}
setQrToken(token);
setError(null);
try {
@@ -41,7 +76,7 @@ export function Login() {
// Attendees: QR + the ticket email (the QR token is the auth password).
const loginEmail = isStaff ? found?.email : email.trim();
const loginPassword = isStaff ? staffPassword : qrToken;
if (!loginEmail || !loginPassword) return;
if (!loginEmail || !loginPassword || busy) return;
setBusy(true);
setError(null);
try {
@@ -81,8 +116,18 @@ export function Login() {
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" />
<Scanner
onResult={handleScan}
label="Point your camera at your lanyard QR"
entryLabel="QR code or admin email"
placeholder="QR code or admin email"
disabled={busy}
submitDisabled={isEmailEntry(entry) && cooldown > 0}
submitLabel={busy ? 'Sending...' : isEmailEntry(entry) ? cooldown ? `Resend in ${cooldown}s` : sent ? 'Resend magic link' : 'Send magic link' : 'Go'}
onEntryChange={(value) => { setEntry(value); setSent(false); setError(null); }}
/>
{sent && <p role="status">{adminLinkNotice}</p>}
{error && <p role="alert" data-testid="login-error">{error}</p>}
</section>
);
}
@@ -139,7 +184,7 @@ export function Login() {
</>
)}
</div>
{error && <div className="muted small" data-testid="login-error" style={{ color: 'var(--red)' }}>{error}</div>}
{error && <div role="alert" className="muted small" data-testid="login-error" style={{ color: 'var(--red)' }}>{error}</div>}
<button
className="btn primary"
data-testid="login-confirm"