From 1ad2a1838e5b5ef8c728f2d6ffecd7df34301501 Mon Sep 17 00:00:00 2001 From: Zi Nean Teoh Date: Thu, 26 Oct 2023 23:33:20 -0500 Subject: [PATCH] fix error when calendar has new events but count does not exist --- components/Organizer/EventsTab/EventsTab.tsx | 26 ++++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/components/Organizer/EventsTab/EventsTab.tsx b/components/Organizer/EventsTab/EventsTab.tsx index 296d01b5..87d07247 100644 --- a/components/Organizer/EventsTab/EventsTab.tsx +++ b/components/Organizer/EventsTab/EventsTab.tsx @@ -124,15 +124,25 @@ export default function Events() { if (eventsData && eventsData.length > 0) { setEvents( eventsData.map((event: EventData) => { - // TODO convert startTime and endTime here so we don't have to do it in the render function - const count = eventsCountData?.find((e: any) => e._id === event._id) || 0; + if (eventsCountData && eventsCountData.length > 0) { + // check counts data exist. if so, compute count for each event + const count = eventsCountData?.find((e: any) => e._id === event._id) || 0; - return { - key: event._id, - ...event, - setCurEvent, - count: count, - }; + return { + key: event._id, + ...event, + setCurEvent, + count: count, + }; + } else { + // counts data does not exist yet. set count to 0 + return { + key: event._id, + ...event, + setCurEvent, + count: 0, + }; + } }) ); }