WIP 1.51.12: tickets, scan locks, attendance, allocations on v2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ls1vMdg2GYqbnKZmPaX1ot
This commit is contained in:
2026-10-29 13:52:31 +02:00
co-authored by Claude Opus 5.5
parent 91fa42ba5f
commit fe6034f10f
28 changed files with 8048 additions and 96 deletions
@@ -2,7 +2,7 @@
import React, { useEffect, useMemo, useState } from "react";
import { CheckSquare, X, Download } from "lucide-react";
import { apiFetch, API_BASE } from "@/lib/api";
import { API_BASE } from "@/lib/api";
import { errorMessage } from "@/lib/utils";
import { downloadReportExcel } from "@/lib/export";
import type { Event, Registration } from "@/types";
@@ -56,7 +56,7 @@ export function RegistrationBulkBar({ selected, events, token, onClear, onDone }
useEffect(() => {
if (action !== "allocate" || !oneEvent) { setSets([]); return; }
apiFetch<{ sets?: AllocationSet[] }>(`/api/allocations/event/${oneEvent.id}`, { authToken: token })
(apiV2Data("get", "/events/{id}/allocations", { params: { id: oneEvent.id }, authToken: token }) as Promise<{ sets?: AllocationSet[] }>)
.then(b => setSets((b.sets || []).filter(s => s.groups.length)))
.catch(() => setSets([]));
}, [action, oneEvent, token]);
@@ -2,11 +2,12 @@
import React, { useEffect, useState } from "react";
import { Award, Download } from "lucide-react";
import { apiFetch, API_BASE } from "@/lib/api";
import { API_BASE } from "@/lib/api";
import { fetchApiFile, saveBlob } from "@/lib/export";
import { formatDate } from "@/lib/date";
import { errorMessage } from "@/lib/utils";
import type { MyCertificate } from "@/types";
import { apiV2Data } from "@/lib/apiV2";
// Completion certificates on My Events. Hidden until the person has one.
export function MyCertificates({ token }: { token: string | null }) {
@@ -15,7 +16,7 @@ export function MyCertificates({ token }: { token: string | null }) {
useEffect(() => {
if (!token) return;
apiFetch<MyCertificate[]>("/api/attendance/certificates/mine", { authToken: token })
(apiV2Data("get", "/me/certificates", { authToken: token }) as Promise<MyCertificate[]>)
.then(list => setCerts(Array.isArray(list) ? list : []))
.catch(() => setCerts([]));
}, [token]);
@@ -26,7 +27,7 @@ export function MyCertificates({ token }: { token: string | null }) {
if (!token) return;
setError(null);
try {
saveBlob(await fetchApiFile(API_BASE, token, `/api/attendance/certificates/${c.id}/pdf`), `Certificate - ${c.event.title.replace(/[^a-z0-9 -]/gi, "")}.pdf`);
saveBlob(await fetchApiFile(API_BASE, token, `/api/v2/certificates/${c.id}/pdf`), `Certificate - ${c.event.title.replace(/[^a-z0-9 -]/gi, "")}.pdf`);
} catch (e) {
setError(errorMessage(e) || "Download failed");
}
@@ -346,7 +346,7 @@ export default function ReportsV2({ backHref }: { backHref?: string } = {}) {
const result: Record<string, { used: number; unused: number }> = {};
for (const id of eventIds) {
try {
const tickets = await apiFetch<Ticket[]>(`/api/tickets/event/${encodeURIComponent(id)}`, { authToken: token });
const tickets = await (apiV2Data("get", "/events/{id}/tickets", { params: { id: id }, authToken: token }) as Promise<Ticket[]>);
result[id] = { used: tickets.filter(t => t.isUsed).length, unused: tickets.filter(t => !t.isUsed).length };
} catch {
result[id] = { used: 0, unused: 0 };
@@ -2,9 +2,9 @@
import React, { useEffect, useState } from "react";
import { Wifi, WifiOff, CloudUpload, Lock } from "lucide-react";
import { apiFetch } from "@/lib/api";
import type { OtherLock } from "./useOfflineScanning";
import { errorMessage } from "@/lib/utils";
import { apiV2Data } from "@/lib/apiV2";
type Offline = ReturnType<typeof import("./useOfflineScanning").useOfflineScanning>;
@@ -28,7 +28,7 @@ export function OfflineScanPanel({ offline, token, eventId, eventTitle, sectionI
useEffect(() => {
if (!token || !eventId || eventId === "all" || !online) { setLocks([]); return; }
apiFetch<OtherLock[]>(`/api/scan-locks?eventId=${encodeURIComponent(eventId)}`, { authToken: token })
(apiV2Data("get", "/scan-locks", { query: { eventId: eventId }, authToken: token }) as Promise<OtherLock[]>)
.then(setLocks).catch(() => setLocks([]));
}, [token, eventId, online, lock]);
@@ -1,7 +1,7 @@
"use client";
import { useCallback, useEffect, useRef, useState } from "react";
import { apiFetch } from "@/lib/api";
import { apiV2Data } from "@/lib/apiV2";
import {
OfflineLock, SnapshotTicket, clearOffline, deviceId, deviceName, findTicket, getOfflineLock,
queuedScans, recordScan, removeQueued, startOffline,
@@ -57,9 +57,11 @@ export function useOfflineScanning(token: string | null) {
queue.forEach(q => byLock.set(q.lockId, [...(byLock.get(q.lockId) || []), q]));
let accepted = 0, conflicts = 0;
for (const [lockId, scans] of byLock) {
const res = await apiFetch<{ accepted: number; duplicates: number; conflicts: unknown[] }>(`/api/scan-locks/${lockId}/sync`, {
method: "POST", authToken: token, body: { deviceId: deviceId(), scans },
});
const res = await (apiV2Data("post", "/scan-locks/{id}/sync", {
params: { id: lockId },
authToken: token,
body: { deviceId: deviceId(), scans },
}) as Promise<{ accepted: number; duplicates: number; conflicts: unknown[] }>);
accepted += res.accepted;
conflicts += res.conflicts.length;
// Synced (or already on the server) — either way they're done on this device.
@@ -85,13 +87,14 @@ export function useOfflineScanning(token: string | null) {
const enable = useCallback(async (eventId: string, eventTitle: string, sectionId: string | null, sectionName: string | null) => {
if (!token) throw new Error("Log in first.");
const created = await apiFetch<{ id: string }>("/api/scan-locks", {
method: "POST", authToken: token, body: { eventId, sectionId, deviceId: deviceId(), deviceName: deviceName() },
});
const snap = await apiFetch<{ snapshotAt: string; tickets: SnapshotTicket[]; session?: { id: string; label: string } | null; noSessionToday?: boolean }>(`/api/scan-locks/${created.id}/snapshot?deviceId=${encodeURIComponent(deviceId())}`, { authToken: token });
const created = await (apiV2Data("post", "/scan-locks", {
authToken: token,
body: { eventId, sectionId, deviceId: deviceId(), deviceName: deviceName() },
}) as Promise<{ id: string }>);
const snap = await (apiV2Data("get", "/scan-locks/{id}/snapshot", { params: { id: created.id }, query: { deviceId: deviceId() }, authToken: token }) as Promise<{ snapshotAt: string; tickets: SnapshotTicket[]; session?: { id: string; label: string } | null; noSessionToday?: boolean }>);
// Multi-day events: the downloaded list is for today's session, so there must be one.
if (snap.noSessionToday) {
await apiFetch(`/api/scan-locks/${created.id}`, { method: "DELETE", authToken: token, body: { deviceId: deviceId() } }).catch(() => {});
await apiV2Data("delete", "/scan-locks/{id}", { params: { id: created.id }, authToken: token, body: { deviceId: deviceId() } }).catch(() => {});
throw new Error("There's no session of this event open for check-in today, so offline mode can't start.");
}
const next: OfflineLock = { lockId: created.id, eventId, eventTitle, sectionId, sectionName, snapshotAt: snap.snapshotAt, sessionLabel: snap.session?.label || null };
@@ -104,7 +107,7 @@ export function useOfflineScanning(token: string | null) {
if (!lock || !token) return;
await sync();
if ((await queuedScans()).length > 0) throw new Error("Some scans haven't synced yet. Try again when you're online.");
await apiFetch(`/api/scan-locks/${lock.lockId}`, { method: "DELETE", authToken: token, body: { deviceId: deviceId() } });
await apiV2Data("delete", "/scan-locks/{id}", { params: { id: lock.lockId }, authToken: token, body: { deviceId: deviceId() } });
await clearOffline();
setLock(null);
}, [lock, token, sync]);
@@ -1,7 +1,7 @@
"use client";
import React, { useEffect, useState } from "react";
import { apiFetch } from "@/lib/api";
import { apiV2Data } from "@/lib/apiV2";
type SetWithGroups = { id: string; name: string; groups: { id: string; name: string }[] };
@@ -20,7 +20,7 @@ export function AllocationGroupFilter({ token, eventId, value, onChange }: {
useEffect(() => {
onChange("");
if (!token || !eventId) { setSets([]); return; }
apiFetch<{ sets: SetWithGroups[] }>(`/api/allocations/event/${encodeURIComponent(eventId)}`, { authToken: token })
(apiV2Data("get", "/events/{id}/allocations", { params: { id: eventId }, authToken: token }) as Promise<{ sets: SetWithGroups[] }>)
.then(b => setSets((b.sets || []).filter(s => s.groups.length > 0)))
.catch(() => setSets([]));
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -2,10 +2,10 @@
import React, { useState } from "react";
import { ArrowRightLeft } from "lucide-react";
import { apiFetch } from "@/lib/api";
import { isMinorOn } from "@/components/shared/AttendeeNamesEditor";
import { errorMessage } from "@/lib/utils";
import { ModalOverlay } from "@/components/shared/ModalOverlay";
import { apiV2Data } from "@/lib/apiV2";
type TransferTicket = { id: string; isUsed?: boolean; quantity?: number; usages?: unknown[] };
type TransferEvent = {
@@ -50,7 +50,7 @@ export function TransferTicketModal({ ticket, event, token, onClose, onDone }: {
try {
const body: Record<string, string> = { name: f.name, email: f.email, phone: f.phone, ...(f.gender ? { gender: f.gender } : {}) };
if (youth) Object.assign(body, { dateOfBirth: f.dateOfBirth, parentName: f.parentName, parentEmail: f.parentEmail, parentPhone: f.parentPhone });
const res = await apiFetch<{ message: string }>(`/api/tickets/${ticket.id}/transfer`, { method: "POST", authToken: token, body });
const res = await (apiV2Data("post", "/tickets/{id}/transfer", { params: { id: ticket.id }, authToken: token, body }) as Promise<{ message: string }>);
onDone(res.message);
} catch (err) {
setError(errorMessage(err) || "Couldn't transfer the ticket");