feat: remove bookingCode from searchParams for hotels without availability

This commit is contained in:
Simon Emanuelsson
2025-06-12 15:00:53 +02:00
committed by Simon.Emanuelsson
parent 180a100140
commit 7be6c5dfb5

View File

@@ -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({
/>
</div>
<PricesWrapper
href={`${selectRate(lang)}?hotel=${hotel.operaId}`}
pathname={selectRate(lang)}
isClickable={availability.productType && !isDisabled}
hotelId={hotel.operaId}
removeBookingCodeFromSearchParams={!!(bookingCode && fullPrice)}
searchParams={searchParams}
>
{!availability.productType ? (
<NoPriceAvailableCard />
@@ -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 = <div className={styles.prices}>{children}</div>
return isClickable ? (
<Link href={href} color="none" className={styles.link} keepSearchParams>
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 (
<Link href={href} color="none" className={styles.link}>
{content}
</Link>
) : (
content
)
}