diff --git a/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/index.tsx b/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/index.tsx index 1c14d77ad..b9fb1bce5 100644 --- a/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/index.tsx +++ b/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/index.tsx @@ -1,5 +1,6 @@ "use client" +import { useSearchParams } from "next/navigation" import { useIntl } from "react-intl" import { trpc } from "@/lib/trpc/client" @@ -7,6 +8,7 @@ import { trpc } from "@/lib/trpc/client" import Alert from "@/components/TempDesignSystem/Alert" import useLang from "@/hooks/useLang" import RatesProvider from "@/providers/RatesProvider" +import { convertSearchParamsToObj, searchParamsToRecord } from "@/utils/url" import RateSummary from "./RateSummary" import Rooms from "./Rooms" @@ -15,16 +17,21 @@ import { RoomsContainerSkeleton } from "./RoomsContainerSkeleton" import styles from "./index.module.css" import type { RoomsContainerProps } from "@/types/components/hotelReservation/selectRate/roomsContainer" +import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate" import { AlertTypeEnum } from "@/types/enums/alert" export function RoomsContainer({ - booking, hotelType, roomCategories, vat, }: RoomsContainerProps) { const lang = useLang() const intl = useIntl() + const searchParams = useSearchParams() + + const booking = convertSearchParamsToObj( + searchParamsToRecord(searchParams) + ) const { data, isFetching, isError, error } = trpc.hotel.availability.selectRate.rooms.useQuery( diff --git a/apps/scandic-web/components/HotelReservation/SelectRate/index.tsx b/apps/scandic-web/components/HotelReservation/SelectRate/index.tsx index 7a4bc4920..e033aafed 100644 --- a/apps/scandic-web/components/HotelReservation/SelectRate/index.tsx +++ b/apps/scandic-web/components/HotelReservation/SelectRate/index.tsx @@ -8,7 +8,6 @@ import HotelInfoCard from "@/components/HotelReservation/SelectRate/HotelInfoCar import { RoomsContainer } from "@/components/HotelReservation/SelectRate/RoomsContainer" import { setLang } from "@/i18n/serverContext" import { getHotelSearchDetails } from "@/utils/hotelSearchDetails" -import { convertSearchParamsToObj } from "@/utils/url" import FnFNotAllowedAlert from "../FnFNotAllowedAlert/FnFNotAllowedAlert" import AvailabilityError from "./AvailabilityError" @@ -39,8 +38,6 @@ export default async function SelectRatePage({ return notFound() } - const booking = convertSearchParamsToObj(searchParams) - let isInValidFNF = false if (bookingCode && FamilyAndFriendsCodes.includes(bookingCode)) { const cookieStore = cookies() @@ -54,7 +51,6 @@ export default async function SelectRatePage({ ) : ( () const pathname = usePathname() const searchParams = useSearchParams() const intl = useIntl() - if (!storeRef.current) { - storeRef.current = createRatesStore({ + const store = useMemo( + () => + createRatesStore({ + booking, + hotelType, + labels: { + accessibilityRoom: intl.formatMessage({ + defaultMessage: "Accessible room", + }), + allergyRoom: intl.formatMessage({ + defaultMessage: "Allergy-friendly room", + }), + petRoom: intl.formatMessage({ + defaultMessage: "Pet-friendly room", + }), + }, + pathname, + roomCategories, + roomsAvailability, + searchParams: new URLSearchParams(searchParams), + vat, + }), + [ booking, hotelType, - labels: { - accessibilityRoom: intl.formatMessage({ - defaultMessage: "Accessible room", - }), - allergyRoom: intl.formatMessage({ - defaultMessage: "Allergy-friendly room", - }), - petRoom: intl.formatMessage({ - defaultMessage: "Pet-friendly room", - }), - }, + intl, pathname, roomCategories, roomsAvailability, - searchParams: new URLSearchParams(searchParams), + searchParams, vat, - }) - } - - return ( - - {children} - + ] ) + + return {children} } diff --git a/apps/scandic-web/types/components/hotelReservation/selectRate/roomsContainer.ts b/apps/scandic-web/types/components/hotelReservation/selectRate/roomsContainer.ts index b0907141b..5908f25a8 100644 --- a/apps/scandic-web/types/components/hotelReservation/selectRate/roomsContainer.ts +++ b/apps/scandic-web/types/components/hotelReservation/selectRate/roomsContainer.ts @@ -1,8 +1,5 @@ import type { HotelData } from "@/types/hotel" -import type { SelectRateSearchParams } from "./selectRate" export interface RoomsContainerProps extends Pick, - Pick { - booking: SelectRateSearchParams -} + Pick {}