/** Volunteer rosters (1.46.0): shared types and helpers for the Serving, roster and check-in pages. */ export type Shift = { startsAt: string; endsAt: string; text: string; hours?: number }; export type RosterVolunteer = { slotId: string; userId: string; name: string; phone: string | null; email: string | null; assignedBy: string | null; checkedInAt: string | null; checkedInBy: string | null; checkInMethod: "qr" | "manual" | null; swapOpen: boolean; hasTicket: boolean; }; export type ServingRole = { id: string; eventId: string; sessionId: string | null; sessionLabel: string | null; name: string; description: string; startsAt: string | null; endsAt: string | null; shift: Shift & { hours: number }; kidsRoom: { id: string; name: string } | null; order: number; past: boolean; needed: number; filled: number; open: number; full: boolean; mine: { slotId: string; checkedInAt: string | null; swapId: string | null } | null; coverNeeded: { swapId: string; note: string }[]; /** Staff only. */ volunteers?: RosterVolunteer[]; }; export type Roster = { event: { id: string; title: string; startDate: string; endDate: string; scheduleType: string; location: string | null; kidsCheckIn: boolean }; sessions: { id: string; label: string; startsAt: string; endsAt: string }[]; roles: ServingRole[]; totals: { needed: number; filled: number; checkedIn: number; fillRate: number | null }; }; export type MySlot = { slotId: string; role: { id: string; name: string; description: string; sessionLabel: string | null; kidsRoom: string | null }; event: { id: string; title: string; location: string | null }; shift: Shift & { hours: number }; checkedInAt: string | null; canCheckIn: boolean; past: boolean; swapId: string | null; hasTicket: boolean; }; export type CoverRequest = { swapId: string; note: string; from: string | null; role: { id: string; name: string; sessionLabel: string | null }; event: { id: string; title: string }; shift: Shift; }; export type ServingEvent = { id: string; title: string; startDate: string; endDate: string; location: string | null; roles: number }; export type RosterEvent = { id: string; title: string; startDate: string; endDate: string; scheduleType: string; campusId: string | null; roles: number }; export type HoursRow = { userId: string; name: string; shifts: number; hours: number; events: number }; /** The page the volunteer check-in QR code opens (phone cameras open it straight away). */ export function checkInUrl(qr: string): string { const origin = typeof window !== "undefined" ? window.location.origin : ""; return `${origin}/serve/check-in?code=${encodeURIComponent(qr)}`; } /** A Date as the value of a datetime-local input (local time), or "". */ export function toLocalInput(iso: string | null | undefined): string { if (!iso) return ""; const d = new Date(iso); const pad = (n: number) => String(n).padStart(2, "0"); return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`; } /** A datetime-local value as an ISO string, or null when empty. */ export function fromLocalInput(v: string): string | null { return v ? new Date(v).toISOString() : null; } export const hoursText = (h: number) => `${h % 1 === 0 ? h : h.toFixed(2).replace(/0$/, "")} h`;