feat(SW-718) Added type FilterValues
This commit is contained in:
@@ -18,6 +18,7 @@ import { Tooltip } from "@/components/TempDesignSystem/Tooltip"
|
|||||||
import styles from "./roomFilter.module.css"
|
import styles from "./roomFilter.module.css"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
type FilterValues,
|
||||||
type RoomFilterProps,
|
type RoomFilterProps,
|
||||||
RoomPackageCodeEnum,
|
RoomPackageCodeEnum,
|
||||||
} from "@/types/components/hotelReservation/selectRate/roomFilter"
|
} from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||||
@@ -38,13 +39,10 @@ export default function RoomFilter({
|
|||||||
const packagesFromSearchParams =
|
const packagesFromSearchParams =
|
||||||
searchParams.get(`room[${roomListIndex}].packages`)?.split(",") ?? []
|
searchParams.get(`room[${roomListIndex}].packages`)?.split(",") ?? []
|
||||||
|
|
||||||
return filterOptions.reduce(
|
return filterOptions.reduce<FilterValues>((acc, option) => {
|
||||||
(acc, option) => {
|
acc[option.code] = packagesFromSearchParams.includes(option.code)
|
||||||
acc[option.code] = packagesFromSearchParams.includes(option.code)
|
return acc
|
||||||
return acc
|
}, {})
|
||||||
},
|
|
||||||
{} as Record<string, boolean | undefined>
|
|
||||||
)
|
|
||||||
}, [filterOptions, searchParams, roomListIndex])
|
}, [filterOptions, searchParams, roomListIndex])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -56,7 +54,7 @@ export default function RoomFilter({
|
|||||||
}, [initialFilterValues])
|
}, [initialFilterValues])
|
||||||
|
|
||||||
const intl = useIntl()
|
const intl = useIntl()
|
||||||
const methods = useForm<Record<string, boolean | undefined>>({
|
const methods = useForm<FilterValues>({
|
||||||
defaultValues: initialFilterValues,
|
defaultValues: initialFilterValues,
|
||||||
mode: "all",
|
mode: "all",
|
||||||
reValidateMode: "onChange",
|
reValidateMode: "onChange",
|
||||||
@@ -73,7 +71,7 @@ export default function RoomFilter({
|
|||||||
id: "Pet-friendly rooms have an additional fee of 20 EUR per stay",
|
id: "Pet-friendly rooms have an additional fee of 20 EUR per stay",
|
||||||
})
|
})
|
||||||
const submitFilter = useCallback(
|
const submitFilter = useCallback(
|
||||||
(data: Record<string, boolean | undefined>) => {
|
(data: FilterValues) => {
|
||||||
onFilter(data)
|
onFilter(data)
|
||||||
},
|
},
|
||||||
[onFilter]
|
[onFilter]
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ export interface DefaultFilterOptions {
|
|||||||
description: string
|
description: string
|
||||||
itemCode: string | undefined
|
itemCode: string | undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FilterValues {
|
||||||
|
[key: string]: boolean | undefined
|
||||||
|
}
|
||||||
export interface RoomFilterProps {
|
export interface RoomFilterProps {
|
||||||
numberOfRooms: number
|
numberOfRooms: number
|
||||||
onFilter: (filter: Record<string, boolean | undefined>) => void
|
onFilter: (filter: Record<string, boolean | undefined>) => void
|
||||||
|
|||||||
Reference in New Issue
Block a user