Files
web/apps/scandic-web/components/HotelReservation/BookingConfirmation/utils.ts
Anton Gunnarsson e572d9e7e9 Merged in feat/sw-2862-move-booking-router-to-trpc-package (pull request #2421)
feat(SW-2861): Move booking router to trpc package

* Use direct imports from trpc package

* Add lint-staged config to trpc

* Move lang enum to common

* Restructure trpc package folder structure

* WIP first step

* update internal imports in trpc

* Fix most errors in scandic-web

Just 100 left...

* Move Props type out of trpc

* Fix CategorizedFilters types

* Move more schemas in hotel router

* Fix deps

* fix getNonContentstackUrls

* Fix import error

* Fix entry error handling

* Fix generateMetadata metrics

* Fix alertType enum

* Fix duplicated types

* lint:fix

* Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package

* Fix broken imports

* Move booking router to trpc package

* Move partners router to trpc package

* Move autocomplete router to trpc package

* Move booking router to trpc package

* Merge branch 'master' into feat/sw-2862-move-booking-router-to-trpc-package


Approved-by: Linus Flood
2025-06-26 13:21:16 +00:00

93 lines
2.6 KiB
TypeScript

import { type IntlShape } from "react-intl"
import { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
import { BreakfastPackageEnum } from "@scandic-hotels/trpc/enums/breakfast"
import { formatPrice } from "@/utils/numberFormatting"
import type {
BookingConfirmationSchema,
PackageSchema,
} from "@scandic-hotels/trpc/types/bookingConfirmation"
import type { BookingConfirmationRoom } from "@/types/components/hotelReservation/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
)
} 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,
formattedRoomCost,
fromDate: booking.checkInDate,
name: room.name,
packages: booking.packages,
rateDefinition: booking.rateDefinition,
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,
}
}