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" "use client"
import { cx } from "class-variance-authority" import { cx } from "class-variance-authority"
import { useParams } from "next/dist/client/components/navigation" import {
import { useRouter, useSearchParams } from "next/navigation" type ReadonlyURLSearchParams,
useParams,
useRouter,
useSearchParams,
} from "next/navigation"
import { memo } from "react" import { memo } from "react"
import { useIntl } from "react-intl" import { useIntl } from "react-intl"
@@ -180,8 +184,11 @@ function HotelCard({
/> />
</div> </div>
<PricesWrapper <PricesWrapper
href={`${selectRate(lang)}?hotel=${hotel.operaId}`} pathname={selectRate(lang)}
isClickable={availability.productType && !isDisabled} isClickable={availability.productType && !isDisabled}
hotelId={hotel.operaId}
removeBookingCodeFromSearchParams={!!(bookingCode && fullPrice)}
searchParams={searchParams}
> >
{!availability.productType ? ( {!availability.productType ? (
<NoPriceAvailableCard /> <NoPriceAvailableCard />
@@ -268,19 +275,41 @@ function HotelCard({
} }
interface PricesWrapperProps { interface PricesWrapperProps {
href: string
isClickable?: boolean
children: React.ReactNode 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> const content = <div className={styles.prices}>{children}</div>
return isClickable ? ( if (!isClickable) {
<Link href={href} color="none" className={styles.link} keepSearchParams> 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} {content}
</Link> </Link>
) : (
content
) )
} }