Fix date parsing errors in EventsListPage
- 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 <noreply@anthropic.com>
This commit is contained in:
@@ -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}
|
||||
</td>
|
||||
<td className="px-6 py-4 text-sm text-neutral-700">
|
||||
{format(parseISO(event.event_date), 'MMM d, yyyy')}
|
||||
{event.event_date ? format(parseISO(event.event_date), 'MMM d, yyyy') : 'N/A'}
|
||||
</td>
|
||||
<td className="px-6 py-4">
|
||||
<span className={`inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ${status.color}`}>
|
||||
@@ -318,7 +322,7 @@ export const EventsListPage: React.FC = () => {
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-6 py-4 text-sm text-neutral-700">
|
||||
{format(parseISO(event.expires_at), 'MMM d, yyyy')}
|
||||
{event.expires_at ? format(parseISO(event.expires_at), 'MMM d, yyyy') : 'N/A'}
|
||||
</td>
|
||||
<td className="px-6 py-4 text-right">
|
||||
<div className="relative inline-block text-left">
|
||||
|
||||
Reference in New Issue
Block a user