feat(SW-1534): Added booking code functionality from either searchParams or pageSettings
Approved-by: Christian Andolf
This commit is contained in:
@@ -33,8 +33,9 @@ export default async function BookingWidgetPage({
|
||||
}
|
||||
|
||||
const hotelPageParams = {
|
||||
hotel: hotelData?.hotel.id || "",
|
||||
city: hotelData?.hotel.cityName || "",
|
||||
bookingCode: searchParams.bookingCode ?? "",
|
||||
hotel: hotelData?.hotel.id ?? "",
|
||||
city: hotelData?.hotel.cityName ?? "",
|
||||
}
|
||||
|
||||
return <BookingWidget bookingWidgetSearchParams={hotelPageParams} />
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { useEffect, useRef, useState } from "react"
|
||||
import { use, useEffect, useRef, useState } from "react"
|
||||
import { FormProvider, useForm } from "react-hook-form"
|
||||
|
||||
import { REDEMPTION } from "@/constants/booking"
|
||||
@@ -37,6 +37,7 @@ import type { Location } from "@/types/trpc/routers/hotel/locations"
|
||||
export default function BookingWidgetClient({
|
||||
type,
|
||||
bookingWidgetSearchParams,
|
||||
pageSettingsBookingCodePromise,
|
||||
}: BookingWidgetClientProps) {
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
const bookingWidgetRef = useRef(null)
|
||||
@@ -83,7 +84,13 @@ export default function BookingWidgetClient({
|
||||
selectedLocation = getLocationObj(locations ?? [], params.city)
|
||||
}
|
||||
|
||||
const selectedBookingCode = params.bookingCode ?? ""
|
||||
// if bookingCode is not provided in the search params,
|
||||
// we will fetch it from the page settings stored in Contentstack.
|
||||
const selectedBookingCode =
|
||||
params.bookingCode ||
|
||||
(pageSettingsBookingCodePromise !== null
|
||||
? use(pageSettingsBookingCodePromise)
|
||||
: "")
|
||||
|
||||
const defaultRoomsData: BookingWidgetSchema["rooms"] = params.rooms?.map(
|
||||
(room) => ({
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { isBookingWidgetHidden } from "@/lib/trpc/memoizedRequests"
|
||||
import {
|
||||
getPageSettingsBookingCode,
|
||||
isBookingWidgetHidden,
|
||||
} from "@/lib/trpc/memoizedRequests"
|
||||
|
||||
import BookingWidgetClient from "./Client"
|
||||
|
||||
@@ -14,10 +17,16 @@ export default async function BookingWidget({
|
||||
return null
|
||||
}
|
||||
|
||||
let pageSettingsBookingCodePromise: Promise<string> | null = null
|
||||
if (!bookingWidgetSearchParams.bookingCode) {
|
||||
pageSettingsBookingCodePromise = getPageSettingsBookingCode()
|
||||
}
|
||||
|
||||
return (
|
||||
<BookingWidgetClient
|
||||
type={type}
|
||||
bookingWidgetSearchParams={bookingWidgetSearchParams}
|
||||
pageSettingsBookingCodePromise={pageSettingsBookingCodePromise}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
fragment PageSettings on PageSettings {
|
||||
hide_booking_widget
|
||||
booking_code
|
||||
}
|
||||
|
||||
@@ -258,6 +258,14 @@ export const isBookingWidgetHidden = cache(
|
||||
}
|
||||
)
|
||||
|
||||
export const getPageSettingsBookingCode = cache(
|
||||
async function getMemoizedPageSettingsBookingCode() {
|
||||
const lang = getLang()
|
||||
const pageSettings = await getPageSettings(lang)
|
||||
return pageSettings?.page.settings.booking_code ?? ""
|
||||
}
|
||||
)
|
||||
|
||||
export const getJobylonFeed = cache(async function getMemoizedJobylonFeed() {
|
||||
return serverClient().partner.jobylon.feed.get()
|
||||
})
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { nullableStringValidator } from "@/utils/zod/stringValidator"
|
||||
|
||||
export const pageSettingsSchema = z.object({
|
||||
hide_booking_widget: z.boolean(),
|
||||
booking_code: nullableStringValidator,
|
||||
})
|
||||
|
||||
export type PageSettingsSchema = z.output<typeof pageSettingsSchema>
|
||||
|
||||
@@ -34,6 +34,7 @@ export interface BookingWidgetProps {
|
||||
export interface BookingWidgetClientProps {
|
||||
type?: BookingWidgetType
|
||||
bookingWidgetSearchParams: SearchParams<BookingWidgetSearchData>["searchParams"]
|
||||
pageSettingsBookingCodePromise: Promise<string> | null
|
||||
}
|
||||
|
||||
export interface BookingWidgetToggleButtonProps {
|
||||
|
||||
Reference in New Issue
Block a user