Files
web/packages/booking-flow/lib/bookingFlowConfig/bookingFlowConfig.tsx
Anton Gunnarsson 1eb70766b4 Merged in feat/sw-3580-redemption-feature-flag (pull request #3045)
feat(SW-3580): Add feature toggle enableRedemption to BookingFlowConfig

* Add feature toggle enableRedemption to BookingFlowConfig

* Update error message


Approved-by: Joakim Jäderberg
2025-11-03 07:57:39 +00:00

62 lines
1.4 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 { BookingFlowVariant } from "./bookingFlowVariants"
export type BookingFlowConfig = {
bookingCodeEnabled: boolean
redemptionEnabled: boolean
enterDetailsMembershipIdInputLocation: "form" | "join-card"
variant: BookingFlowVariant
routes: {
myStay: LangRoute
bookingTermsAndConditions: LangRoute
membershipTermsAndConditions: 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>
)
}