Merged in feat/sw-3472-booking-flow-parameterization (pull request #2811)
feat(SW-3272): Add BookingFlowConfig * Add BookingFlowConfig * Rename "provider" to BookingFlowConfig * Change bookingCode to boolean * Fix error Approved-by: Joakim Jäderberg Approved-by: Linus Flood
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
"use client"
|
||||
|
||||
import { createContext, useContext } from "react"
|
||||
|
||||
import type { BookingFlowConfig } from "./bookingFlowConfig"
|
||||
|
||||
type BookingFlowConfigContextData = {
|
||||
config: BookingFlowConfig
|
||||
}
|
||||
|
||||
const BookingFlowConfigContext = createContext<
|
||||
BookingFlowConfigContextData | undefined
|
||||
>(undefined)
|
||||
|
||||
export const useBookingFlowConfig = (): BookingFlowConfigContextData => {
|
||||
const context = useContext(BookingFlowConfigContext)
|
||||
|
||||
if (!context) {
|
||||
throw new Error(
|
||||
"useBookingFlowConfig must be used within a BookingFlowConfigContextProvider. Did you forget to use BookingFlowConfig in the consuming app?"
|
||||
)
|
||||
}
|
||||
|
||||
return context
|
||||
}
|
||||
|
||||
export function BookingFlowConfigContextProvider({
|
||||
children,
|
||||
config,
|
||||
}: {
|
||||
children: React.ReactNode
|
||||
config: BookingFlowConfig
|
||||
}) {
|
||||
return (
|
||||
<BookingFlowConfigContext.Provider value={{ config }}>
|
||||
{children}
|
||||
</BookingFlowConfigContext.Provider>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user