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:
@@ -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)
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user