Archived
Volunteer rosters: serving, roster and check-in pages, help, e2e
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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 },
|
||||
|
||||
@@ -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<RosterEvent[]>([]);
|
||||
const [eventId, setEventId] = useState("");
|
||||
const [tab, setTab] = useState<Tab>("roster");
|
||||
const [settings, setSettings] = useState<Settings | null>(null);
|
||||
const [hours, setHours] = useState<HoursRow[] | null>(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<RosterEvent[]>("/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<Settings>(`/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<HoursRow[]>(`/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<Settings>(`/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 (
|
||||
<div className="max-w-4xl mx-auto w-full p-6">
|
||||
<div className="flex items-center gap-3 mb-4 print:hidden">
|
||||
<div className="w-10 h-10 rounded-xl bg-brand-50 flex items-center justify-center shrink-0"><HandHeart className="w-5 h-5 text-brand-600" /></div>
|
||||
<div>
|
||||
<BackLink href="/dashboard" />
|
||||
<h1 className="text-2xl font-semibold text-gray-900 mt-0.5">Volunteer rosters</h1>
|
||||
<p className="text-sm text-gray-500">Who serves where, for an event or each session</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label className="text-sm block max-w-md print:hidden">
|
||||
<span className="block text-xs text-gray-500 mb-1">Event</span>
|
||||
<select className="w-full border rounded-lg px-3 py-2 text-sm" value={eventId} onChange={e => setEventId(e.target.value)}>
|
||||
<option value="">Choose an event…</option>
|
||||
{events.map(e => <option key={e.id} value={e.id}>{e.title} · {formatDate(new Date(e.startDate))}{e.roles ? ` · ${e.roles} role${e.roles === 1 ? "" : "s"}` : ""}</option>)}
|
||||
</select>
|
||||
</label>
|
||||
|
||||
{msg && <div role="status" className={`mt-3 p-3 rounded-lg text-sm print:hidden ${msg.type === "ok" ? "bg-green-50 text-green-800 border border-green-200" : "bg-red-50 text-red-800 border border-red-200"}`}>{msg.text}</div>}
|
||||
|
||||
<div className="flex flex-wrap gap-1 mt-4 border-b print:hidden" role="tablist">
|
||||
{TABS.map(t => (
|
||||
<button key={t.id} role="tab" aria-selected={tab === t.id} onClick={() => setTab(t.id)} className={`px-3 py-2 text-sm -mb-px border-b-2 ${tab === t.id ? "border-brand-600 text-brand-700 font-medium" : "border-transparent text-gray-500"}`}>{t.label}</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mt-4">
|
||||
{tab !== "hours" && !eventId && <p className="text-sm text-gray-500">Choose an event.</p>}
|
||||
{tab === "roster" && eventId && (
|
||||
<p className="text-xs text-gray-500 mb-3 print:hidden">
|
||||
Sign-up link to share: <span className="font-mono select-all break-all" data-testid="signup-link">{`${typeof window !== "undefined" ? window.location.origin : ""}/dashboard/user/serving?event=${eventId}`}</span>
|
||||
</p>
|
||||
)}
|
||||
{tab === "roster" && eventId && <RosterSheet token={token} eventId={eventId} canEdit kidsRooms={settings?.kidsRooms || []} onMessage={setMsg} />}
|
||||
{tab === "qr" && eventId && <CheckInQr token={token} eventId={eventId} title={event?.title || ""} />}
|
||||
{tab === "ticket" && eventId && settings && (
|
||||
<section className="border rounded-xl p-4 bg-white shadow-sm space-y-3">
|
||||
<h2 className="font-semibold">Free volunteer ticket</h2>
|
||||
<p className="text-sm text-gray-600">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.</p>
|
||||
<div className="flex flex-wrap gap-2 items-center">
|
||||
<select aria-label="Volunteer ticket" className="border rounded-lg px-3 py-2 text-sm" value={settings.event.volunteerOptionId || ""} disabled={busy}
|
||||
onChange={e => saveTicket(e.target.value || null, e.target.value ? "Volunteers get a free place on this ticket." : "No free volunteer ticket.")}>
|
||||
<option value="">Off — no free ticket</option>
|
||||
{settings.options.map(o => <option key={o.id} value={o.id}>{o.name}{o.price ? ` (R${o.price})` : " (free)"}</option>)}
|
||||
</select>
|
||||
{!settings.event.volunteerOptionId && <button disabled={busy} onClick={() => saveTicket("new", "Added a free \"Volunteer\" ticket — volunteers get a place on it.")} className="px-3 py-2 rounded-lg border text-sm">Add a free "Volunteer" ticket</button>}
|
||||
</div>
|
||||
<p className="text-xs text-gray-500">Places already given stay when you switch it off.</p>
|
||||
</section>
|
||||
)}
|
||||
{tab === "hours" && (
|
||||
<section className="space-y-3">
|
||||
<div className="flex gap-4 text-sm">
|
||||
<label className="inline-flex items-center gap-1"><input type="radio" checked={hoursAll} onChange={() => setHoursAll(true)} /> All events</label>
|
||||
<label className="inline-flex items-center gap-1"><input type="radio" checked={!hoursAll} disabled={!eventId} onChange={() => setHoursAll(false)} /> This event only</label>
|
||||
</div>
|
||||
<p className="text-xs text-gray-500">Shifts people checked in for, counted at the shift's length.</p>
|
||||
{!hours && <div className="text-sm text-gray-500">Loading…</div>}
|
||||
{hours && hours.length === 0 && <p className="text-sm text-gray-500">No checked-in shifts yet.</p>}
|
||||
{hours && hours.length > 0 && (
|
||||
<table className="w-full text-sm border rounded-xl overflow-hidden bg-white">
|
||||
<thead className="bg-gray-50 text-left text-xs text-gray-500"><tr><th className="p-2">Volunteer</th><th className="p-2">Shifts</th><th className="p-2">Events</th><th className="p-2">Hours</th></tr></thead>
|
||||
<tbody>{hours.map(h => <tr key={h.userId} className="border-t"><td className="p-2">{h.name}</td><td className="p-2">{h.shifts}</td><td className="p-2">{h.events}</td><td className="p-2 font-medium">{hoursText(h.hours)}</td></tr>)}</tbody>
|
||||
</table>
|
||||
)}
|
||||
</section>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user