import { useState } from "react"; import { TIMEZONE_OPTIONS } from "~/components/league/TimezoneSelect"; const VALID_TIMEZONES = new Set( TIMEZONE_OPTIONS.flatMap((g) => g.zones.map((z) => z.value)) ); interface TimezonePromptBannerProps { /** Called with the saved timezone value after a successful POST. */ onSaved?: (timezone: string) => void; } export function TimezonePromptBanner({ onSaved }: TimezonePromptBannerProps) { const [dismissed, setDismissed] = useState(false); const [saving, setSaving] = useState(false); const [saved, setSaved] = useState(false); if (dismissed || saved) return null; const detectedTz = typeof window !== "undefined" ? (() => { try { const tz = Intl.DateTimeFormat().resolvedOptions().timeZone; return VALID_TIMEZONES.has(tz) ? tz : null; } catch { return null; } })() : null; if (!detectedTz) return null; const handleSave = async () => { setSaving(true); try { const body = new FormData(); body.set("timezone", detectedTz); const res = await fetch("/api/user/timezone", { method: "POST", body }); if (res.ok) { setSaved(true); onSaved?.(detectedTz); } } finally { setSaving(false); } }; return (
Set your timezone to {detectedTz} for overnight pick protection?
); }