diff --git a/src/components/WorkshopRoster.ts b/src/components/WorkshopRoster.ts index 576b31d..2ffff38 100644 --- a/src/components/WorkshopRoster.ts +++ b/src/components/WorkshopRoster.ts @@ -1,4 +1,12 @@ -import { getCleanDigitsPhone } from "../utils"; +import { ApiError, fetchRosters, quickCheckin } from "../api"; +import type { + QuickCheckinBookingPayload, + QuickCheckinWalkInPayload, + RosterAttendee, + RosterSession, +} from "../types"; +import { formatMexicanPhone, getCleanDigitsPhone } from "../utils"; +import { showToast } from "./Toast"; /** * Format workshop session capacity label according to spec AC-1: @@ -45,6 +53,45 @@ export function buildWhatsAppUrl(phone: string): string { return `https://wa.me/${clean}`; } +/** + * Format ISO datetime to 24-hour time in Mexico City timezone (e.g. 18:00) + */ +export function formatRosterSessionTime(isoStr: string): string { + try { + const dt = new Date(isoStr); + if (Number.isNaN(dt.getTime())) return isoStr; + return new Intl.DateTimeFormat("es-MX", { + timeZone: "America/Mexico_City", + hour: "2-digit", + minute: "2-digit", + hour12: false, + }).format(dt); + } catch { + return isoStr; + } +} + +/** + * Helper to get today's date formatted as YYYY-MM-DD in Mexico City timezone + */ +export function getTodayDateString(): string { + try { + const formatter = new Intl.DateTimeFormat("en-CA", { + timeZone: "America/Mexico_City", + year: "numeric", + month: "2-digit", + day: "2-digit", + }); + return formatter.format(new Date()); + } catch { + const d = new Date(); + const y = d.getFullYear(); + const m = String(d.getMonth() + 1).padStart(2, "0"); + const day = String(d.getDate()).padStart(2, "0"); + return `${y}-${m}-${day}`; + } +} + export type ConflictType = | "ALREADY_CHECKED_IN" | "CAPACITY_EXCEEDED" @@ -64,3 +111,744 @@ export function disambiguate409Error(detail?: string): ConflictType { } return "UNKNOWN"; } + +/** + * Main component renderer for the Group Workshop Roster view (#rosters) + */ +export function renderWorkshopRoster( + container: HTMLElement, + onStateChange?: () => void, +): void { + let selectedDate = getTodayDateString(); + let cachedSessions: RosterSession[] = []; + + container.innerHTML = ` +
Pase de lista digital, cobro en puerta y registro de asistentes sin cita.
+Fecha seleccionada: ${dateStr}. Navega a otra fecha para consultar talleres.
+Aún no hay asistentes registrados para esta sesión.
+