From 4166096706f5738fb19194403d080cf128396da3 Mon Sep 17 00:00:00 2001 From: joshua Date: Wed, 28 Oct 2026 03:59:52 +0200 Subject: [PATCH] Volunteer rosters: serving, roster and check-in pages, help, e2e Co-Authored-By: Claude Opus 5.5 --- apps/events/e2e/fixtures.ts | 2 +- apps/events/e2e/support/prepare-db.js | 10 +- apps/events/e2e/volunteers.spec.ts | 65 ++++++ .../app/dashboard/admin/audit-log/page.tsx | 5 + .../frontend/src/app/dashboard/admin/page.tsx | 3 +- .../frontend/src/app/dashboard/staff/page.tsx | 3 +- .../app/dashboard/staff/volunteers/page.tsx | 71 ++++++ .../src/app/dashboard/supervisor/page.tsx | 3 +- .../dashboard/supervisor/volunteers/page.tsx | 154 +++++++++++++ .../src/app/dashboard/user/serving/page.tsx | 186 +++++++++++++++ .../frontend/src/app/serve/check-in/page.tsx | 74 ++++++ .../src/components/kids/RoomBoard.tsx | 1 + .../src/components/layout/Sidebar.tsx | 3 +- .../src/components/volunteers/CheckInQr.tsx | 33 +++ .../src/components/volunteers/RosterSheet.tsx | 214 ++++++++++++++++++ .../frontend/src/content/help/registry.ts | 16 ++ .../frontend/src/content/help/volunteers.tsx | 113 +++++++++ apps/events/frontend/src/lib/kids.ts | 5 +- apps/events/frontend/src/lib/volunteers.ts | 69 ++++++ 19 files changed, 1023 insertions(+), 7 deletions(-) create mode 100644 apps/events/e2e/volunteers.spec.ts create mode 100644 apps/events/frontend/src/app/dashboard/staff/volunteers/page.tsx create mode 100644 apps/events/frontend/src/app/dashboard/supervisor/volunteers/page.tsx create mode 100644 apps/events/frontend/src/app/dashboard/user/serving/page.tsx create mode 100644 apps/events/frontend/src/app/serve/check-in/page.tsx create mode 100644 apps/events/frontend/src/components/volunteers/CheckInQr.tsx create mode 100644 apps/events/frontend/src/components/volunteers/RosterSheet.tsx create mode 100644 apps/events/frontend/src/content/help/volunteers.tsx create mode 100644 apps/events/frontend/src/lib/volunteers.ts diff --git a/apps/events/e2e/fixtures.ts b/apps/events/e2e/fixtures.ts index e80f22d..9cbba29 100644 --- a/apps/events/e2e/fixtures.ts +++ b/apps/events/e2e/fixtures.ts @@ -5,7 +5,7 @@ import path from "path"; export type Role = "admin" | "supervisor" | "staff" | "user"; export type Seed = { users: Record; - events: { free: string; paid: string; course: string; dropIn: string; conference: string; kids: string }; + events: { free: string; paid: string; course: string; dropIn: string; conference: string; kids: string; serving: string }; campuses: Record<"north" | "south", { id: string; slug: string }>; northTicketQr: string; course: { sessions: { id: string; label: string }[]; ticketId: string; qrCode: string }; diff --git a/apps/events/e2e/support/prepare-db.js b/apps/events/e2e/support/prepare-db.js index 8671d7b..87e5757 100644 --- a/apps/events/e2e/support/prepare-db.js +++ b/apps/events/e2e/support/prepare-db.js @@ -88,6 +88,14 @@ async function seed(url) { price: 0, isHidden: true, createdById: users.supervisor.id, }, }); + // Volunteer rosters (volunteers.spec.ts): on today, hidden. + const serving = await prisma.event.create({ + data: { + title: 'E2E Serving Sunday', description: 'Volunteer rosters for the tests.', startDate: new Date(Date.now() - 60 * 60 * 1000), endDate: new Date(Date.now() + 6 * 60 * 60 * 1000), + price: 0, isHidden: true, createdById: users.supervisor.id, + eventOptions: { create: [{ name: 'Entry', price: 0, isMainTicket: true }] }, + }, + }); const paid = await prisma.event.create({ data: { campusId: south.id, @@ -181,7 +189,7 @@ async function seed(url) { const out = { users: Object.fromEntries(Object.entries(users).map(([k, u]) => [k, { id: u.id, name: u.name, email: u.email, token: generateToken(u.id, u.role, u.tokenVersion || 0) }])), - events: { free: free.id, paid: paid.id, course: course.id, dropIn: dropIn.id, conference: conference.id, kids: kids.id }, + events: { free: free.id, paid: paid.id, course: course.id, dropIn: dropIn.id, conference: conference.id, kids: kids.id, serving: serving.id }, campuses: { north: { id: north.id, slug: north.slug }, south: { id: south.id, slug: south.slug } }, northTicketQr: northTicket.qrCode, course: { sessions: course.sessions.map(s => ({ id: s.id, label: s.label })), ticketId: ticket.id, qrCode: ticket.qrCode }, diff --git a/apps/events/e2e/volunteers.spec.ts b/apps/events/e2e/volunteers.spec.ts new file mode 100644 index 0000000..8ab9e73 --- /dev/null +++ b/apps/events/e2e/volunteers.spec.ts @@ -0,0 +1,65 @@ +import { test, expect, seed, loginAs, API } from "./fixtures"; + +// Volunteer rosters (1.46.0): a supervisor adds a role and switches the free volunteer ticket on, +// a user signs up, can't make it and asks for cover, staff take the place over, then check in by +// scanning the event's QR code. "E2E Serving Sunday" is seeded hidden and on today. +test.describe.serial("volunteer rosters", () => { + test("a supervisor adds a role and switches the volunteer ticket on", async ({ page }) => { + await loginAs(page, "supervisor"); + await page.goto(`/dashboard/supervisor/volunteers?event=${seed().events.serving}`); + await page.getByRole("button", { name: "Add a role" }).click(); + await page.getByLabel("Role name").fill("Welcome team"); + await page.getByLabel("People needed").fill("1"); + await page.getByRole("button", { name: "Add role" }).click(); + await expect(page.getByTestId("roster-role")).toContainText("Welcome team"); + await expect(page.getByTestId("roster-totals")).toContainText("0 of 1"); + + await page.getByRole("tab", { name: "Volunteer ticket" }).click(); + await page.getByRole("button", { name: /Add a free "Volunteer" ticket/ }).click(); + await expect(page.getByLabel("Volunteer ticket")).not.toHaveValue(""); + }); + + test("the volunteer ticket isn't offered publicly", async ({ request }) => { + const res = await request.get(`${API}/api/events/${seed().events.serving}`); + const ev = await res.json(); + expect(ev.eventOptions.map((o: { name: string }) => o.name)).toEqual(["Entry"]); + }); + + test("a user signs up, then asks for cover", async ({ page }) => { + await loginAs(page, "user"); + await page.goto(`/dashboard/user/serving?event=${seed().events.serving}`); + await page.getByTestId("open-role").filter({ hasText: "Welcome team" }).getByRole("button", { name: "Sign up" }).click(); + await expect(page.getByRole("status")).toContainText("you're on the roster"); + const shift = page.getByTestId("my-shift").filter({ hasText: "Welcome team" }); + await expect(shift).toContainText("free volunteer ticket"); + + page.once("dialog", d => d.accept("Away that weekend")); + await shift.getByRole("button", { name: "Can't make it" }).click(); + await expect(shift).toContainText("Cover requested"); + }); + + test("staff take the place over, then check in with the QR code", async ({ page, request }) => { + await loginAs(page, "staff"); + await page.goto("/dashboard/user/serving"); + const cover = page.getByTestId("cover-request").filter({ hasText: "Welcome team" }); + await expect(cover).toContainText("Away that weekend"); + await cover.getByRole("button", { name: "Take over" }).click(); + await expect(page.getByRole("status")).toContainText("taken over Welcome team"); + await expect(page.getByTestId("my-shift").filter({ hasText: "Welcome team" })).toBeVisible(); + + // The QR code on the wall holds this; a phone camera opens the check-in page. + const qr = await request.get(`${API}/api/volunteers/manage/events/${seed().events.serving}/qr`, { headers: { Authorization: `Bearer ${seed().users.supervisor.token}` } }); + const { qr: code } = await qr.json(); + await page.goto(`/serve/check-in?code=${encodeURIComponent(code)}`); + await expect(page.getByTestId("volunteer-checked-in")).toContainText("Welcome team"); + }); + + test("the roster shows who took over and checked in", async ({ page }) => { + await loginAs(page, "supervisor"); + await page.goto(`/dashboard/supervisor/volunteers?event=${seed().events.serving}`); + const volunteer = page.getByTestId("roster-volunteer"); + await expect(volunteer).toContainText(seed().users.staff.name); + await expect(volunteer).toContainText("(QR)"); + await expect(page.getByTestId("roster-totals")).toContainText("1 checked in"); + }); +}); diff --git a/apps/events/frontend/src/app/dashboard/admin/audit-log/page.tsx b/apps/events/frontend/src/app/dashboard/admin/audit-log/page.tsx index 85bb2cd..4bff067 100644 --- a/apps/events/frontend/src/app/dashboard/admin/audit-log/page.tsx +++ b/apps/events/frontend/src/app/dashboard/admin/audit-log/page.tsx @@ -109,6 +109,11 @@ const ACTION_LABELS: Record = { kids_wrong_code: "Wrong pickup code entered", kids_custody_notes_changed: "Child's custody notes changed", kids_offline_sync: "Offline kids desk synced", + volunteer_settings_updated: "Volunteer ticket changed", + volunteer_roles_changed: "Serving role added, changed or deleted", + volunteer_assigned: "Volunteer put on a roster", + volunteer_removed: "Volunteer taken off a roster", + volunteer_checked_in_manual: "Volunteer checked in by hand", }; interface AuditLogEntry { diff --git a/apps/events/frontend/src/app/dashboard/admin/page.tsx b/apps/events/frontend/src/app/dashboard/admin/page.tsx index 92abeb0..d81c11b 100644 --- a/apps/events/frontend/src/app/dashboard/admin/page.tsx +++ b/apps/events/frontend/src/app/dashboard/admin/page.tsx @@ -9,7 +9,7 @@ import { useVisiblePolling } from "@/hooks/useVisiblePolling"; import { Calendar, Banknote, Gift, Users, Ticket, QrCode, ClipboardList, UserPlus, FileText, MessageCircle, BarChart2, Mail, Wallet, DoorOpen, History, TicketPercent, ShieldCheck, ListChecks, WifiOff, BedDouble, Filter, ClipboardCheck, Inbox, - Baby, + Baby, HandHeart, } from "lucide-react"; import { StatCard, StatCardRow } from "@/components/shared/StatCard"; import { QuickActionTile, QuickActionGrid } from "@/components/shared/QuickActionTile"; @@ -33,6 +33,7 @@ const QUICK_ACTIONS = [ { href: "/dashboard/supervisor/allocations", label: "Rooms & groups", description: "Put attendees into rooms, groups or buses", icon: BedDouble }, { href: "/dashboard/staff/kids", label: "Kids check-in", description: "Check children in and out with pickup codes", icon: Baby }, { href: "/dashboard/supervisor/kids", label: "Kids check-in setup", description: "Switch it on for an event and set up the rooms", icon: Baby }, + { href: "/dashboard/supervisor/volunteers", label: "Volunteer rosters", description: "Serving roles, who serves where, check-ins and hours", icon: HandHeart }, { href: "/dashboard/supervisor/offline-scans", label: "Offline scanning", description: "Devices scanning offline and their synced scans", icon: WifiOff }, { href: "/dashboard/supervisor/attendance", label: "Attendance", description: "Who came to each session, and certificates", icon: ClipboardCheck }, { href: "/dashboard/supervisor/waitlist", label: "Waitlist", description: "People waiting for sold-out tickets", icon: ListChecks }, diff --git a/apps/events/frontend/src/app/dashboard/staff/page.tsx b/apps/events/frontend/src/app/dashboard/staff/page.tsx index f87f4a0..600a43b 100644 --- a/apps/events/frontend/src/app/dashboard/staff/page.tsx +++ b/apps/events/frontend/src/app/dashboard/staff/page.tsx @@ -6,7 +6,7 @@ import { useRouter } from "next/navigation"; import { apiFetch } from "@/lib/api"; import { useStableState } from "@/hooks/useStableState"; import { useVisiblePolling } from "@/hooks/useVisiblePolling"; -import { QrCode, Ticket, Activity, UserCheck, Clock, Users, ClipboardCheck, Baby } from "lucide-react"; +import { QrCode, Ticket, Activity, UserCheck, Clock, Users, ClipboardCheck, Baby, HandHeart } from "lucide-react"; import { StatCard, StatCardRow } from "@/components/shared/StatCard"; import { QuickActionTile, QuickActionGrid } from "@/components/shared/QuickActionTile"; import type { DashboardStats, RecentScan, ScanStats } from "@/types"; @@ -17,6 +17,7 @@ const QUICK_ACTIONS = [ { href: "/dashboard/staff/event-tickets", label: "Event tickets & printing", description: "Browse event tickets and print lists", icon: Ticket }, { href: "/dashboard/staff/my-groups", label: "My groups", description: "Rooms and groups you lead", icon: Users }, { href: "/dashboard/staff/kids", label: "Kids check-in", description: "Check children in and out with pickup codes", icon: Baby }, + { href: "/dashboard/staff/volunteers", label: "Volunteers", description: "Who is serving today, check-ins and the check-in QR code", icon: HandHeart }, { href: "/dashboard/supervisor/attendance", label: "Attendance", description: "Who came to each session of an event", icon: ClipboardCheck }, ] as const; diff --git a/apps/events/frontend/src/app/dashboard/staff/volunteers/page.tsx b/apps/events/frontend/src/app/dashboard/staff/volunteers/page.tsx new file mode 100644 index 0000000..eb09cc5 --- /dev/null +++ b/apps/events/frontend/src/app/dashboard/staff/volunteers/page.tsx @@ -0,0 +1,71 @@ +"use client"; + +import React, { useEffect, useState } from "react"; +import { useAuth } from "@/hooks/useAuth"; +import { apiFetch } from "@/lib/api"; +import { errorMessage } from "@/lib/utils"; +import { formatDate } from "@/lib/date"; +import { useDismissingState } from "@/hooks/useDismissingState"; +import { BackLink } from "@/components/shared/BackLink"; +import { RosterSheet } from "@/components/volunteers/RosterSheet"; +import { CheckInQr } from "@/components/volunteers/CheckInQr"; +import { HandHeart } from "lucide-react"; +import type { RosterEvent } from "@/lib/volunteers"; + +/** Staff → Volunteers: the roster on the day — who's here, ticking people in, and the check-in QR code. */ +export default function StaffVolunteersPage() { + const { token } = useAuth(); + const [events, setEvents] = useState(null); + const [eventId, setEventId] = useState(""); + const [showQr, setShowQr] = useState(false); + const [msg, setMsg] = useDismissingState<{ type: "ok" | "err"; text: string } | null>(null); + + useEffect(() => { + if (!token) return; + apiFetch("/api/volunteers/manage/events", { authToken: token }) + .then(list => { + setEvents(list); + const now = Date.now(); + const current = list.find(e => new Date(e.endDate).getTime() >= now); + if (current) setEventId(current.id); + }) + .catch(e => setMsg({ type: "err", text: errorMessage(e) || "Could not load events" })); + }, [token, setMsg]); + + const event = events?.find(e => e.id === eventId); + + return ( +
+
+
+
+ +

