Feat/SW-2078 update confirmation page vouchers and Corp Cheques rate * feat: SW-2078 Tablet bookingCode ref forward issue fix (cherry picked from commit 16a6a00fd99b6b6220a98ad74de062d67d35e1c0) * feat: SW-2078 Display Vouchers and Cheques prices on confirmation page (cherry picked from commit a76494de497a7d5e7641cb0036bd7055acf875c1) * feat: SW-2078 Rebase issue fix * feat: SW-2079 Updated rate title in terms modal * feat: SW-2078 Optimized code * feat: SW-2078 Removed extra tags Approved-by: Christian Andolf
77 lines
2.2 KiB
TypeScript
77 lines
2.2 KiB
TypeScript
import { formatPrice } from "@/utils/numberFormatting"
|
|
|
|
import type { IntlShape } from "react-intl"
|
|
|
|
import type { BookingConfirmationRoom } from "@/types/components/hotelReservation/bookingConfirmation/bookingConfirmation"
|
|
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
|
|
import { CurrencyEnum } from "@/types/enums/currency"
|
|
import type { BookingConfirmationSchema } from "@/types/trpc/routers/booking/confirmation"
|
|
|
|
export function mapRoomState(
|
|
booking: BookingConfirmationSchema,
|
|
room: BookingConfirmationRoom,
|
|
intl: IntlShape
|
|
) {
|
|
const breakfast = booking.packages.find(
|
|
(pkg) => pkg.code === BreakfastPackageEnum.REGULAR_BREAKFAST
|
|
)
|
|
const breakfastIncluded = booking.packages.some(
|
|
(pkg) => pkg.code === BreakfastPackageEnum.FREE_MEMBER_BREAKFAST
|
|
)
|
|
|
|
let formattedTotalCost = formatPrice(
|
|
intl,
|
|
booking.totalPrice,
|
|
booking.currencyCode
|
|
)
|
|
if (booking.roomPoints) {
|
|
formattedTotalCost = formatPrice(
|
|
intl,
|
|
booking.roomPoints,
|
|
CurrencyEnum.POINTS,
|
|
booking.totalPrice,
|
|
booking.currencyCode
|
|
)
|
|
} else if (booking.cheques) {
|
|
formattedTotalCost = formatPrice(
|
|
intl,
|
|
booking.cheques,
|
|
CurrencyEnum.CC,
|
|
booking.totalPrice,
|
|
booking.currencyCode
|
|
)
|
|
} else if (booking.vouchers) {
|
|
formattedTotalCost = formatPrice(
|
|
intl,
|
|
booking.vouchers,
|
|
CurrencyEnum.Voucher
|
|
)
|
|
}
|
|
|
|
return {
|
|
adults: booking.adults,
|
|
bedDescription: room.bedType.description,
|
|
breakfast,
|
|
breakfastIncluded,
|
|
cheques: booking.cheques,
|
|
childrenAges: booking.childrenAges,
|
|
childBedPreferences: booking.childBedPreferences,
|
|
confirmationNumber: booking.confirmationNumber,
|
|
currencyCode: booking.currencyCode,
|
|
formattedTotalCost,
|
|
fromDate: booking.checkInDate,
|
|
name: room.name,
|
|
packages: booking.packages,
|
|
rateDefinition: booking.rateDefinition,
|
|
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,
|
|
}
|
|
}
|