diff --git a/src/features/meetings/my_assignments/useAssignments.ts b/src/features/meetings/my_assignments/useAssignments.ts index 2c6d7f0973..8f4a6e59a8 100644 --- a/src/features/meetings/my_assignments/useAssignments.ts +++ b/src/features/meetings/my_assignments/useAssignments.ts @@ -51,8 +51,10 @@ const useMyAssignments = () => { (record) => (record.assignment.person === userUID || delegateMembers.includes(record.assignment.person)) && - new Date(record.weekOf).toISOString() >= now.toISOString() && - new Date(record.weekOf).toISOString() <= maxDate.toISOString() + formatDate(new Date(record.weekOf), 'yyyy/MM/dd') >= + formatDate(now, 'yyyy/MM/dd') && + formatDate(new Date(record.weekOf), 'yyyy/MM/dd') <= + formatDate(maxDate, 'yyyy/MM/dd') ); if (exactDate) { diff --git a/src/features/meetings/weekly_schedules/midweek_meeting/useMidweekMeeting.tsx b/src/features/meetings/weekly_schedules/midweek_meeting/useMidweekMeeting.tsx index e8f5f901d6..54cd47b3fc 100644 --- a/src/features/meetings/weekly_schedules/midweek_meeting/useMidweekMeeting.tsx +++ b/src/features/meetings/weekly_schedules/midweek_meeting/useMidweekMeeting.tsx @@ -2,7 +2,7 @@ import { useMemo, useState } from 'react'; import { useRecoilValue } from 'recoil'; import { useAppTranslation, useIntersectionObserver } from '@hooks/index'; import { schedulesState } from '@states/schedules'; -import { getWeekDate } from '@utils/date'; +import { addMonths, getWeekDate } from '@utils/date'; import { formatDate } from '@services/dateformat'; import { midweekMeetingClassCountState, @@ -48,11 +48,17 @@ const useMidweekMeeting = () => { return schedules.length === 0; }, [schedules]); + const filteredSchedules = useMemo(() => { + const minDate = formatDate(addMonths(new Date(), -2), 'yyyy/MM/dd'); + + return schedules.filter((record) => record.weekOf >= minDate); + }, [schedules]); + const week = useMemo(() => { if (typeof value === 'boolean') return null; - return schedules.at(value)?.weekOf || null; - }, [value, schedules]); + return filteredSchedules.at(value)?.weekOf || null; + }, [value, filteredSchedules]); const schedule = useMemo(() => { return schedules.find((record) => record.weekOf === week); @@ -177,7 +183,9 @@ const useMidweekMeeting = () => { const now = getWeekDate(); const weekOf = formatDate(now, 'yyyy/MM/dd'); - const index = schedules.findIndex((record) => record.weekOf === weekOf); + const index = filteredSchedules.findIndex( + (record) => record.weekOf === weekOf + ); setValue(index); }; diff --git a/src/features/meetings/weekly_schedules/week_selector/useWeekSelector.tsx b/src/features/meetings/weekly_schedules/week_selector/useWeekSelector.tsx index b9f4b1e4d1..acf7e26ab2 100644 --- a/src/features/meetings/weekly_schedules/week_selector/useWeekSelector.tsx +++ b/src/features/meetings/weekly_schedules/week_selector/useWeekSelector.tsx @@ -22,27 +22,29 @@ const useWeekSelector = ({ onChange, value }: WeekSelectorProps) => { const [currentTab, setCurrentTab] = useState(false); + const filteredSources = useMemo(() => { + const minDate = formatDate(addMonths(new Date(), -2), 'yyyy/MM/dd'); + + return sources.filter((record) => record.weekOf >= minDate); + }, [sources]); + const defaultValue = useMemo(() => { const now = getWeekDate(); const weekOf = formatDate(now, 'yyyy/MM/dd'); - return sources.findIndex((record) => record.weekOf === weekOf); - }, [sources]); + return filteredSources.findIndex((record) => record.weekOf === weekOf); + }, [filteredSources]); const weeksTab = useMemo(() => { - let filteredSources = structuredClone(sources); - - const minDate = formatDate(addMonths(new Date(), 2), 'yyyy/MM/dd'); - - filteredSources = sources.filter((record) => record.weekOf >= minDate); + let weeksList = structuredClone(filteredSources); if (scheduleType === 'midweek') { - filteredSources = filteredSources.filter( + weeksList = weeksList.filter( (record) => record.midweek_meeting.week_date_locale[lang]?.length > 0 ); } - return filteredSources.map((source, index) => { + return weeksList.map((source, index) => { const [, month, date] = source.weekOf.split('/'); const monthName = months[+month - 1]; @@ -52,7 +54,7 @@ const useWeekSelector = ({ onChange, value }: WeekSelectorProps) => { Component: <>, }; }); - }, [sources, months, t, defaultValue, scheduleType, lang]); + }, [months, t, defaultValue, scheduleType, lang, filteredSources]); const handleWeekChange = (value: number) => { setCurrentTab(value); @@ -60,7 +62,7 @@ const useWeekSelector = ({ onChange, value }: WeekSelectorProps) => { }; useEffect(() => { - if (!value) { + if (value === false) { setCurrentTab(defaultValue); onChange?.(defaultValue); } diff --git a/src/features/meetings/weekly_schedules/weekend_meeting/useWeekendMeeting.tsx b/src/features/meetings/weekly_schedules/weekend_meeting/useWeekendMeeting.tsx index b4778a9306..ea984da0dd 100644 --- a/src/features/meetings/weekly_schedules/weekend_meeting/useWeekendMeeting.tsx +++ b/src/features/meetings/weekly_schedules/weekend_meeting/useWeekendMeeting.tsx @@ -2,7 +2,7 @@ import { useMemo, useState } from 'react'; import { useRecoilValue } from 'recoil'; import { useAppTranslation, useIntersectionObserver } from '@hooks/index'; import { schedulesState } from '@states/schedules'; -import { getWeekDate, timeAddMinutes } from '@utils/date'; +import { addMonths, getWeekDate, timeAddMinutes } from '@utils/date'; import { formatDate } from '@services/dateformat'; import { userDataViewState, @@ -50,11 +50,17 @@ const useWeekendMeeting = () => { return schedules.length === 0; }, [schedules]); + const filteredSchedules = useMemo(() => { + const minDate = formatDate(addMonths(new Date(), -2), 'yyyy/MM/dd'); + + return schedules.filter((record) => record.weekOf >= minDate); + }, [schedules]); + const week = useMemo(() => { if (typeof value === 'boolean') return null; - return schedules.at(value)?.weekOf || null; - }, [value, schedules]); + return filteredSchedules.at(value)?.weekOf || null; + }, [value, filteredSchedules]); const schedule = useMemo(() => { return schedules.find((record) => record.weekOf === week); @@ -194,7 +200,9 @@ const useWeekendMeeting = () => { const now = getWeekDate(); const weekOf = formatDate(now, 'yyyy/MM/dd'); - const index = schedules.findIndex((record) => record.weekOf === weekOf); + const index = filteredSchedules.findIndex( + (record) => record.weekOf === weekOf + ); setValue(index); }; diff --git a/src/pages/dashboard/useDashboard.tsx b/src/pages/dashboard/useDashboard.tsx index 88eee4c478..2d39f46a80 100644 --- a/src/pages/dashboard/useDashboard.tsx +++ b/src/pages/dashboard/useDashboard.tsx @@ -10,6 +10,7 @@ import { isMyAssignmentOpenState } from '@states/app'; import { assignmentsHistoryState } from '@states/schedules'; import { getWeekDate } from '@utils/date'; import { isDemo } from '@constants/index'; +import { formatDate } from '@services/dateformat'; const useDashboard = () => { const setIsMyAssignmentOpen = useSetRecoilState(isMyAssignmentOpenState); @@ -31,12 +32,12 @@ const useDashboard = () => { const [newCongSnack, setNewCongSnack] = useState(initialSnackValue); const countFutureAssignments = useMemo(() => { - const now = getWeekDate().toISOString(); + const now = formatDate(getWeekDate(), 'yyyy/MM/dd'); const personAssignments = assignmentsHistory.filter( (record) => record.assignment.person === userUID && - new Date(record.weekOf).toISOString() >= now + formatDate(new Date(record.weekOf), 'yyyy/MM/dd') >= now ); return personAssignments.length;