Volunteers

+

Who's serving today, and checking them in

+
+
+ + {events && !events.length &&
No events have volunteer rosters yet. A supervisor adds serving roles under Supervisor → Volunteer rosters.
} + {events && events.length > 0 && ( +
+ + {eventId && } +
+ )} + + {msg &&
{msg.text}
} + +
+ {eventId && (showQr + ? + : )} +
+
+ ); +} diff --git a/apps/events/frontend/src/app/dashboard/supervisor/page.tsx b/apps/events/frontend/src/app/dashboard/supervisor/page.tsx index 291dd8b..c0ee847 100644 --- a/apps/events/frontend/src/app/dashboard/supervisor/page.tsx +++ b/apps/events/frontend/src/app/dashboard/supervisor/page.tsx @@ -9,7 +9,7 @@ import { useVisiblePolling } from "@/hooks/useVisiblePolling"; import { Calendar, Banknote, Gift, Users, Ticket, QrCode, DoorOpen, Wallet, UserPlus, FileText, MessageCircle, BarChart2, Mail, TicketPercent, ShieldCheck, ListChecks, WifiOff, BedDouble, Filter, ClipboardCheck, - Baby, + Baby, HandHeart, } from "lucide-react"; import { StatCard, StatCardRow } from "@/components/shared/StatCard"; import { QuickActionTile, QuickActionGrid } from "@/components/shared/QuickActionTile"; @@ -30,6 +30,7 @@ const QUICK_ACTIONS = [ { href: "/dashboard/supervisor/allocations", label: "Rooms & groups", description: "Put attendees into rooms, groups or buses", icon: BedDouble }, { href: "/dashboard/staff/kids", label: "Kids check-in", description: "Check children in and out with pickup codes", icon: Baby }, { href: "/dashboard/supervisor/kids", label: "Kids check-in setup", description: "Switch it on for an event and set up the rooms", icon: Baby }, + { href: "/dashboard/supervisor/volunteers", label: "Volunteer rosters", description: "Serving roles, who serves where, check-ins and hours", icon: HandHeart }, { href: "/dashboard/supervisor/offline-scans", label: "Offline scanning", description: "Devices scanning offline and their synced scans", icon: WifiOff }, { href: "/dashboard/supervisor/attendance", label: "Attendance", description: "Who came to each session, and certificates", icon: ClipboardCheck }, { href: "/dashboard/supervisor/waitlist", label: "Waitlist", description: "People waiting for sold-out tickets", icon: ListChecks }, diff --git a/apps/events/frontend/src/app/dashboard/supervisor/volunteers/page.tsx b/apps/events/frontend/src/app/dashboard/supervisor/volunteers/page.tsx new file mode 100644 index 0000000..d047126 --- /dev/null +++ b/apps/events/frontend/src/app/dashboard/supervisor/volunteers/page.tsx @@ -0,0 +1,154 @@ +"use client"; + +import React, { useCallback, useEffect, useState } from "react"; +import { useAuth } from "@/hooks/useAuth"; +import { apiFetch } from "@/lib/api"; +import { errorMessage } from "@/lib/utils"; +import { formatDate } from "@/lib/date"; +import { useDismissingState } from "@/hooks/useDismissingState"; +import { BackLink } from "@/components/shared/BackLink"; +import { RosterSheet } from "@/components/volunteers/RosterSheet"; +import { CheckInQr } from "@/components/volunteers/CheckInQr"; +import { HandHeart } from "lucide-react"; +import { hoursText, type HoursRow, type RosterEvent } from "@/lib/volunteers"; + +type Settings = { + event: { id: string; title: string; volunteerOptionId: string | null }; + options: { id: string; name: string; price: number }[]; + kidsRooms: { id: string; name: string }[]; +}; +type Tab = "roster" | "qr" | "ticket" | "hours"; +const TABS: { id: Tab; label: string }[] = [ + { id: "roster", label: "Roster" }, + { id: "qr", label: "Check-in QR" }, + { id: "ticket", label: "Volunteer ticket" }, + { id: "hours", label: "Hours served" }, +]; + +/** Supervisor → Volunteer rosters: serving roles per event or session, people, check-in QR, volunteer ticket, hours. */ +export default function VolunteerRostersPage() { + const { token } = useAuth(); + const [events, setEvents] = useState([]); + const [eventId, setEventId] = useState(""); + const [tab, setTab] = useState("roster"); + const [settings, setSettings] = useState(null); + const [hours, setHours] = useState(null); + const [hoursAll, setHoursAll] = useState(true); + const [msg, setMsg] = useDismissingState<{ type: "ok" | "err"; text: string } | null>(null); + const [busy, setBusy] = useState(false); + + useEffect(() => { + if (!token) return; + apiFetch("/api/volunteers/manage/events?all=1", { authToken: token }) + .then(list => { + setEvents(list); + const wanted = new URLSearchParams(window.location.search).get("event"); + if (wanted && list.some(e => e.id === wanted)) setEventId(wanted); + }) + .catch(e => setMsg({ type: "err", text: errorMessage(e) || "Could not load events" })); + }, [token, setMsg]); + + const loadSettings = useCallback(async () => { + if (!token || !eventId) { setSettings(null); return; } + try { + setSettings(await apiFetch(`/api/volunteers/manage/events/${eventId}/settings`, { authToken: token })); + } catch (e) { + setMsg({ type: "err", text: errorMessage(e) || "Could not load the settings" }); + } + }, [token, eventId, setMsg]); + useEffect(() => { loadSettings(); }, [loadSettings]); + + useEffect(() => { + if (!token || tab !== "hours") return; + setHours(null); + apiFetch(`/api/volunteers/manage/hours${!hoursAll && eventId ? `?eventId=${eventId}` : ""}`, { authToken: token }) + .then(setHours) + .catch(e => setMsg({ type: "err", text: errorMessage(e) || "Could not load hours" })); + }, [token, tab, hoursAll, eventId, setMsg]); + + const saveTicket = async (optionId: string | null, ok: string) => { + setBusy(true); + try { + setSettings(await apiFetch(`/api/volunteers/manage/events/${eventId}/settings`, { method: "PUT", authToken: token, body: { optionId } })); + setMsg({ type: "ok", text: ok }); + } catch (e) { + setMsg({ type: "err", text: errorMessage(e) || "Could not save" }); + } finally { + setBusy(false); + } + }; + + const event = events.find(e => e.id === eventId); + + return ( +
+
+
+
+ +

Volunteer rosters

+

Who serves where, for an event or each session

+
+
+ + + + {msg &&
{msg.text}
} + +
+ {TABS.map(t => ( + + ))} +
+ +
+ {tab !== "hours" && !eventId &&

Choose an event.

} + {tab === "roster" && eventId && ( +

+ Sign-up link to share: {`${typeof window !== "undefined" ? window.location.origin : ""}/dashboard/user/serving?event=${eventId}`} +

+ )} + {tab === "roster" && eventId && } + {tab === "qr" && eventId && } + {tab === "ticket" && eventId && settings && ( +
+

Free volunteer ticket

+

Off unless you choose a ticket. When it's on, everyone on this event's roster gets a free place on it (shown in their My Events), unless they already have a ticket. It's never offered to the public, and it's given back when they leave the roster.

+
+ + {!settings.event.volunteerOptionId && } +
+

Places already given stay when you switch it off.

+
+ )} + {tab === "hours" && ( +
+
+ + +
+

Shifts people checked in for, counted at the shift's length.

+ {!hours &&
Loading…
} + {hours && hours.length === 0 &&

No checked-in shifts yet.

} + {hours && hours.length > 0 && ( + + + {hours.map(h => )} +
VolunteerShiftsEventsHours
{h.name}{h.shifts}{h.events}{hoursText(h.hours)}
+ )} +
+ )} +
+
+ ); +} diff --git a/apps/events/frontend/src/app/dashboard/user/serving/page.tsx b/apps/events/frontend/src/app/dashboard/user/serving/page.tsx new file mode 100644 index 0000000..7944e9c --- /dev/null +++ b/apps/events/frontend/src/app/dashboard/user/serving/page.tsx @@ -0,0 +1,186 @@ +"use client"; + +import React, { useCallback, useEffect, useState } from "react"; +import { useAuth } from "@/hooks/useAuth"; +import { apiFetch } from "@/lib/api"; +import { errorMessage } from "@/lib/utils"; +import { formatDate } from "@/lib/date"; +import { useDismissingState } from "@/hooks/useDismissingState"; +import { BackLink } from "@/components/shared/BackLink"; +import { CheckCircle2, HandHeart, QrCode, Repeat } from "lucide-react"; +import type { CoverRequest, MySlot, Roster, ServingEvent } from "@/lib/volunteers"; + +type Mine = { slots: MySlot[]; cover: CoverRequest[]; events: ServingEvent[] }; +type Msg = { type: "ok" | "err"; text: string } | null; + +const btn = "px-3 py-1.5 rounded-lg text-sm border disabled:opacity-50"; + +/** My account → Serving: my shifts, cover requests I could take, and events looking for volunteers. */ +export default function ServingPage() { + const { token } = useAuth(); + const [data, setData] = useState(null); + const [msg, setMsg] = useDismissingState(null); + const [busy, setBusy] = useState(false); + const [openEvent, setOpenEvent] = useState(""); + const [roster, setRoster] = useState(null); + + const load = useCallback(async () => { + if (!token) return; + try { + setData(await apiFetch("/api/volunteers/me", { authToken: token })); + } catch (e) { + setMsg({ type: "err", text: errorMessage(e) || "Could not load your shifts" }); + } + }, [token, setMsg]); + useEffect(() => { load(); }, [load]); + // ?event=: the sign-up link a supervisor shares (works for hidden events too). + useEffect(() => { + const wanted = new URLSearchParams(window.location.search).get("event"); + if (wanted) setOpenEvent(wanted); + }, []); + + const loadRoster = useCallback(async (id: string) => { + if (!token || !id) { setRoster(null); return; } + try { + setRoster(await apiFetch(`/api/volunteers/events/${id}`, { authToken: token })); + } catch (e) { + setMsg({ type: "err", text: errorMessage(e) || "Could not load the roles" }); + } + }, [token, setMsg]); + useEffect(() => { loadRoster(openEvent); }, [openEvent, loadRoster]); + + const call = async (fn: () => Promise, ok: string) => { + setBusy(true); + try { + await fn(); + setMsg({ type: "ok", text: ok }); + await Promise.all([load(), openEvent ? loadRoster(openEvent) : null]); + } catch (e) { + setMsg({ type: "err", text: errorMessage(e) || "Something went wrong" }); + } finally { + setBusy(false); + } + }; + + const askCover = (s: MySlot) => { + const note = prompt(`Ask the other volunteers to take over ${s.role.name}? The first to accept takes your place. Add a note (optional):`, ""); + if (note === null) return; + call(() => apiFetch(`/api/volunteers/slots/${s.slotId}/swap`, { method: "POST", authToken: token, body: { note } }), "Cover requested — you stay on the roster until someone takes over."); + }; + const withdraw = (s: MySlot) => confirm(`Withdraw from ${s.role.name} at ${s.event.title}? The organisers will be told.`) + && call(() => apiFetch(`/api/volunteers/slots/${s.slotId}`, { method: "DELETE", authToken: token }), "You're off the roster for this shift."); + + const upcoming = (data?.slots || []).filter(s => !s.past); + const past = (data?.slots || []).filter(s => s.past); + + return ( +
+
+
+
+ +

Serving

+

Your volunteer shifts, and events looking for people to serve

+
+
+ + {msg &&
{msg.text}
} + {!data &&
Loading…
} + + {data && ( +
+

My shifts

+ {upcoming.length === 0 &&

You're not on any roster yet. Sign up for a role below.

} + {upcoming.map(s => ( +
+
+
+
{s.role.name} · {s.event.title}
+
{s.role.sessionLabel ? `${s.role.sessionLabel} · ` : ""}{s.shift.text}{s.event.location ? ` · ${s.event.location}` : ""}
+ {s.role.kidsRoom &&
Kids room: {s.role.kidsRoom}
} + {s.role.description &&
{s.role.description}
} + {s.hasTicket &&
Your free volunteer ticket is in My Events.
} +
+ {s.checkedInAt + ? Checked in + : s.swapId && Cover requested} +
+ {s.canCheckIn &&

When you arrive, scan the volunteer check-in QR code with your phone's camera.

} + {!s.checkedInAt && ( +
+ {s.swapId + ? + : } + +
+ )} +
+ ))} + {past.length > 0 && ( +
+ Last week ({past.length}) +
    + {past.map(s =>
  • {s.role.name} · {s.event.title} · {s.shift.text}{s.checkedInAt ? " · served" : ""}
  • )} +
+
+ )} +
+ )} + + {data && data.cover.length > 0 && ( +
+

Can you take over?

+ {data.cover.map(c => ( +
+
+
{c.role.name} · {c.event.title}
+
{c.role.sessionLabel ? `${c.role.sessionLabel} · ` : ""}{c.shift.text}
+
{c.from || "A volunteer"} can't make it{c.note ? `: “${c.note}”` : ""}
+
+ +
+ ))} +
+ )} + + {data && ( +
+

Serve at an event

+ {data.events.length === 0 && !openEvent &&

No events are looking for volunteers right now.

} + {(data.events.length > 0 || openEvent) && ( + + )} + {roster && roster.event.id === openEvent && ( +
+ {roster.roles.filter(r => !r.past).map(r => ( +
+
+
{r.name}{r.kidsRoom ? · kids room {r.kidsRoom.name} : null}
+
{r.sessionLabel ? `${r.sessionLabel} · ` : ""}{r.shift.text}
+ {r.description &&
{r.description}
} +
{r.filled} of {r.needed} signed up
+
+ {r.mine + ? You're serving + : r.coverNeeded.length > 0 + ? + : r.full + ? Full + : } +
+ ))} + {roster.roles.every(r => r.past) &&

All shifts at this event are over.

} +
+ )} +
+ )} +
+ ); +} diff --git a/apps/events/frontend/src/app/serve/check-in/page.tsx b/apps/events/frontend/src/app/serve/check-in/page.tsx new file mode 100644 index 0000000..27c287d --- /dev/null +++ b/apps/events/frontend/src/app/serve/check-in/page.tsx @@ -0,0 +1,74 @@ +"use client"; + +import React, { Suspense, useEffect, useRef, useState } from "react"; +import Link from "next/link"; +import { useSearchParams } from "next/navigation"; +import { Navbar } from "@/components/layout/Navbar"; +import { Footer } from "@/components/layout/Footer"; +import { useAuth } from "@/hooks/useAuth"; +import { apiFetch } from "@/lib/api"; +import { errorMessage } from "@/lib/utils"; +import { CheckCircle2, HandHeart } from "lucide-react"; + +type Result = { event: { id: string; title: string }; checkedIn: { role: string; kidsRoom: string | null }[]; already: string[] }; + +/** Where the volunteer check-in QR code leads: checks the signed-in volunteer in for today's shifts. */ +function CheckIn() { + const code = useSearchParams().get("code") || ""; + const { user, token, loading } = useAuth(); + const [result, setResult] = useState(null); + const [error, setError] = useState(code ? null : "This check-in link is incomplete — scan the QR code again."); + const sent = useRef(false); + + useEffect(() => { + if (!code || loading || !token || sent.current) return; + sent.current = true; + apiFetch("/api/volunteers/check-in", { method: "POST", authToken: token, body: { qr: code } }) + .then(setResult) + .catch(e => setError(errorMessage(e) || "Couldn't check you in.")); + }, [code, loading, token]); + + if (error) return
{error} My shifts
; + if (loading) return
Loading…
; + if (!user) { + const back = `/serve/check-in?code=${encodeURIComponent(code)}`; + return ( +
+

Log in to check in for your volunteer shift.

+ Log in +
+ ); + } + if (!result) return
Checking you in…
; + return ( +
+
Thank you for serving, {user.name?.split(" ")[0]}!
+

You're checked in at {result.event.title}:

+
    + {result.checkedIn.map(c =>
  • {c.role}{c.kidsRoom ? ` — you're on duty in ${c.kidsRoom}` : ""}
  • )} + {result.already.map(r =>
  • {r} (already checked in)
  • )} +
+ My shifts +
+ ); +} + +export default function VolunteerCheckInPage() { + return ( +
+ +
+
+
+ +
+

Volunteer check-in

+
+ Loading…
}> + + + +