Skip to content

Commit

Permalink
feat: availability use 2 years to call to api
Browse files Browse the repository at this point in the history
  • Loading branch information
IB-AUTEN-rvillalba committed Dec 4, 2023
1 parent d2c86fc commit 9f87ea6
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import styles from './availability-table.module.css'
export const AvailabilityTable: FC = () => {
const { selectedDate } = useCalendarContext()
const [userAbsences, setUserAbsences] = useState<UserAbsence[]>([])
const [previousDate, setPreviousDate] = useState<Date | null>(null)
const [absenceFilters, setAbsenceFilters] = useState<AbsenceFilters>({
startDate: chrono().format(chrono.DATE_FORMAT),
endDate: chrono().format(chrono.DATE_FORMAT)
Expand Down Expand Up @@ -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])

Check warning on line 67 in src/features/binnacle/features/availability/ui/components/availability-table/availability-table.tsx

View workflow job for this annotation

GitHub Actions / Test

React Hook useEffect has missing dependencies: 'getAbsencesQry', 'requiredFiltersAreSelected', and 'selectedDate'. Either include them or remove the dependency array

const checkIfHoliday = (day: Date) =>
holidays.some((holiday) => chrono(day).isSameDay(holiday.date))
Expand Down

0 comments on commit 9f87ea6

Please sign in to comment.