Skip to content

Commit

Permalink
fix error when calendar has new events but count does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
zineanteoh committed Oct 27, 2023
1 parent a9dc9f3 commit 1ad2a18
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions components/Organizer/EventsTab/EventsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
})
);
}
Expand Down

1 comment on commit 1ad2a18

@vercel
Copy link

@vercel vercel bot commented on 1ad2a18 Oct 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.