Files
web/packages/booking-flow/lib/bookingFlowConfig/bookingFlowConfig.tsx
Anton Gunnarsson c21d0dbc74 Merged in fix/sw-3495-booking-flow-links-to-web (pull request #2837)
fix: (SW-3495): Update booking-flow links in partner-sas

* Update links to scandic web in booking-flow

* Fix routeToScandicWeb util function


Approved-by: Hrishikesh Vaipurkar
2025-09-22 13:30:38 +00:00

56 lines
1.2 KiB
TypeScript

import "server-only"
import { cache } from "react"
import { BookingFlowConfigContextProvider } from "./bookingFlowConfigContext"
import type { LangRoute } from "@scandic-hotels/common/constants/routes/langRoute"
export type BookingFlowConfig = {
bookingCodeEnabled: boolean
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>
)
}