Files
web/packages/booking-flow/lib/components/BookingConfirmation/utils.ts
Anton Gunnarsson 16fbdb7ae0 Merged in fix/refactor-currency-display (pull request #3434)
fix(SW-3616): Handle EuroBonus point type everywhere

* Add tests to formatPrice

* formatPrice

* More work replacing config with api points type

* More work replacing config with api points type

* More fixing with currency

* maybe actually fixed it

* Fix MyStay

* Clean up

* Fix comments

* Merge branch 'master' into fix/refactor-currency-display

* Fix calculateTotalPrice for EB points + SF points + cash


Approved-by: Joakim Jäderberg
2026-01-15 09:32:17 +00:00

95 lines
2.7 KiB
TypeScript

import { type IntlShape } from "react-intl"
import { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
import { formatPrice } from "@scandic-hotels/common/utils/numberFormatting"
import { BreakfastPackageEnum } from "@scandic-hotels/trpc/enums/breakfast"
import type {
BookingConfirmationSchema,
PackageSchema,
} from "@scandic-hotels/trpc/types/bookingConfirmation"
import type { BookingConfirmationRoom } from "../../types/components/bookingConfirmation/bookingConfirmation"
export function mapRoomState(
booking: BookingConfirmationSchema,
room: BookingConfirmationRoom,
intl: IntlShape
) {
const breakfastPackage = booking.packages.find(
(pkg) => pkg.code === BreakfastPackageEnum.REGULAR_BREAKFAST
)
const breakfastIncluded =
booking.packages.some(
(pkg) => pkg.code === BreakfastPackageEnum.FREE_MEMBER_BREAKFAST
) || booking.rateDefinition.breakfastIncluded
let breakfast: false | undefined | PackageSchema
if (breakfastPackage) {
breakfast = breakfastPackage
} else if (!breakfastIncluded) {
breakfast = false
}
let formattedRoomCost = formatPrice(
intl,
booking.roomPrice,
booking.currencyCode
)
if (booking.roomPoints) {
formattedRoomCost = formatPrice(
intl,
booking.roomPoints,
CurrencyEnum.POINTS,
booking.roomPrice,
booking.currencyCode,
booking.roomPointType
)
} else if (booking.cheques) {
formattedRoomCost = formatPrice(
intl,
booking.cheques,
CurrencyEnum.CC,
booking.roomPrice,
booking.currencyCode
)
} else if (booking.vouchers) {
formattedRoomCost = formatPrice(
intl,
booking.vouchers,
CurrencyEnum.Voucher
)
}
return {
adults: booking.adults,
bedDescription: room.bedType.description,
bedType: room.bedType.mainBed.type,
bookingCode: booking.bookingCode,
breakfast,
breakfastIncluded,
cheques: booking.cheques,
childrenAges: booking.childrenAges,
childBedPreferences: booking.childBedPreferences,
confirmationNumber: booking.confirmationNumber,
currencyCode: booking.currencyCode,
pointsType: booking.roomPointType,
formattedRoomCost,
fromDate: booking.checkInDate,
name: room.name,
packages: booking.packages,
rateDefinition: booking.rateDefinition,
rateCodeType: booking.bookingType,
refId: booking.refId,
roomFeatures: booking.packages.filter((p) => p.type === "RoomFeature"),
roomPoints: booking.roomPoints,
roomPrice: booking.roomPrice,
roomTypeCode: booking.roomTypeCode,
toDate: booking.checkOutDate,
totalPrice: booking.totalPrice,
totalPriceExVat: booking.totalPriceExVat,
vatAmount: booking.vatAmount,
vouchers: booking.vouchers,
}
}