Files
web/apps/scandic-web/components/HotelReservation/EnterDetails/Summary/UI/mapToPrice.ts
Simon.Emanuelsson 85acd3453d Merged in feat/SW-1719-strikethrough-rates (pull request #2266)
Feat/SW-1719 strikethrough rates

* feat(SW-1719): Strikethrough rate if logged in on regular rate cards

* feat(SW-1719): Strikethrough rate if logged in on rate summary

* feat(SW-1719): Strikethrough rate if logged in on mobile rate summary

* feat(SW-1719): Strikethrough rate if logged in on enter details

* feat(SW-1719): Strikethrough rate support for multiple rooms

* feat(SW-1719): booking receipt fixes on confirmation page

* feat(SW-1719): improve initial total price calculation

* feat: harmonize enter details total price to use one and the same function


Approved-by: Michael Zetterberg
2025-06-13 12:01:16 +00:00

140 lines
3.9 KiB
TypeScript

import { sumPackages } from "@/components/HotelReservation/utils"
import type { RoomState } from "@/types/stores/enter-details"
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: {
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: {
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: {
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,
},
}
}
console.error(room.roomRate)
throw new Error(`Unknown roomRate`)
})
}