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

fix: hooks warnings #194

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
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 @@ -17,15 +17,18 @@ export const NextMonthArrow = () => {
setSelectedDate(nextMonth)
}, [selectedDate, setSelectedDate])

const handlePressedKey = (e: KeyboardEvent) => {
handleKeyPressWhenModalIsNotOpenedOrInputIsNotFocused(e.key, 'n', handleNextMonthClick)
}
const handlePressedKey = useCallback(
(e: KeyboardEvent) => {
handleKeyPressWhenModalIsNotOpenedOrInputIsNotFocused(e.key, 'n', handleNextMonthClick)
},
[handleNextMonthClick]
)

useEffect(() => {
document.addEventListener('keydown', handlePressedKey)

return () => document.removeEventListener('keydown', handlePressedKey)
}, [selectedDate, setSelectedDate])
}, [handlePressedKey, selectedDate, setSelectedDate])

const ariaLabel = t('accessibility.next_month', {
monthStr: chrono(selectedDate).plus(1, 'month').format('LLLL yyyy')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ export const PrevMonthArrow = () => {
setSelectedDate(prevMonth)
}, [selectedDate, setSelectedDate])

const handlePressedKey = (e: KeyboardEvent) => {
handleKeyPressWhenModalIsNotOpenedOrInputIsNotFocused(e.key, 'p', handlePrevMonthClick)
}
const handlePressedKey = useCallback(
(e: KeyboardEvent) => {
handleKeyPressWhenModalIsNotOpenedOrInputIsNotFocused(e.key, 'p', handlePrevMonthClick)
},
[handlePrevMonthClick]
)

useEffect(() => {
document.addEventListener('keydown', handlePressedKey)

return () => document.removeEventListener('keydown', handlePressedKey)
}, [selectedDate, setSelectedDate])
}, [handlePressedKey, selectedDate, setSelectedDate])

const ariaLabel = t('accessibility.prev_month', {
monthStr: chrono(selectedDate).minus(1, 'month').format('LLLL yyyy')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, Text } from '@chakra-ui/react'
import { FC, useEffect, useState } from 'react'
import { FC, useCallback, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { chrono } from '../../../../../../../shared/utils/chrono'
import { useCalendarContext } from '../../contexts/calendar-context'
Expand All @@ -16,21 +16,24 @@ export const TodayButton: FC = () => {
setIsCurrentMonth(chrono(selectedDate).isThisMonth())
}, [selectedDate])

const handlePressedKey = (e: KeyboardEvent) => {
handleKeyPressWhenModalIsNotOpenedOrInputIsNotFocused(e.key, 't', handleSetCurrentMonth)
}
const handleSetCurrentMonth = useCallback(() => {
if (isCurrentMonth) return

setSelectedDate(new Date())
}, [isCurrentMonth, setSelectedDate])

const handlePressedKey = useCallback(
(e: KeyboardEvent) => {
handleKeyPressWhenModalIsNotOpenedOrInputIsNotFocused(e.key, 't', handleSetCurrentMonth)
},
[handleSetCurrentMonth]
)

useEffect(() => {
document.addEventListener('keydown', handlePressedKey)

return () => document.removeEventListener('keydown', handlePressedKey)
}, [selectedDate, isCurrentMonth])

const handleSetCurrentMonth = () => {
if (isCurrentMonth) return

setSelectedDate(new Date())
}
}, [handlePressedKey, selectedDate, isCurrentMonth])

return (
<Button variant={'outline'} onClick={handleSetCurrentMonth}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const ProjectRolesCombo = forwardRef<HTMLInputElement, ComboProps>((props
}).then((roles) => {
setItems(roles)
})
}, [project?.id, executeUseCase, selectedDate])
}, [props.userId, project?.id, executeUseCase, selectedDate])

return (
<ComboField
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, useEffect, useMemo, useState } from 'react'
import { FC, useCallback, useEffect, useMemo, useState } from 'react'
import { Box, Flex, Spinner, Table, Tbody, Td, Text, Th, Thead, Tr } from '@chakra-ui/react'
import { chrono } from '../../../../../../../shared/utils/chrono'
import { useExecuteUseCaseOnMount } from '../../../../../../../shared/arch/hooks/use-execute-use-case-on-mount'
Expand Down Expand Up @@ -45,9 +45,9 @@ export const AvailabilityTable: FC = () => {
selectedDateInterval.start.getFullYear()
)

const requiredFiltersAreSelected = () =>
absenceFilters.organizationIds !== undefined || absenceFilters.userIds !== undefined

const requiredFiltersAreSelected = useCallback(() => {
return absenceFilters.organizationIds !== undefined || absenceFilters.userIds !== undefined
}, [absenceFilters.organizationIds, absenceFilters.userIds])
useEffect(() => {
if (
requiredFiltersAreSelected() &&
Expand All @@ -66,7 +66,15 @@ export const AvailabilityTable: FC = () => {
setRequiredFiltersChange(false)
})
}
}, [absenceFilters, selectedDateInterval, previousDate])
}, [
getAbsencesQry,
requiredFiltersAreSelected,
requiredFiltersChange,
selectedDate,
absenceFilters,
selectedDateInterval,
previousDate
])

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