From c8ed172f0e23821c8da8ddf807e87bafcf9010b0 Mon Sep 17 00:00:00 2001 From: Pontus Dreij Date: Fri, 24 Jan 2025 11:45:10 +0100 Subject: [PATCH] feat(SW-718) Added type FilterValues --- .../SelectRate/RoomFilter/index.tsx | 16 +++++++--------- .../hotelReservation/selectRate/roomFilter.ts | 4 ++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/components/HotelReservation/SelectRate/RoomFilter/index.tsx b/components/HotelReservation/SelectRate/RoomFilter/index.tsx index f8eb91356..ea1a1d95a 100644 --- a/components/HotelReservation/SelectRate/RoomFilter/index.tsx +++ b/components/HotelReservation/SelectRate/RoomFilter/index.tsx @@ -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 - ) + return filterOptions.reduce((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>({ + const methods = useForm({ 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) => { + (data: FilterValues) => { onFilter(data) }, [onFilter] diff --git a/types/components/hotelReservation/selectRate/roomFilter.ts b/types/components/hotelReservation/selectRate/roomFilter.ts index 9c0831a4b..8d506ba78 100644 --- a/types/components/hotelReservation/selectRate/roomFilter.ts +++ b/types/components/hotelReservation/selectRate/roomFilter.ts @@ -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) => void