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