Skip to content

Commit

Permalink
t7
Browse files Browse the repository at this point in the history
  • Loading branch information
gurramkarthiknetha committed Dec 12, 2024
1 parent 5d7118a commit 08e70de
Showing 1 changed file with 14 additions and 31 deletions.
45 changes: 14 additions & 31 deletions src/components/EventCalendar/EventCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ const Calendar: React.FC<InterfaceCalendarProps> = ({
): InterfaceEventListCardProps[] => {
const data: InterfaceEventListCardProps[] = [];
if (userRole === Role.SUPERADMIN) return eventData;
// Hard to test all the cases
/* istanbul ignore next */
if (userRole === Role.ADMIN) {
eventData?.forEach((event) => {
if (event.isPublic) data.push(event);
Expand Down Expand Up @@ -122,12 +120,7 @@ const Calendar: React.FC<InterfaceCalendarProps> = ({
const data = filterData(eventData, orgData, userRole, userId);
setEvents(data);
}, [eventData, orgData, userRole, userId]);

/**
* Moves the calendar view to the previous month.
*/
const handlePrevMonth = (): void => {
/*istanbul ignore next*/
if (currentMonth === 0) {
setCurrentMonth(11);
setCurrentYear(currentYear - 1);
Expand All @@ -143,42 +136,35 @@ const Calendar: React.FC<InterfaceCalendarProps> = ({

return holidays.filter((holiday) => {
if (!holiday.date) {
console.warn(`Holiday "${holiday.name}" has no date specified.`);
return false;
}

try {
if (holiday.date) {
const holidayMonth = dayjs(holiday.date, 'MM-DD', true).month();
return holidayMonth === currentMonth;
} else {
console.warn(`Holiday "${holiday.name}" has no date specified.`);
return false;
}
} catch (error) {
console.error(
`Error processing holiday "${holiday.name}": ${error instanceof Error ? error.message : 'Unknown error'}`,
);
return false;
}
const holidayMonth = dayjs(holiday.date, 'MM-DD', true).month();
return holidayMonth === currentMonth;
});
}, [holidays, currentMonth]);
useEffect(() => {
if (!Array.isArray(holidays)) {
console.error('Invalid holidays array');
return;
}

holidays.forEach((holiday) => {
if (!holiday.date) {
console.warn(`Holiday "${holiday.name}" has no date specified.`);
}
});
}, [holidays]);

const handleNextMonth = (): void => {
/*istanbul ignore next*/
if (currentMonth === 11) {
setCurrentMonth(0);
setCurrentYear(currentYear + 1);
} else {
setCurrentMonth(currentMonth + 1);
}
};

/**
* Moves the calendar view to the previous date.
*/
const handlePrevDate = (): void => {
/*istanbul ignore next*/
if (currentDate > 1) {
setCurrentDate(currentDate - 1);
} else {
Expand All @@ -197,10 +183,7 @@ const Calendar: React.FC<InterfaceCalendarProps> = ({
}
}
};

/*istanbul ignore next*/
const handleNextDate = (): void => {
/*istanbul ignore next*/
const lastDayOfCurrentMonth = new Date(
currentYear,
currentMonth - 1,
Expand Down

0 comments on commit 08e70de

Please sign in to comment.