import { FC } from 'react'; import AddToCalendar from '@culturehq/add-to-calendar'; interface Event { id: number; title: string; date?: string | null; // Make date optional and allow it to be null description: string; images: { [key: string]: string }; start_time?: string | null; end_time?: string | null; } interface EventCardProps { event: Event; onClick: () => void; } const EventCard: FC = ({ event, onClick }) => { const hasImages = Object.values(event.images).some(url => url !== ''); // Initialize variables for startsAt, endsAt, and formattedDate let startsAt: string | null = null; let endsAt: string | null = null; let formattedDate: string | null = null; if (event.date) { // Parse the event date const eventDate = new Date(event.date); // Format the date as "Wednesday, August 21" formattedDate = eventDate.toLocaleDateString('en-US', { weekday: 'long', month: 'long', day: 'numeric', }); // Process the start and end times if (event.start_time) { startsAt = new Date(`${event.date}T${event.start_time}`).toISOString(); } else { startsAt = eventDate.toISOString(); } if (event.end_time) { endsAt = new Date(`${event.date}T${event.end_time}`).toISOString(); } else { endsAt = new Date(new Date(startsAt).getTime() + 60 * 60 * 1000).toISOString(); } } else { console.error('Event date is not defined'); } return (

{event.title}

{formattedDate || 'Date not provided'} , {event.start_time || 'No start time provided'}
{hasImages && (
{event.title}
)}
{startsAt && ( )}
); }; export default EventCard;