From 68d7e869db4057f27d4e798c4a2c295f14cc32d2 Mon Sep 17 00:00:00 2001 From: Pontus Dreij Date: Mon, 27 Jan 2025 17:08:57 +0100 Subject: [PATCH] feat(SW-718) updates after PR comments --- .../RoomCardSkeleton.module.css | 0 .../RoomCardSkeleton}/RoomCardSkeleton.tsx | 0 .../SelectHotelMapContainerSkeleton.tsx | 2 +- .../SelectHotelMapContent/index.tsx | 2 +- .../SelectRate/RateSummary/index.tsx | 6 +- .../SelectRate/RoomSelectionPanel/index.tsx | 26 +++- .../{RoomFilter => RoomTypeFilter}/index.tsx | 15 +- .../roomFilter.module.css | 0 .../FlexibilityOption/PriceList/index.tsx | 0 .../PriceList/priceList.module.css | 0 .../FlexibilityOption/PriceList/utils.ts | 0 .../flexibilityOption.module.css | 0 .../FlexibilityOption/index.tsx | 80 +--------- .../RoomCard/cardVariants.ts | 0 .../RoomCard/index.tsx | 109 +++++++++++-- .../RoomCard/roomCard.module.css | 0 .../{RoomList => RoomTypeList}/index.tsx | 6 +- .../roomSelection.module.css | 0 .../Rooms/RoomsContainerSkeleton.tsx | 2 +- .../SelectRate/Rooms/index.tsx | 144 +++++++++--------- .../SelectRate/Rooms/rooms.module.css | 34 ++--- .../SelectRate/Rooms/variants.ts | 21 +++ .../SelectRate/SelectedRoomPanel/index.tsx | 3 +- stores/rate-selection.ts | 110 ------------- stores/select-rate/helper.ts | 58 +++++++ stores/select-rate/rate-selection.ts | 67 ++++++++ .../selectRate/flexibilityOption.ts | 3 +- .../hotelReservation/selectRate/roomFilter.ts | 2 +- .../selectRate/roomSelection.ts | 2 +- 29 files changed, 371 insertions(+), 321 deletions(-) rename components/HotelReservation/{SelectRate/RoomList/RoomCard => SelectHotel/RoomCardSkeleton}/RoomCardSkeleton.module.css (100%) rename components/HotelReservation/{SelectRate/RoomList/RoomCard => SelectHotel/RoomCardSkeleton}/RoomCardSkeleton.tsx (100%) rename components/HotelReservation/SelectRate/{RoomFilter => RoomTypeFilter}/index.tsx (91%) rename components/HotelReservation/SelectRate/{RoomFilter => RoomTypeFilter}/roomFilter.module.css (100%) rename components/HotelReservation/SelectRate/{RoomList => RoomTypeList}/FlexibilityOption/PriceList/index.tsx (100%) rename components/HotelReservation/SelectRate/{RoomList => RoomTypeList}/FlexibilityOption/PriceList/priceList.module.css (100%) rename components/HotelReservation/SelectRate/{RoomList => RoomTypeList}/FlexibilityOption/PriceList/utils.ts (100%) rename components/HotelReservation/SelectRate/{RoomList => RoomTypeList}/FlexibilityOption/flexibilityOption.module.css (100%) rename components/HotelReservation/SelectRate/{RoomList => RoomTypeList}/FlexibilityOption/index.tsx (57%) rename components/HotelReservation/SelectRate/{RoomList => RoomTypeList}/RoomCard/cardVariants.ts (100%) rename components/HotelReservation/SelectRate/{RoomList => RoomTypeList}/RoomCard/index.tsx (72%) rename components/HotelReservation/SelectRate/{RoomList => RoomTypeList}/RoomCard/roomCard.module.css (100%) rename components/HotelReservation/SelectRate/{RoomList => RoomTypeList}/index.tsx (84%) rename components/HotelReservation/SelectRate/{RoomList => RoomTypeList}/roomSelection.module.css (100%) create mode 100644 components/HotelReservation/SelectRate/Rooms/variants.ts delete mode 100644 stores/rate-selection.ts create mode 100644 stores/select-rate/helper.ts create mode 100644 stores/select-rate/rate-selection.ts 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 (