Files
web/apps/scandic-web/components/HotelReservation/MyStay/utils/mapRoomDetails.ts
Pontus Dreij 74c5b47319 Merged in feat/SW-1737-design-mystay-multiroom (pull request #1565)
Feat/SW-1737 design mystay multiroom

* feat(SW-1737) Fixed member view of guest details

* feat(SW-1737) fix merge issues

* feat(SW-1737) Fixed price details

* feat(SW-1737) removed unused imports

* feat(SW-1737) removed true as statement

* feat(SW-1737) updated store handling

* feat(SW-1737) fixed bug showing double numbers

* feat(SW-1737) small design fixed

* feat(SW-1737) fixed rebase errors

* feat(SW-1737) fixed create booking error with dates

* feat(SW-1737) fixed view multiroom as singleroom

* feat(SW-1737) fixes for multiroom

* feat(SW-1737) fixed bookingsummary

* feat(SW-1737) dont hide modify dates

* feat(SW-1737) updated breakfast to handle number

* feat(SW-1737) Added red color if member rate

* feat(SW-1737) fix PR comments

* feat(SW-1737) updated member tiers svg

* feat(SW-1737) updated how to handle paymentMethodDescription

* feat(SW-1737) fixes after testing mystay

* feat(SW-1737) updated Room type to just use whats used

* feat(SW-1737) fixed access

* feat(SW-1737) refactor my stay after PR comments

* feat(SW-1737) fix roomNumber translation

* feat(SW-1737) removed log


Approved-by: Arvid Norlin
2025-03-24 09:30:10 +00:00

141 lines
4.4 KiB
TypeScript

import { BookingStatusEnum } from "@/constants/booking"
import { dt } from "@/lib/dt"
import { formatChildBedPreferences } from "../utils"
import { convertToChildType } from "./convertToChildType"
import type { BreakfastPackage } from "@/types/components/hotelReservation/breakfast"
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
import { PackageTypeEnum } from "@/types/enums/packages"
import type { Room } from "@/types/hotel"
import type { BookingConfirmation } from "@/types/trpc/routers/booking/confirmation"
import type { Room as MyStayRoom } from "@/stores/my-stay/myStayRoomDetailsStore"
interface MapRoomDetailsParams {
booking: BookingConfirmation["booking"]
room: (Room & { bedType: Room["roomTypes"][number] }) | null
roomNumber: number
}
export function mapRoomDetails({
booking,
room,
roomNumber,
}: MapRoomDetailsParams): MyStayRoom {
const nights = dt(booking.checkOutDate)
.startOf("day")
.diff(dt(booking.checkInDate).startOf("day"), "days")
const breakfastPkg = booking.packages.find(
(pkg) =>
pkg.code === BreakfastPackageEnum.REGULAR_BREAKFAST ||
pkg.code === BreakfastPackageEnum.FREE_MEMBER_BREAKFAST ||
pkg.code === BreakfastPackageEnum.SPECIAL_PACKAGE_BREAKFAST
)
const featuresPkg = booking.packages.filter(
(pkg) =>
pkg.code === RoomPackageCodeEnum.PET_ROOM ||
pkg.code === RoomPackageCodeEnum.ALLERGY_ROOM ||
pkg.code === RoomPackageCodeEnum.ACCESSIBILITY_ROOM
)
const breakfast: BreakfastPackage | false = breakfastPkg
? {
code: breakfastPkg.code,
description: breakfastPkg.description,
localPrice: {
currency: breakfastPkg.currency,
price: breakfastPkg.unitPrice,
totalPrice: breakfastPkg.totalPrice,
},
requestedPrice: {
currency: breakfastPkg.currency,
price: breakfastPkg.unitPrice,
totalPrice: breakfastPkg.totalPrice,
},
packageType: PackageTypeEnum.BreakfastAdult,
}
: false
const isCancelled = booking.reservationStatus === BookingStatusEnum.Cancelled
const childrenAsString = formatChildBedPreferences({
childrenAges: booking.childrenAges,
childBedPreferences: booking.childBedPreferences,
})
const childrenInRoom = convertToChildType(
booking.childrenAges,
booking.childBedPreferences
)
return {
hotelId: booking.hotelId,
roomTypeCode: booking.roomTypeCode,
adults: booking.adults,
childrenAges: booking.childrenAges,
checkInDate: booking.checkInDate,
checkOutDate: booking.checkOutDate,
confirmationNumber: booking.confirmationNumber,
cancellationNumber: booking.cancellationNumber,
createDateTime: booking.createDateTime,
rateDefinition: booking.rateDefinition,
guaranteeInfo: booking.guaranteeInfo,
linkedReservations: booking.linkedReservations,
bookingCode: booking.bookingCode,
isModifiable: booking.isModifiable,
isCancelable: booking.isCancelable,
multiRoom: booking.multiRoom,
canChangeDate: booking.canChangeDate,
guest: booking.guest,
currencyCode: booking.currencyCode,
vatPercentage: booking.vatPercentage,
mainRoom: booking.mainRoom,
roomName: room?.name ?? "",
roomNumber,
isCancelled,
childrenInRoom,
childrenAsString,
terms: booking.rateDefinition.cancellationText,
packages: featuresPkg.map((pkg) => ({
code: pkg.code as RoomPackageCodeEnum,
description: pkg.description,
inventories: [],
itemCode: "",
localPrice: {
currency: pkg.currency,
price: pkg.unitPrice,
totalPrice: pkg.totalPrice,
},
requestedPrice: {
currency: pkg.currency,
price: pkg.unitPrice,
totalPrice: pkg.totalPrice,
},
})),
bedType: {
description: room?.bedType.mainBed.description ?? "",
roomTypeCode: room?.bedType.code ?? "",
},
roomPrice: {
perNight: {
local: {
currency: booking.currencyCode,
price: isCancelled ? 0 : booking.roomPrice / nights,
},
requested: undefined,
},
perStay: {
local: {
currency: booking.currencyCode,
price: isCancelled ? 0 : booking.roomPrice,
},
requested: undefined,
},
},
breakfast,
}
}