Files
web/packages/booking-flow/lib/bookingFlowConfig/bookingFlowConfig.tsx
Hrishikesh Vaipurkar 16e6c1596c Merged in feat/SW-3477-hide-voucher-booking-code-sas- (pull request #2836)
feat(SW-3477) Updated booking widget for SAS white label

Approved-by: Anton Gunnarsson
2025-09-23 08:44:55 +00:00

58 lines
1.3 KiB
TypeScript

import "server-only"
import { cache } from "react"
import { BookingFlowConfigContextProvider } from "./bookingFlowConfigContext"
import type { LangRoute } from "@scandic-hotels/common/constants/routes/langRoute"
import type { ScandicPartnersEnum } from "@scandic-hotels/common/constants/scandicPartners"
export type BookingFlowConfig = {
bookingCodeEnabled: boolean
partner?: ScandicPartnersEnum
routes: {
myStay: LangRoute
bookingTermsAndConditions: LangRoute
customerService: LangRoute
privacyPolicy: LangRoute
}
}
const getRef = cache(() => ({
current: undefined as BookingFlowConfig | undefined,
}))
function setBookingFlowConfig(newConfig: BookingFlowConfig) {
getRef().current = newConfig
}
export function getBookingFlowConfig(): BookingFlowConfig {
const contextConfig = getRef().current
if (!contextConfig) {
throw new Error("BookingFlowConfig not set")
}
return contextConfig
}
/*
* Sets up both a server side context and a client side context
* for the booking flow config.
*/
export async function BookingFlowConfig({
children,
config,
}: {
children: React.ReactNode
config: BookingFlowConfig
}) {
setBookingFlowConfig(config)
return (
<BookingFlowConfigContextProvider config={config}>
{children}
</BookingFlowConfigContextProvider>
)
}