Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: availability use 2 years to call to api #189

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
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 @@
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
Loading