Skip to content

Commit

Permalink
Merge pull request #189 from autentia/feat/availability_with_2_years
Browse files Browse the repository at this point in the history
feat: availability use 2 years to call to api
  • Loading branch information
Francisco Javier Martínez authored Dec 5, 2023
2 parents d2c86fc + db72fed commit 884c3c1
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ 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 [requiredFiltersChange, setRequiredFiltersChange] = useState<boolean>(false)
const [absenceFilters, setAbsenceFilters] = useState<AbsenceFilters>({
startDate: chrono().format(chrono.DATE_FORMAT),
endDate: chrono().format(chrono.DATE_FORMAT)
Expand Down Expand Up @@ -47,24 +49,31 @@ export const AvailabilityTable: FC = () => {
absenceFilters.organizationIds !== undefined || absenceFilters.userIds !== undefined

useEffect(() => {
if (requiredFiltersAreSelected()) {
if (
requiredFiltersAreSelected() &&
(requiredFiltersChange === true || 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)
setRequiredFiltersChange(false)
})
} else {
setUserAbsences([])
}
}, [absenceFilters, selectedDateInterval])
}, [absenceFilters, selectedDateInterval, previousDate])

Check warning on line 69 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', 'requiredFiltersChange', and 'selectedDate'. Either include them or remove the dependency array

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

const onFilterChange = (updatedFilter: Partial<AbsenceFilters>) => {
setAbsenceFilters({ ...absenceFilters, ...updatedFilter })
setRequiredFiltersChange(true)
}

useEffect(() => {
Expand Down

0 comments on commit 884c3c1

Please sign in to comment.