From 08e70de2acb75059c93633880fb058d1cedf0b68 Mon Sep 17 00:00:00 2001 From: gurramkarthiknetha Date: Fri, 13 Dec 2024 03:00:37 +0530 Subject: [PATCH] t7 --- .../EventCalendar/EventCalendar.tsx | 45 ++++++------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/src/components/EventCalendar/EventCalendar.tsx b/src/components/EventCalendar/EventCalendar.tsx index 7bb17ddd6c..9cc44c88f8 100644 --- a/src/components/EventCalendar/EventCalendar.tsx +++ b/src/components/EventCalendar/EventCalendar.tsx @@ -89,8 +89,6 @@ const Calendar: React.FC = ({ ): 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); @@ -122,12 +120,7 @@ const Calendar: React.FC = ({ 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); @@ -143,29 +136,27 @@ const Calendar: React.FC = ({ 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); @@ -173,12 +164,7 @@ const Calendar: React.FC = ({ setCurrentMonth(currentMonth + 1); } }; - - /** - * Moves the calendar view to the previous date. - */ const handlePrevDate = (): void => { - /*istanbul ignore next*/ if (currentDate > 1) { setCurrentDate(currentDate - 1); } else { @@ -197,10 +183,7 @@ const Calendar: React.FC = ({ } } }; - - /*istanbul ignore next*/ const handleNextDate = (): void => { - /*istanbul ignore next*/ const lastDayOfCurrentMonth = new Date( currentYear, currentMonth - 1,