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:
Hrishikesh Vaipurkar
2025-10-15 06:54:44 +00:00
parent 73af1eed9b
commit 78ede453a2
27 changed files with 281 additions and 176 deletions

View File

@@ -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,

View File

@@ -12,6 +12,7 @@ import { useScrollToTop } from "@scandic-hotels/common/hooks/useScrollToTop"
import { BackToTopButton } from "@scandic-hotels/design-system/BackToTopButton"
import { HotelCard } from "@scandic-hotels/design-system/HotelCard"
import { useGetPointsCurrency } from "../../bookingFlowConfig/bookingFlowConfigContext"
import { useIsLoggedIn } from "../../hooks/useIsLoggedIn"
import useLang from "../../hooks/useLang"
import { mapApiImagesToGalleryImages } from "../../misc/imageGallery"
@@ -57,6 +58,7 @@ export default function HotelCardListing({
const { activeHotel, activate, disengage, engage } = useHotelsMapStore()
const { showBackToTop, scrollToTop } = useScrollToTop({ threshold: 490 })
const activeCardRef = useRef<HTMLDivElement | null>(null)
const pointsCurrency = useGetPointsCurrency()
const sortBy = searchParams.get("sort") ?? DEFAULT_SORT
@@ -159,6 +161,7 @@ export default function HotelCardListing({
tripAdvisor: hotel.hotel.ratings?.tripAdvisor.rating,
},
}}
pointsCurrency={pointsCurrency}
lang={lang}
fullPrice={!hotel.availability.bookingCode}
prices={

View File

@@ -16,6 +16,7 @@ import { OldDSButton as Button } from "@scandic-hotels/design-system/OldDSButton
import Subtitle from "@scandic-hotels/design-system/Subtitle"
import { Typography } from "@scandic-hotels/design-system/Typography"
import { useGetPointsCurrency } from "../../bookingFlowConfig/bookingFlowConfigContext"
import { useIsLoggedIn } from "../../hooks/useIsLoggedIn"
import useLang from "../../hooks/useLang"
@@ -34,6 +35,7 @@ export default function ListingHotelCardDialog({
}: ListingHotelCardProps) {
const intl = useIntl()
const lang = useLang()
const pointsCurrency = useGetPointsCurrency()
const [imageError, setImageError] = useState(false)
@@ -153,7 +155,10 @@ export default function ListingHotelCardDialog({
</Subtitle>
)}
{redemptionPrice && (
<HotelPointsRow pointsPerStay={redemptionPrice} />
<HotelPointsRow
pointsPerStay={redemptionPrice}
pointsCurrency={pointsCurrency}
/>
)}
{chequePrice && (
<Subtitle type="two">

View File

@@ -1,14 +1,16 @@
"use client"
import { useIntl } from "react-intl"
import { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
import { formatPrice } from "@scandic-hotels/common/utils/numberFormatting"
import { useGetPointsCurrency } from "../../../../../bookingFlowConfig/bookingFlowConfigContext"
import BoldRow from "../Bold"
import RegularRow from "../Regular"
import BedTypeRow from "./BedType"
import PackagesRow from "./Packages"
import type { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
import type { SharedPriceRowProps } from "./price"
export interface RedemptionPriceType {
@@ -34,6 +36,7 @@ export default function RedemptionPrice({
price,
}: RedemptionPriceProps) {
const intl = useIntl()
const pointsCurrency = useGetPointsCurrency()
if (!price) {
return null
@@ -50,7 +53,7 @@ export default function RedemptionPrice({
: null
const additionalCurrency = price.currency ?? currency
let averagePricePerNight = `${price.pointsPerNight} ${CurrencyEnum.POINTS}`
let averagePricePerNight = `${price.pointsPerNight} ${pointsCurrency}`
if (averageAdditionalPricePerNight) {
averagePricePerNight = `${averagePricePerNight} + ${averageAdditionalPricePerNight} ${additionalCurrency}`
}
@@ -62,7 +65,7 @@ export default function RedemptionPrice({
value={formatPrice(
intl,
price.pointsPerStay,
CurrencyEnum.POINTS,
pointsCurrency,
additionalPricePerStay,
additionalCurrency
)}

View File

@@ -19,6 +19,7 @@ import { InteractiveMap } from "@scandic-hotels/design-system/Map/InteractiveMap
import { Typography } from "@scandic-hotels/design-system/Typography"
import { trackEvent } from "@scandic-hotels/tracking/base"
import { useGetPointsCurrency } from "../../../../bookingFlowConfig/bookingFlowConfigContext"
import { useIsLoggedIn } from "../../../../hooks/useIsLoggedIn"
import useLang from "../../../../hooks/useLang"
import { mapApiImagesToGalleryImages } from "../../../../misc/imageGallery"
@@ -76,6 +77,7 @@ export function SelectHotelMapContent({
const activeFilters = useHotelFilterStore((state) => state.activeFilters)
const setResultCount = useHotelFilterStore((state) => state.setResultCount)
const pointsCurrency = useGetPointsCurrency()
const hotelMapStore = useHotelsMapStore()
@@ -254,6 +256,7 @@ export function SelectHotelMapContent({
)}
</div>
<InteractiveMap
pointsCurrency={pointsCurrency}
closeButton={closeButton}
coordinates={coordinates}
hotelPins={filteredHotelPins.map((pin) => {

View File

@@ -3,6 +3,7 @@ import { useIntl } from "react-intl"
import PointsRateCard from "@scandic-hotels/design-system/PointsRateCard"
import { useGetPointsCurrency } from "../../../../../../../bookingFlowConfig/bookingFlowConfigContext"
import { useSelectRateContext } from "../../../../../../../contexts/SelectRate/SelectRateContext"
import { BookingCodeFilterEnum } from "../../../../../../../stores/bookingCode-filter"
import { sumPackages } from "../../../../../../../utils/SelectRate"
@@ -33,6 +34,7 @@ export default function Redemptions({
actions: { selectRate },
selectedRates,
} = useSelectRateContext()
const pointsCurrency = useGetPointsCurrency()
// TODO: Replace with context value when we have support for dropdown "Show all rates"
const selectedFilter = BookingCodeFilterEnum.All as BookingCodeFilterEnum
@@ -86,7 +88,7 @@ export default function Redemptions({
price: additionalPrice.toString(),
}
: undefined,
currency: "PTS",
currency: pointsCurrency ?? "PTS",
isDisabled: !r.redemption.hasEnoughPoints,
points: r.redemption.localPrice.pointsPerStay.toString(),
rateCode: r.redemption.rateCode,

View File

@@ -6,6 +6,7 @@ import { createContext, useEffect, useRef, useState } from "react"
import { dt } from "@scandic-hotels/common/dt"
import { LoadingSpinner } from "@scandic-hotels/design-system/LoadingSpinner"
import { useGetPointsCurrency } from "../../bookingFlowConfig/bookingFlowConfigContext"
import { getMultiroomDetailsSchema } from "../../components/EnterDetails/Details/Multiroom/schema"
import { guestDetailsSchema } from "../../components/EnterDetails/Details/RoomOne/schema"
import {
@@ -60,6 +61,7 @@ export default function EnterDetailsProvider({
// rendering the form until that has been done.
const [hasInitializedStore, setHasInitializedStore] = useState(false)
const storeRef = useRef<EnterDetailsStore>(undefined)
const pointsCurrency = useGetPointsCurrency()
if (!storeRef.current) {
const initialData: InitialState = {
booking,
@@ -99,7 +101,8 @@ export default function EnterDetailsProvider({
searchParamsStr,
user,
breakfastPackages,
lang
lang,
pointsCurrency
)
}

View File

@@ -18,6 +18,7 @@ import { RoomPackageCodeEnum } from "@scandic-hotels/trpc/enums/roomFilter"
import { AvailabilityEnum } from "@scandic-hotels/trpc/enums/selectHotel"
import { selectRateRoomsAvailabilityInputSchema } from "@scandic-hotels/trpc/routers/hotels/availability/selectRate/rooms/schema"
import { useGetPointsCurrency } from "../../../bookingFlowConfig/bookingFlowConfigContext"
import { useIsLoggedIn } from "../../../hooks/useIsLoggedIn"
import useLang from "../../../hooks/useLang"
import { BookingCodeFilterEnum } from "../../../stores/bookingCode-filter"
@@ -68,6 +69,7 @@ export function SelectRateProvider({
const updateBooking = useUpdateBooking()
const isUserLoggedIn = useIsLoggedIn()
const intl = useIntl()
const pointsCurrency = useGetPointsCurrency()
const [activeRoomIndex, setInternalActiveRoomIndex] = useQueryState<number>(
"activeRoomIndex",
@@ -233,6 +235,7 @@ export function SelectRateProvider({
roomConfiguration: roomAvailability[ix]?.[0],
})),
isMember: isUserLoggedIn,
pointsCurrency,
})
const getPriceForRoom = useCallback(
@@ -253,9 +256,10 @@ export function SelectRateProvider({
],
isMember: isUserLoggedIn && roomIndex === 0,
addAdditionalCost: false,
pointsCurrency,
})
},
[selectedRates, roomAvailability, isUserLoggedIn]
[selectedRates, roomAvailability, isUserLoggedIn, pointsCurrency]
)
const setActiveRoomIndex = useCallback(

View File

@@ -17,10 +17,12 @@ export function getTotalPrice({
selectedRates,
isMember,
addAdditionalCost = true,
pointsCurrency,
}: {
selectedRates: Array<SelectedRate | null>
isMember: boolean
addAdditionalCost?: boolean
pointsCurrency?: CurrencyEnum
}): Price | null {
const mainRoom = selectedRates[0]
const mainRoomRate = mainRoom?.rate
@@ -45,7 +47,8 @@ export function getTotalPrice({
mainRoom.roomConfiguration?.selectedPackages.filter(
(pkg) => "localPrice" in pkg
) ?? null,
addAdditionalCost
addAdditionalCost,
pointsCurrency
)
}
if ("voucher" in mainRoomRate) {
@@ -156,7 +159,8 @@ function calculateTotalPrice(
function calculateRedemptionTotalPrice(
redemption: RedemptionProduct["redemption"],
packages: RoomPackage[] | null,
addAdditonalCost: boolean
addAdditonalCost: boolean,
pointsCurrency?: CurrencyEnum
) {
const pkgsSum = addAdditonalCost
? sumPackages(packages)
@@ -179,7 +183,7 @@ function calculateRedemptionTotalPrice(
local: {
additionalPrice,
additionalPriceCurrency,
currency: CurrencyEnum.POINTS,
currency: pointsCurrency ?? CurrencyEnum.POINTS,
price: redemption.localPrice.pointsPerStay,
},
}

View File

@@ -52,7 +52,11 @@ function add(...nums: (number | string | undefined)[]) {
}, 0)
}
export function getRoomPrice(roomRate: Product, isMember: boolean) {
export function getRoomPrice(
roomRate: Product,
isMember: boolean,
pointsCurrency?: CurrencyEnum
) {
if (isMember && "member" in roomRate && roomRate.member) {
let publicRate
if (
@@ -196,7 +200,7 @@ export function getRoomPrice(roomRate: Product, isMember: boolean) {
perNight: {
requested: undefined,
local: {
currency: CurrencyEnum.POINTS,
currency: pointsCurrency ?? CurrencyEnum.POINTS,
price: roomRate.redemption.localPrice.pointsPerStay,
additionalPrice:
roomRate.redemption.localPrice.additionalPricePerStay,
@@ -207,7 +211,7 @@ export function getRoomPrice(roomRate: Product, isMember: boolean) {
perStay: {
requested: undefined,
local: {
currency: CurrencyEnum.POINTS,
currency: pointsCurrency ?? CurrencyEnum.POINTS,
price: roomRate.redemption.localPrice.pointsPerStay,
additionalPrice:
roomRate.redemption.localPrice.additionalPricePerStay,
@@ -440,7 +444,11 @@ interface TRoomRedemption extends TRoom {
roomRate: RedemptionProduct
}
function getRedemptionPrice(rooms: TRoom[], nights: number) {
function getRedemptionPrice(
rooms: TRoom[],
nights: number,
pointsCurrency?: CurrencyEnum
) {
return rooms
.filter((room): room is TRoomRedemption => "redemption" in room.roomRate)
.reduce<Price>(
@@ -466,7 +474,7 @@ function getRedemptionPrice(rooms: TRoom[], nights: number) {
},
{
local: {
currency: CurrencyEnum.POINTS,
currency: pointsCurrency ?? CurrencyEnum.POINTS,
price: 0,
},
requested: undefined,
@@ -575,7 +583,8 @@ function getRegularPrice(rooms: TRoom[], isMember: boolean, nights: number) {
export function getTotalPrice(
rooms: TRoom[],
isMember: boolean,
nights: number
nights: number,
pointsCurrency?: CurrencyEnum
) {
const hasCorpChqRates = rooms.some(
(room) => "corporateCheque" in room.roomRate
@@ -586,7 +595,7 @@ export function getTotalPrice(
const hasRedemptionRates = rooms.some((room) => "redemption" in room.roomRate)
if (hasRedemptionRates) {
return getRedemptionPrice(rooms, nights)
return getRedemptionPrice(rooms, nights, pointsCurrency)
}
const hasVoucherRates = rooms.some((room) => "voucher" in room.roomRate)

View File

@@ -16,6 +16,7 @@ import {
writeToSessionStorage,
} from "./helpers"
import type { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
import type { Lang } from "@scandic-hotels/common/constants/language"
import type { BreakfastPackages } from "@scandic-hotels/trpc/routers/hotels/output"
import type { User } from "@scandic-hotels/trpc/types/user"
@@ -43,7 +44,8 @@ export function createDetailsStore(
searchParams: string,
user: User | null,
breakfastPackages: BreakfastPackages,
lang: Lang
lang: Lang,
pointsCurrency?: CurrencyEnum
) {
const isMember = !!user
const nights = dt(initialState.booking.toDate).diff(
@@ -68,14 +70,23 @@ export function createDetailsStore(
...defaultGuestState,
phoneNumberCC: getDefaultCountryFromLang(lang),
},
roomPrice: getRoomPrice(room.roomRate, isMember && idx === 0),
roomPrice: getRoomPrice(
room.roomRate,
isMember && idx === 0,
pointsCurrency
),
specialRequest: {
comment: "",
},
}
})
const initialTotalPrice = getTotalPrice(initialRooms, isMember, nights)
const initialTotalPrice = getTotalPrice(
initialRooms,
isMember,
nights,
pointsCurrency
)
const availableBeds = initialState.rooms.reduce<
DetailsState["availableBeds"]
@@ -175,7 +186,8 @@ export function createDetailsStore(
state.totalPrice = getTotalPrice(
state.rooms.map((r) => r.room),
isMember,
nights
nights,
pointsCurrency
)
const isAllStepsCompleted = checkRoomProgress(
@@ -206,7 +218,8 @@ export function createDetailsStore(
}
currentRoom.roomPrice = getRoomPrice(
currentRoom.roomRate,
isValidMembershipNo || currentRoom.guest.join
isValidMembershipNo || currentRoom.guest.join,
pointsCurrency
)
const nights = dt(state.booking.toDate).diff(
@@ -217,7 +230,8 @@ export function createDetailsStore(
state.totalPrice = getTotalPrice(
state.rooms.map((r) => r.room),
isMember,
nights
nights,
pointsCurrency
)
writeToSessionStorage({
@@ -240,7 +254,8 @@ export function createDetailsStore(
currentRoom.roomPrice = getRoomPrice(
currentRoom.roomRate,
join || !!currentRoom.guest.membershipNo
join || !!currentRoom.guest.membershipNo,
pointsCurrency
)
const nights = dt(state.booking.toDate).diff(
@@ -251,7 +266,8 @@ export function createDetailsStore(
state.totalPrice = getTotalPrice(
state.rooms.map((r) => r.room),
isMember,
nights
nights,
pointsCurrency
)
writeToSessionStorage({
@@ -316,7 +332,8 @@ export function createDetailsStore(
currentRoom.roomPrice = getRoomPrice(
currentRoom.roomRate,
Boolean(data.join || data.membershipNo || isMemberAndRoomOne)
Boolean(data.join || data.membershipNo || isMemberAndRoomOne),
pointsCurrency
)
const nights = dt(state.booking.toDate).diff(
@@ -327,7 +344,8 @@ export function createDetailsStore(
state.totalPrice = getTotalPrice(
state.rooms.map((r) => r.room),
isMember,
nights
nights,
pointsCurrency
)
const isAllStepsCompleted = checkRoomProgress(