WIP 1.51.13: kids check-in and volunteers 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:
@@ -6,6 +6,7 @@ import { errorMessage } from "@/lib/utils";
|
||||
import { useVisiblePolling } from "@/hooks/useVisiblePolling";
|
||||
import { CheckCircle2, Pencil, Plus, Printer, Trash2, UserPlus, X } from "lucide-react";
|
||||
import { fromLocalInput, toLocalInput, type Roster, type ServingRole } from "@/lib/volunteers";
|
||||
import { apiV2Data } from "@/lib/apiV2";
|
||||
|
||||
type Msg = { type: "ok" | "err"; text: string };
|
||||
type Props = {
|
||||
@@ -40,7 +41,7 @@ export function RosterSheet({ token, eventId, canEdit, kidsRooms = [], onMessage
|
||||
const load = useCallback(async (log = false) => {
|
||||
if (!token || !eventId) return;
|
||||
try {
|
||||
setRoster(await apiFetch<Roster>(`/api/volunteers/manage/events/${eventId}${log ? "?log=1" : ""}`, { authToken: token }));
|
||||
setRoster(await (apiV2Data("get", "/events/{id}/volunteers", { params: { id: eventId }, query: { log: log ? "1" : undefined }, authToken: token }) as Promise<Roster>));
|
||||
} catch (e) {
|
||||
onMessage({ type: "err", text: errorMessage(e) || "Could not load the roster" });
|
||||
}
|
||||
@@ -71,12 +72,12 @@ export function RosterSheet({ token, eventId, canEdit, kidsRooms = [], onMessage
|
||||
});
|
||||
const saveRole = () => run(
|
||||
() => editing === "new"
|
||||
? apiFetch(`/api/volunteers/manage/events/${eventId}/roles`, { method: "POST", authToken: token, body: body(draft) })
|
||||
: apiFetch(`/api/volunteers/manage/roles/${editing}`, { method: "PUT", authToken: token, body: body(draft) }),
|
||||
? apiV2Data("post", "/events/{id}/volunteer-roles", { params: { id: eventId }, authToken: token, body: body(draft) })
|
||||
: apiV2Data("patch", "/volunteer-roles/{id}", { params: { id: editing! }, authToken: token, body: body(draft) }),
|
||||
editing === "new" ? "Role added." : "Role saved.",
|
||||
).then(ok => { if (ok) { setEditing(null); setDraft(EMPTY); } });
|
||||
const deleteRole = (r: ServingRole) => confirm(`Delete ${r.name}?${r.filled ? ` The ${r.filled} volunteer${r.filled === 1 ? "" : "s"} on it will be told.` : ""}`)
|
||||
&& run(() => apiFetch(`/api/volunteers/manage/roles/${r.id}`, { method: "DELETE", authToken: token }), "Role deleted.");
|
||||
&& run(() => apiV2Data("delete", "/volunteer-roles/{id}", { params: { id: r.id }, authToken: token }), "Role deleted.");
|
||||
|
||||
const search = async () => {
|
||||
if (!token || query.trim().length < 2) return;
|
||||
@@ -88,7 +89,7 @@ export function RosterSheet({ token, eventId, canEdit, kidsRooms = [], onMessage
|
||||
}
|
||||
};
|
||||
const assign = (roleId: string, u: { id: string; name: string }) => run(
|
||||
() => apiFetch(`/api/volunteers/manage/roles/${roleId}/assign`, { method: "POST", authToken: token, body: { userId: u.id } }),
|
||||
() => apiV2Data("post", "/volunteer-roles/{id}/assign", { params: { id: roleId }, authToken: token, body: { userId: u.id } }),
|
||||
`${u.name} is on the roster.`,
|
||||
).then(ok => { if (ok) { setAssignFor(null); setQuery(""); setFound([]); } });
|
||||
|
||||
@@ -196,9 +197,9 @@ export function RosterSheet({ token, eventId, canEdit, kidsRooms = [], onMessage
|
||||
: <span className="text-xs text-gray-400 print:inline hidden">☐</span>}
|
||||
<span className="print:hidden flex gap-1">
|
||||
{vl.checkedInAt
|
||||
? <button disabled={busy} onClick={() => run(() => apiFetch(`/api/volunteers/manage/slots/${vl.slotId}/check-in`, { method: "POST", authToken: token, body: { undo: true } }), "Check-in undone.")} className="text-xs px-2 py-1 rounded-lg border">Undo</button>
|
||||
: <button disabled={busy} onClick={() => run(() => apiFetch(`/api/volunteers/manage/slots/${vl.slotId}/check-in`, { method: "POST", authToken: token }), `${vl.name} checked in.`)} className="text-xs px-2 py-1 rounded-lg border">Check in</button>}
|
||||
{canEdit && !vl.checkedInAt && <button aria-label={`Take ${vl.name} off ${r.name}`} disabled={busy} onClick={() => confirm(`Take ${vl.name} off ${r.name}? They'll be told.`) && run(() => apiFetch(`/api/volunteers/manage/slots/${vl.slotId}`, { method: "DELETE", authToken: token }), `${vl.name} is off the roster.`)} className="text-xs p-1 rounded-lg border"><X className="w-3.5 h-3.5" /></button>}
|
||||
? <button disabled={busy} onClick={() => run(() => apiV2Data("post", "/volunteer-slots/{id}/check-in", { params: { id: vl.slotId }, authToken: token, body: { undo: true } }), "Check-in undone.")} className="text-xs px-2 py-1 rounded-lg border">Undo</button>
|
||||
: <button disabled={busy} onClick={() => run(() => apiV2Data("post", "/volunteer-slots/{id}/check-in", { params: { id: vl.slotId }, authToken: token, body: {} }), `${vl.name} checked in.`)} className="text-xs px-2 py-1 rounded-lg border">Check in</button>}
|
||||
{canEdit && !vl.checkedInAt && <button aria-label={`Take ${vl.name} off ${r.name}`} disabled={busy} onClick={() => confirm(`Take ${vl.name} off ${r.name}? They'll be told.`) && run(() => apiV2Data("post", "/volunteer-slots/{id}/remove", { params: { id: vl.slotId }, authToken: token, body: {} }), `${vl.name} is off the roster.`)} className="text-xs p-1 rounded-lg border"><X className="w-3.5 h-3.5" /></button>}
|
||||
</span>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
Reference in New Issue
Block a user