Skip to content

Commit

Permalink
fix: hooks warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenGonzalezAutentia committed May 16, 2024
1 parent 087269e commit 8ffebed
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 25 deletions.
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

0 comments on commit 8ffebed

Please sign in to comment.