Merged in feat/SW-3526-show-sas-eb-points-rate-in- (pull request #2933)
feat(SW-3526): Show EB points rate and label in booking flow * feat(SW-3526): Show EB points rate and label in booking flow * feat(SW-3526) Optimized points currency code * feat(SW-3526) Removed extra multiplication for token expiry after rebase * feat(SW-3526): Updated to exhaustive check and thow if type error Approved-by: Anton Gunnarsson
This commit is contained in:
@@ -2,8 +2,9 @@
|
||||
|
||||
import { createContext, useContext } from "react"
|
||||
|
||||
import { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
|
||||
|
||||
import type { BookingFlowConfig } from "./bookingFlowConfig"
|
||||
import type { BookingFlowVariant } from "./bookingFlowVariants"
|
||||
|
||||
type BookingFlowConfigContextData = BookingFlowConfig
|
||||
|
||||
@@ -11,18 +12,6 @@ const BookingFlowConfigContext = createContext<
|
||||
BookingFlowConfigContextData | undefined
|
||||
>(undefined)
|
||||
|
||||
export const useIsPartner = (variant: BookingFlowVariant) => {
|
||||
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.variant === variant
|
||||
}
|
||||
|
||||
export const useBookingFlowConfig = (): BookingFlowConfigContextData => {
|
||||
const context = useContext(BookingFlowConfigContext)
|
||||
|
||||
@@ -35,6 +24,19 @@ export const useBookingFlowConfig = (): BookingFlowConfigContextData => {
|
||||
return context
|
||||
}
|
||||
|
||||
export const useGetPointsCurrency = () => {
|
||||
const config = useBookingFlowConfig()
|
||||
|
||||
switch (config.variant) {
|
||||
case "scandic":
|
||||
return CurrencyEnum.POINTS
|
||||
case "partner-sas":
|
||||
return CurrencyEnum.EUROBONUS
|
||||
default:
|
||||
throw new Error(`Unknown variant: ${config.variant}`)
|
||||
}
|
||||
}
|
||||
|
||||
export function BookingFlowConfigContextProvider({
|
||||
children,
|
||||
config,
|
||||
|
||||
Reference in New Issue
Block a user