From 7be6c5dfb50d60a0779c4ceec107c2c5a90700e6 Mon Sep 17 00:00:00 2001 From: Simon Emanuelsson Date: Thu, 12 Jun 2025 15:00:53 +0200 Subject: [PATCH] feat: remove bookingCode from searchParams for hotels without availability --- .../HotelReservation/HotelCard/index.tsx | 49 +++++++++++++++---- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/apps/scandic-web/components/HotelReservation/HotelCard/index.tsx b/apps/scandic-web/components/HotelReservation/HotelCard/index.tsx index 324d9efe5..756c9dc4a 100644 --- a/apps/scandic-web/components/HotelReservation/HotelCard/index.tsx +++ b/apps/scandic-web/components/HotelReservation/HotelCard/index.tsx @@ -1,8 +1,12 @@ "use client" import { cx } from "class-variance-authority" -import { useParams } from "next/dist/client/components/navigation" -import { useRouter, useSearchParams } from "next/navigation" +import { + type ReadonlyURLSearchParams, + useParams, + useRouter, + useSearchParams, +} from "next/navigation" import { memo } from "react" import { useIntl } from "react-intl" @@ -180,8 +184,11 @@ function HotelCard({ /> {!availability.productType ? ( @@ -268,19 +275,41 @@ function HotelCard({ } interface PricesWrapperProps { - href: string - isClickable?: boolean children: React.ReactNode + isClickable?: boolean + hotelId: string + pathname: string + removeBookingCodeFromSearchParams: boolean + searchParams: ReadonlyURLSearchParams } -function PricesWrapper({ href, isClickable, children }: PricesWrapperProps) { +function PricesWrapper({ + children, + hotelId, + isClickable, + pathname, + removeBookingCodeFromSearchParams, + searchParams, +}: PricesWrapperProps) { const content =
{children}
- return isClickable ? ( - + if (!isClickable) { + return content + } + + const params = new URLSearchParams(searchParams) + params.delete("city") + params.set("hotel", hotelId) + + if (removeBookingCodeFromSearchParams) { + params.delete("bookingCode") + } + + const href = `${pathname}?${params.toString()}` + + return ( + {content} - ) : ( - content ) }