diff --git a/src/pages/CreateEventPage.tsx b/src/pages/CreateEventPage.tsx index 2bd27bd..054bfee 100644 --- a/src/pages/CreateEventPage.tsx +++ b/src/pages/CreateEventPage.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect } from 'react'; +import { useState, useEffect, useMemo } from 'react'; import { useSeoMeta } from '@unhead/react'; import { useNavigate, useSearchParams } from 'react-router-dom'; import ngeohash from 'ngeohash'; @@ -158,6 +158,14 @@ export default function CreateEventPage() { return acc; }, {} as Record); + // Today (local) as YYYY-MM-DD, used as the min for the date pickers so hosts + // can't accidentally schedule an event in the past. + const todayStr = useMemo(() => { + const d = new Date(); + const off = d.getTimezoneOffset(); + return new Date(d.getTime() - off * 60_000).toISOString().split('T')[0]; + }, []); + const toggleType = (type: string) => { setSelectedTypes((prev) => prev.includes(type) ? prev.filter((t) => t !== type) : [...prev, type] @@ -272,6 +280,17 @@ export default function CreateEventPage() { return; } + // Guard against scheduling in the past (a 10-min grace window covers + // "starting right now" without rejecting it). + if (startTimestamp < Math.floor(Date.now() / 1000) - 600) { + toast({ + title: 'That start time is in the past', + description: 'Pick a date and time in the future so skaters can RSVP and show up.', + variant: 'destructive', + }); + return; + } + // Parse end time if provided let endTimestamp: number | undefined; if (endDate && endTime) { @@ -535,6 +554,7 @@ export default function CreateEventPage() { setStartDate(e.target.value)} required /> @@ -554,6 +574,7 @@ export default function CreateEventPage() { setEndDate(e.target.value)} />