Feat/book 425 optimize campaign rate card * feat(BOOK-425): design updates to RateCard * feat(BOOK-425): design updates to campaign BookingCodeChip * feat(BOOK-425): fixed breakfast message & booking code chips on select rate and enter detailss * feat(BOOK-425): fixed booking code chip on Booking Confirmation page * fixed draft comments * fixed more comments * feat(BOOK-425): removed fixed height from RateCard banner * fixed another variable comment * fixed more pr comments * fixed more pr comments * updated ratecard campaign standard rate title color * removed deconstructed props Approved-by: Bianca Widstam Approved-by: Erik Tiekstra
145 lines
4.1 KiB
TypeScript
145 lines
4.1 KiB
TypeScript
import { logger } from "@scandic-hotels/common/logger"
|
|
|
|
import { sumPackages } from "../../../../utils/SelectRate"
|
|
|
|
import type { RoomState } from "../../../../stores/enter-details/types"
|
|
|
|
export function mapToPrice(rooms: RoomState[], isMember: boolean) {
|
|
return rooms
|
|
.filter((room) => room && room.room.roomRate)
|
|
.map(({ room }, idx) => {
|
|
const isMainRoom = idx === 0
|
|
|
|
const pkgsSum = sumPackages(room.roomFeatures)
|
|
|
|
const roomWithoutPrice = {
|
|
...room,
|
|
packages: room.roomFeatures,
|
|
rateDefinition: {
|
|
...room.roomRate.rateDefinition,
|
|
isMemberRate: false,
|
|
},
|
|
}
|
|
|
|
if ("corporateCheque" in room.roomRate) {
|
|
if (
|
|
room.roomRate.corporateCheque.localPrice.additionalPricePerStay ||
|
|
pkgsSum.price
|
|
) {
|
|
return {
|
|
...roomWithoutPrice,
|
|
price: {
|
|
corporateCheque: {
|
|
...room.roomRate.corporateCheque.localPrice,
|
|
additionalPricePerStay:
|
|
room.roomRate.corporateCheque.localPrice
|
|
.additionalPricePerStay || 0,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
return {
|
|
...roomWithoutPrice,
|
|
price: {
|
|
corporateCheque: room.roomRate.corporateCheque.localPrice,
|
|
},
|
|
}
|
|
}
|
|
|
|
if ("redemption" in room.roomRate) {
|
|
if (
|
|
room.roomRate.redemption.localPrice.additionalPricePerStay ||
|
|
pkgsSum.price
|
|
) {
|
|
return {
|
|
...roomWithoutPrice,
|
|
price: {
|
|
redemption: {
|
|
...room.roomRate.redemption.localPrice,
|
|
additionalPricePerStay:
|
|
room.roomRate.redemption.localPrice.additionalPricePerStay ||
|
|
0,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
return {
|
|
...roomWithoutPrice,
|
|
price: {
|
|
redemption: room.roomRate.redemption.localPrice,
|
|
},
|
|
}
|
|
}
|
|
|
|
if ("voucher" in room.roomRate) {
|
|
return {
|
|
...roomWithoutPrice,
|
|
price: {
|
|
voucher: room.roomRate.voucher,
|
|
},
|
|
}
|
|
}
|
|
|
|
const isMemberRate = !!(room.guest.join || room.guest.membershipNo)
|
|
if ((isMember && isMainRoom) || isMemberRate) {
|
|
if ("member" in room.roomRate && room.roomRate.member) {
|
|
if (pkgsSum.price) {
|
|
return {
|
|
...roomWithoutPrice,
|
|
rateDefinition: {
|
|
...roomWithoutPrice.rateDefinition,
|
|
isMemberRate: true,
|
|
},
|
|
price: {
|
|
regular: {
|
|
...room.roomRate.member.localPrice,
|
|
pricePerNight: room.roomRate.member.localPrice.pricePerNight,
|
|
pricePerStay: room.roomRate.member.localPrice.pricePerStay,
|
|
regularPricePerStay:
|
|
(room.roomRate.public?.localPrice.pricePerStay ||
|
|
room.roomRate.member.localPrice.pricePerStay) +
|
|
pkgsSum.price,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
return {
|
|
...roomWithoutPrice,
|
|
rateDefinition: {
|
|
...roomWithoutPrice.rateDefinition,
|
|
isMemberRate: true,
|
|
},
|
|
price: {
|
|
regular: {
|
|
...room.roomRate.member.localPrice,
|
|
regularPricePerStay:
|
|
room.roomRate.public?.localPrice.pricePerStay ||
|
|
room.roomRate.member.localPrice.pricePerStay,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
}
|
|
|
|
if ("public" in room.roomRate && room.roomRate.public) {
|
|
if (pkgsSum.price) {
|
|
return {
|
|
...roomWithoutPrice,
|
|
price: {
|
|
regular: room.roomRate.public.localPrice,
|
|
},
|
|
}
|
|
}
|
|
return {
|
|
...roomWithoutPrice,
|
|
price: {
|
|
regular: room.roomRate.public.localPrice,
|
|
},
|
|
}
|
|
}
|
|
|
|
logger.error("Unknown roomRate", room.roomRate)
|
|
throw new Error(`Unknown roomRate`)
|
|
})
|
|
}
|