From 9f87ea6c04f70b0754196bbce15a909168802f08 Mon Sep 17 00:00:00 2001 From: Raul Villalba Medina Date: Mon, 4 Dec 2023 14:50:20 +0100 Subject: [PATCH 1/2] feat: availability use 2 years to call to api --- .../availability-table/availability-table.tsx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/features/binnacle/features/availability/ui/components/availability-table/availability-table.tsx b/src/features/binnacle/features/availability/ui/components/availability-table/availability-table.tsx index ed673cf0..6c02ddb5 100644 --- a/src/features/binnacle/features/availability/ui/components/availability-table/availability-table.tsx +++ b/src/features/binnacle/features/availability/ui/components/availability-table/availability-table.tsx @@ -19,6 +19,7 @@ import styles from './availability-table.module.css' export const AvailabilityTable: FC = () => { const { selectedDate } = useCalendarContext() const [userAbsences, setUserAbsences] = useState([]) + const [previousDate, setPreviousDate] = useState(null) const [absenceFilters, setAbsenceFilters] = useState({ startDate: chrono().format(chrono.DATE_FORMAT), endDate: chrono().format(chrono.DATE_FORMAT) @@ -47,18 +48,23 @@ export const AvailabilityTable: FC = () => { absenceFilters.organizationIds !== undefined || absenceFilters.userIds !== undefined useEffect(() => { - if (requiredFiltersAreSelected()) { + if ( + requiredFiltersAreSelected() && + previousDate?.getFullYear() !== selectedDate.getFullYear() + ) { getAbsencesQry({ ...absenceFilters, - startDate: chrono(selectedDateInterval.start).minus(5, 'day').format(chrono.DATE_FORMAT), - endDate: chrono(selectedDateInterval.end).plus(5, 'day').format(chrono.DATE_FORMAT) + startDate: chrono(selectedDateInterval.start) + .startOf('year') + .minus(1, 'year') + .format(chrono.DATE_FORMAT), + endDate: chrono(selectedDate).endOf('year').format(chrono.DATE_FORMAT) }).then((absences) => { setUserAbsences(absences) + setPreviousDate(selectedDate) }) - } else { - setUserAbsences([]) } - }, [absenceFilters, selectedDateInterval]) + }, [absenceFilters, selectedDateInterval, previousDate]) const checkIfHoliday = (day: Date) => holidays.some((holiday) => chrono(day).isSameDay(holiday.date)) From db72fedca3b5812f75b43a9920328d8f4ea0c658 Mon Sep 17 00:00:00 2001 From: Raul Villalba Medina Date: Tue, 5 Dec 2023 09:39:25 +0100 Subject: [PATCH 2/2] feat: availability use 2 years to call to api --- .../ui/components/availability-table/availability-table.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/features/binnacle/features/availability/ui/components/availability-table/availability-table.tsx b/src/features/binnacle/features/availability/ui/components/availability-table/availability-table.tsx index 6c02ddb5..7e83c701 100644 --- a/src/features/binnacle/features/availability/ui/components/availability-table/availability-table.tsx +++ b/src/features/binnacle/features/availability/ui/components/availability-table/availability-table.tsx @@ -20,6 +20,7 @@ export const AvailabilityTable: FC = () => { const { selectedDate } = useCalendarContext() const [userAbsences, setUserAbsences] = useState([]) const [previousDate, setPreviousDate] = useState(null) + const [requiredFiltersChange, setRequiredFiltersChange] = useState(false) const [absenceFilters, setAbsenceFilters] = useState({ startDate: chrono().format(chrono.DATE_FORMAT), endDate: chrono().format(chrono.DATE_FORMAT) @@ -50,7 +51,7 @@ export const AvailabilityTable: FC = () => { useEffect(() => { if ( requiredFiltersAreSelected() && - previousDate?.getFullYear() !== selectedDate.getFullYear() + (requiredFiltersChange === true || previousDate?.getFullYear() !== selectedDate.getFullYear()) ) { getAbsencesQry({ ...absenceFilters, @@ -62,6 +63,7 @@ export const AvailabilityTable: FC = () => { }).then((absences) => { setUserAbsences(absences) setPreviousDate(selectedDate) + setRequiredFiltersChange(false) }) } }, [absenceFilters, selectedDateInterval, previousDate]) @@ -71,6 +73,7 @@ export const AvailabilityTable: FC = () => { const onFilterChange = (updatedFilter: Partial) => { setAbsenceFilters({ ...absenceFilters, ...updatedFilter }) + setRequiredFiltersChange(true) } useEffect(() => {