From 35681d534606cc95c48ef141b36fd654bcad68bd Mon Sep 17 00:00:00 2001 From: paul Date: Mon, 7 Jul 2025 13:58:33 +0200 Subject: [PATCH] Fix date parsing errors in EventsListPage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add null checks for all date fields before parsing - Handle cases where created_at, event_date, or expires_at might be null/undefined - Prevent "Invalid time value" errors when viewing events list - Sort function now handles null dates gracefully This fixes the RangeError that occurred when navigating to the events page after creating an event. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- frontend/src/pages/admin/EventsListPage.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/frontend/src/pages/admin/EventsListPage.tsx b/frontend/src/pages/admin/EventsListPage.tsx index 1747e65..098bb91 100644 --- a/frontend/src/pages/admin/EventsListPage.tsx +++ b/frontend/src/pages/admin/EventsListPage.tsx @@ -75,7 +75,7 @@ export const EventsListPage: React.FC = () => { } else if (isExpiringFilter) { events = events.filter(e => { if (!e.is_active || e.is_archived) return false; - const days = differenceInDays(parseISO(e.expires_at), new Date()); + const days = e.expires_at ? differenceInDays(parseISO(e.expires_at), new Date()) : 0; return days <= 7 && days > 0; }); } else if (statusFilter === 'archived') { @@ -93,7 +93,11 @@ export const EventsListPage: React.FC = () => { } // Sort by creation date (newest first) - events.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()); + events.sort((a, b) => { + const dateA = a.created_at ? new Date(a.created_at).getTime() : 0; + const dateB = b.created_at ? new Date(b.created_at).getTime() : 0; + return dateB - dateA; + }); return events; }, [data?.events, statusFilter, searchTerm]); @@ -118,7 +122,7 @@ export const EventsListPage: React.FC = () => { if (event.is_archived) return { label: 'Archived', color: 'text-neutral-500 bg-neutral-100' }; if (!event.is_active) return { label: 'Inactive', color: 'text-red-600 bg-red-100' }; - const days = differenceInDays(parseISO(event.expires_at), new Date()); + const days = event.expires_at ? differenceInDays(parseISO(event.expires_at), new Date()) : 0; if (days <= 0) return { label: 'Expired', color: 'text-red-600 bg-red-100' }; if (days <= 7) return { label: `${days}d left`, color: 'text-orange-600 bg-orange-100' }; @@ -310,7 +314,7 @@ export const EventsListPage: React.FC = () => { {event.event_type} - {format(parseISO(event.event_date), 'MMM d, yyyy')} + {event.event_date ? format(parseISO(event.event_date), 'MMM d, yyyy') : 'N/A'} @@ -318,7 +322,7 @@ export const EventsListPage: React.FC = () => { - {format(parseISO(event.expires_at), 'MMM d, yyyy')} + {event.expires_at ? format(parseISO(event.expires_at), 'MMM d, yyyy') : 'N/A'}