diff --git a/components/HotelReservation/SelectRate/RoomList/RoomCard/RoomCardSkeleton.module.css b/components/HotelReservation/SelectHotel/RoomCardSkeleton/RoomCardSkeleton.module.css similarity index 100% rename from components/HotelReservation/SelectRate/RoomList/RoomCard/RoomCardSkeleton.module.css rename to components/HotelReservation/SelectHotel/RoomCardSkeleton/RoomCardSkeleton.module.css diff --git a/components/HotelReservation/SelectRate/RoomList/RoomCard/RoomCardSkeleton.tsx b/components/HotelReservation/SelectHotel/RoomCardSkeleton/RoomCardSkeleton.tsx similarity index 100% rename from components/HotelReservation/SelectRate/RoomList/RoomCard/RoomCardSkeleton.tsx rename to components/HotelReservation/SelectHotel/RoomCardSkeleton/RoomCardSkeleton.tsx diff --git a/components/HotelReservation/SelectHotel/SelectHotelMap/SelectHotelMapContainerSkeleton.tsx b/components/HotelReservation/SelectHotel/SelectHotelMap/SelectHotelMapContainerSkeleton.tsx index 4f0217c14..22665bf24 100644 --- a/components/HotelReservation/SelectHotel/SelectHotelMap/SelectHotelMapContainerSkeleton.tsx +++ b/components/HotelReservation/SelectHotel/SelectHotelMap/SelectHotelMapContainerSkeleton.tsx @@ -1,6 +1,6 @@ import SkeletonShimmer from "@/components/SkeletonShimmer" -import { RoomCardSkeleton } from "../../SelectRate/RoomList/RoomCard/RoomCardSkeleton" +import { RoomCardSkeleton } from "../RoomCardSkeleton/RoomCardSkeleton" import styles from "./SelectHotelMapContainerSkeleton.module.css" diff --git a/components/HotelReservation/SelectHotel/SelectHotelMap/SelectHotelMapContent/index.tsx b/components/HotelReservation/SelectHotel/SelectHotelMap/SelectHotelMapContent/index.tsx index 97a3d5319..c864d629f 100644 --- a/components/HotelReservation/SelectHotel/SelectHotelMap/SelectHotelMapContent/index.tsx +++ b/components/HotelReservation/SelectHotel/SelectHotelMap/SelectHotelMapContent/index.tsx @@ -8,7 +8,7 @@ import { selectHotel } from "@/constants/routes/hotelReservation" import { useHotelFilterStore } from "@/stores/hotel-filters" import { useHotelsMapStore } from "@/stores/hotels-map" -import { RoomCardSkeleton } from "@/components/HotelReservation/SelectRate/RoomList/RoomCard/RoomCardSkeleton" +import { RoomCardSkeleton } from "@/components/HotelReservation/SelectHotel/RoomCardSkeleton/RoomCardSkeleton" import { CloseIcon, CloseLargeIcon } from "@/components/Icons" import InteractiveMap from "@/components/Maps/InteractiveMap" import { BackToTopButton } from "@/components/TempDesignSystem/BackToTopButton" diff --git a/components/HotelReservation/SelectRate/RateSummary/index.tsx b/components/HotelReservation/SelectRate/RateSummary/index.tsx index 42c2fd05b..902f82b19 100644 --- a/components/HotelReservation/SelectRate/RateSummary/index.tsx +++ b/components/HotelReservation/SelectRate/RateSummary/index.tsx @@ -2,7 +2,7 @@ import { useEffect, useState } from "react" import { useIntl } from "react-intl" import { dt } from "@/lib/dt" -import { useRateSelectionStore } from "@/stores/rate-selection" +import { useRateSelectionStore } from "@/stores/select-rate/rate-selection" import SignupPromoDesktop from "@/components/HotelReservation/SignupPromo/Desktop" import SignupPromoMobile from "@/components/HotelReservation/SignupPromo/Mobile" @@ -34,12 +34,12 @@ export default function RateSummary({ return () => clearTimeout(timer) }, []) - if (rateSummary.length === 0) return null - const selectedRateSummary = rateSummary.filter( (summary): summary is Rate => summary !== null ) + if (selectedRateSummary.length === 0) return null + const { member, public: publicRate, diff --git a/components/HotelReservation/SelectRate/RoomSelectionPanel/index.tsx b/components/HotelReservation/SelectRate/RoomSelectionPanel/index.tsx index 334321050..e6ef1dc03 100644 --- a/components/HotelReservation/SelectRate/RoomSelectionPanel/index.tsx +++ b/components/HotelReservation/SelectRate/RoomSelectionPanel/index.tsx @@ -1,6 +1,10 @@ -import RoomFilter from "../RoomFilter" -import RoomList from "../RoomList" +import { useSearchParams } from "next/navigation" +import { useMemo } from "react" +import RoomTypeFilter from "../RoomTypeFilter" +import RoomTypeList from "../RoomTypeList" + +import type { FilterValues } from "@/types/components/hotelReservation/selectRate/roomFilter" import type { RoomSelectionPanelProps } from "@/types/components/hotelReservation/selectRate/roomSelection" export function RoomSelectionPanel({ @@ -13,15 +17,27 @@ export function RoomSelectionPanel({ defaultPackages, roomListIndex, }: RoomSelectionPanelProps) { + const searchParams = useSearchParams() + + const initialFilterValues = useMemo(() => { + const packagesFromSearchParams = + searchParams.get(`room[${roomListIndex}].packages`)?.split(",") ?? [] + + return defaultPackages.reduce((acc, option) => { + acc[option.code] = packagesFromSearchParams.includes(option.code) + return acc + }, {}) + }, [defaultPackages, searchParams, roomListIndex]) + return ( <> - - { - const packagesFromSearchParams = - searchParams.get(`room[${roomListIndex}].packages`)?.split(",") ?? [] - - return filterOptions.reduce((acc, option) => { - acc[option.code] = packagesFromSearchParams.includes(option.code) - return acc - }, {}) - }, [filterOptions, searchParams, roomListIndex]) - useEffect(() => { onFilterRef.current = onFilter }, [onFilter]) diff --git a/components/HotelReservation/SelectRate/RoomFilter/roomFilter.module.css b/components/HotelReservation/SelectRate/RoomTypeFilter/roomFilter.module.css similarity index 100% rename from components/HotelReservation/SelectRate/RoomFilter/roomFilter.module.css rename to components/HotelReservation/SelectRate/RoomTypeFilter/roomFilter.module.css diff --git a/components/HotelReservation/SelectRate/RoomList/FlexibilityOption/PriceList/index.tsx b/components/HotelReservation/SelectRate/RoomTypeList/FlexibilityOption/PriceList/index.tsx similarity index 100% rename from components/HotelReservation/SelectRate/RoomList/FlexibilityOption/PriceList/index.tsx rename to components/HotelReservation/SelectRate/RoomTypeList/FlexibilityOption/PriceList/index.tsx diff --git a/components/HotelReservation/SelectRate/RoomList/FlexibilityOption/PriceList/priceList.module.css b/components/HotelReservation/SelectRate/RoomTypeList/FlexibilityOption/PriceList/priceList.module.css similarity index 100% rename from components/HotelReservation/SelectRate/RoomList/FlexibilityOption/PriceList/priceList.module.css rename to components/HotelReservation/SelectRate/RoomTypeList/FlexibilityOption/PriceList/priceList.module.css diff --git a/components/HotelReservation/SelectRate/RoomList/FlexibilityOption/PriceList/utils.ts b/components/HotelReservation/SelectRate/RoomTypeList/FlexibilityOption/PriceList/utils.ts similarity index 100% rename from components/HotelReservation/SelectRate/RoomList/FlexibilityOption/PriceList/utils.ts rename to components/HotelReservation/SelectRate/RoomTypeList/FlexibilityOption/PriceList/utils.ts diff --git a/components/HotelReservation/SelectRate/RoomList/FlexibilityOption/flexibilityOption.module.css b/components/HotelReservation/SelectRate/RoomTypeList/FlexibilityOption/flexibilityOption.module.css similarity index 100% rename from components/HotelReservation/SelectRate/RoomList/FlexibilityOption/flexibilityOption.module.css rename to components/HotelReservation/SelectRate/RoomTypeList/FlexibilityOption/flexibilityOption.module.css diff --git a/components/HotelReservation/SelectRate/RoomList/FlexibilityOption/index.tsx b/components/HotelReservation/SelectRate/RoomTypeList/FlexibilityOption/index.tsx similarity index 57% rename from components/HotelReservation/SelectRate/RoomList/FlexibilityOption/index.tsx rename to components/HotelReservation/SelectRate/RoomTypeList/FlexibilityOption/index.tsx index 39ef000b6..885aac959 100644 --- a/components/HotelReservation/SelectRate/RoomList/FlexibilityOption/index.tsx +++ b/components/HotelReservation/SelectRate/RoomTypeList/FlexibilityOption/index.tsx @@ -1,11 +1,7 @@ "use client" -import { useSearchParams } from "next/navigation" -import { useEffect, useRef } from "react" import { useIntl } from "react-intl" -import { useRateSelectionStore } from "@/stores/rate-selection" - import { CheckIcon, InfoCircleIcon } from "@/components/Icons" import Modal from "@/components/Modal" import Button from "@/components/TempDesignSystem/Button" @@ -24,60 +20,11 @@ export default function FlexibilityOption({ name, paymentTerm, priceInformation, - roomTypeCode, petRoomPackage, - roomListIndex, + isSelected, + onSelect, }: FlexibilityOptionProps) { const intl = useIntl() - const inputElementRef = useRef(null) - const { selectRate, selectedRates } = useRateSelectionStore() - - const searchParams = useSearchParams() - - // When entering the page with a room and rate selection already in the URL we - // want to preselect the selection. This happens e.g. when you do a selection, - // go to the enter details page and then want to change the room. - useEffect(() => { - const ratecodeSearchParam = searchParams.get( - `room[${roomListIndex}].ratecode` - ) - const roomtypeSearchParam = searchParams.get( - `room[${roomListIndex}].roomtype` - ) - - // If this is not the room and rate we want to preselect, abort - if ( - !product || - ratecodeSearchParam !== product.productType.public.rateCode || - roomtypeSearchParam !== roomTypeCode - ) { - return - } - - // Check if there's already a selection for this room index - const existingSelection = selectedRates[roomListIndex] - if (existingSelection) return - - selectRate(roomListIndex, { - publicRateCode: product.productType.public.rateCode, - roomTypeCode: roomTypeCode, - name: name, - paymentTerm: paymentTerm, - }) - - if (inputElementRef.current) { - inputElementRef.current.checked = true - } - }, [ - searchParams, - roomListIndex, - product, - roomTypeCode, - name, - paymentTerm, - selectedRates, - selectRate, - ]) if (!product) { return ( @@ -100,31 +47,14 @@ export default function FlexibilityOption({ const { public: publicPrice, member: memberPrice } = product.productType - const onClick: React.MouseEventHandler = (e) => { - if ( - selectedRates[roomListIndex]?.publicRateCode === publicPrice.rateCode && - selectedRates[roomListIndex]?.roomTypeCode === roomTypeCode - ) { - if (e.currentTarget?.checked) e.currentTarget.checked = false - selectRate(roomListIndex, undefined) - } else { - selectRate(roomListIndex, { - publicRateCode: publicPrice.rateCode, - roomTypeCode: roomTypeCode, - name: name, - paymentTerm: paymentTerm, - }) - } - } - return (