From 722d4505ba6796af165014044a1f26acce8ad792 Mon Sep 17 00:00:00 2001 From: Simon Emanuelsson Date: Wed, 16 Apr 2025 12:41:37 +0200 Subject: [PATCH] fix: always use totalPrice to display roomCharge --- .../PriceDetails/index.tsx | 8 +- .../PriceDetails/mapToPrice.ts | 21 +- .../Summary/UI/PriceDetailsTable/index.tsx | 398 ------------------ .../EnterDetails/Summary/UI/index.tsx | 12 +- .../EnterDetails/Summary/UI/mapToPrice.ts | 77 +++- .../HotelReservation/MyStay/Cheques/index.tsx | 40 ++ .../MyStay/MultiRoom/index.tsx | 35 +- .../PriceDetails/PriceDetailsTable/index.tsx | 330 --------------- .../MyStay/PriceDetails/mapToPrice.ts | 34 +- .../HotelReservation/MyStay/PriceType.tsx | 62 +++ .../MyStay/SingleRoom/index.tsx | 45 +- .../MyStay/utils/getPriceType.ts | 12 +- .../MyStay/utils/mapRoomDetails.ts | 3 + .../Row/Price/CorporateCheque.tsx | 16 +- .../Row/Price/Redemption.tsx | 16 +- .../PriceDetailsTable/Row/Price/Regular.tsx | 9 +- .../stores/enter-details/helpers.ts | 48 ++- .../stores/my-stay/myStayRoomDetailsStore.ts | 10 +- 18 files changed, 312 insertions(+), 864 deletions(-) delete mode 100644 apps/scandic-web/components/HotelReservation/EnterDetails/Summary/UI/PriceDetailsTable/index.tsx create mode 100644 apps/scandic-web/components/HotelReservation/MyStay/Cheques/index.tsx delete mode 100644 apps/scandic-web/components/HotelReservation/MyStay/PriceDetails/PriceDetailsTable/index.tsx create mode 100644 apps/scandic-web/components/HotelReservation/MyStay/PriceType.tsx diff --git a/apps/scandic-web/components/HotelReservation/BookingConfirmation/PriceDetails/index.tsx b/apps/scandic-web/components/HotelReservation/BookingConfirmation/PriceDetails/index.tsx index 7d05ebfe2..e15b6924e 100644 --- a/apps/scandic-web/components/HotelReservation/BookingConfirmation/PriceDetails/index.tsx +++ b/apps/scandic-web/components/HotelReservation/BookingConfirmation/PriceDetails/index.tsx @@ -36,10 +36,6 @@ export default function PriceDetails() { return total } - const pkgsSum = - room.roomFeatures?.reduce((total, pkg) => total + pkg.totalPrice, 0) ?? - 0 - if (room.cheques) { // CorporateCheque Booking total.local.currency = CurrencyEnum.CC @@ -54,7 +50,7 @@ export default function PriceDetails() { total.local.price = total.local.price + room.vouchers } else { // Price Booking - total.local.price = total.local.price + room.roomPrice + pkgsSum + total.local.price = total.local.price + room.totalPrice } if ( @@ -62,7 +58,7 @@ export default function PriceDetails() { room.roomPrice ) { total.local.additionalPrice = - (total.local.additionalPrice || 0) + room.roomPrice + pkgsSum + (total.local.additionalPrice || 0) + room.totalPrice total.local.additionalPriceCurrency = currency } diff --git a/apps/scandic-web/components/HotelReservation/BookingConfirmation/PriceDetails/mapToPrice.ts b/apps/scandic-web/components/HotelReservation/BookingConfirmation/PriceDetails/mapToPrice.ts index 68d231b5d..d4f7dc322 100644 --- a/apps/scandic-web/components/HotelReservation/BookingConfirmation/PriceDetails/mapToPrice.ts +++ b/apps/scandic-web/components/HotelReservation/BookingConfirmation/PriceDetails/mapToPrice.ts @@ -4,6 +4,8 @@ import { } from "@/server/routers/hotels/schemas/packages" import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums" +import { BreakfastPackageEnum } from "@/types/enums/breakfast" +import { PackageTypeEnum } from "@/types/enums/packages" import type { Package } from "@/types/requests/packages" import type { Room } from "@/types/stores/booking-confirmation" @@ -15,16 +17,20 @@ export function mapToPrice(rooms: (Room | null)[], nights: number) { if (room.cheques) { price = { corporateCheque: { - additionalPricePerStay: room.roomPrice ? room.roomPrice : undefined, - currency: room.roomPrice ? room.currencyCode : undefined, + additionalPricePerStay: room.totalPrice + ? room.totalPrice + : undefined, + currency: room.totalPrice ? room.currencyCode : undefined, numberOfCheques: room.cheques, }, } } else if (room.roomPoints) { price = { redemption: { - additionalPricePerStay: room.roomPrice ? room.roomPrice : undefined, - currency: room.roomPrice ? room.currencyCode : undefined, + additionalPricePerStay: room.totalPrice + ? room.totalPrice + : undefined, + currency: room.totalPrice ? room.currencyCode : undefined, pointsPerNight: room.roomPoints / nights, pointsPerStay: room.roomPoints, }, @@ -40,7 +46,7 @@ export function mapToPrice(rooms: (Room | null)[], nights: number) { regular: { currency: room.currencyCode, pricePerNight: room.roomPrice / nights, - pricePerStay: room.roomPrice, + pricePerStay: room.totalPrice, }, } } @@ -53,7 +59,10 @@ export function mapToPrice(rooms: (Room | null)[], nights: number) { price: room.breakfast?.unitPrice, totalPrice: room.breakfast?.totalPrice, }, - packageType: room.breakfast?.type, + packageType: + room.breakfast?.code === BreakfastPackageEnum.REGULAR_BREAKFAST + ? PackageTypeEnum.BreakfastAdult + : "", requestedPrice: { currency: room.breakfast?.currency, price: room.breakfast?.unitPrice, diff --git a/apps/scandic-web/components/HotelReservation/EnterDetails/Summary/UI/PriceDetailsTable/index.tsx b/apps/scandic-web/components/HotelReservation/EnterDetails/Summary/UI/PriceDetailsTable/index.tsx deleted file mode 100644 index 4f1daf447..000000000 --- a/apps/scandic-web/components/HotelReservation/EnterDetails/Summary/UI/PriceDetailsTable/index.tsx +++ /dev/null @@ -1,398 +0,0 @@ -"use client" - -import { Fragment } from "react" -import { useIntl } from "react-intl" - -import DiscountIcon from "@scandic-hotels/design-system/Icons/DiscountIcon" -import { Typography } from "@scandic-hotels/design-system/Typography" - -import { dt } from "@/lib/dt" - -import IconChip from "@/components/TempDesignSystem/IconChip" -import Body from "@/components/TempDesignSystem/Text/Body" -import Caption from "@/components/TempDesignSystem/Text/Caption" -import useLang from "@/hooks/useLang" -import { formatPrice } from "@/utils/numberFormatting" - -import styles from "./priceDetailsTable.module.css" - -import type { Price } from "@/types/components/hotelReservation/price" -import { CurrencyEnum } from "@/types/enums/currency" -import type { RoomState } from "@/types/stores/enter-details" - -function Row({ - label, - value, - bold, -}: { - label: string - value: string - bold?: boolean -}) { - return ( - - - {label} - - - {value} - - - ) -} - -function TableSection({ children }: React.PropsWithChildren) { - return {children} -} - -function TableSectionHeader({ - title, - subtitle, -}: { - title: string - subtitle?: string -}) { - return ( - - - {title} - {subtitle ? {subtitle} : null} - - - ) -} - -export type Room = Pick< - RoomState["room"], - | "adults" - | "bedType" - | "breakfast" - | "childrenInRoom" - | "roomFeatures" - | "roomRate" - | "roomType" -> & { - guest?: RoomState["room"]["guest"] -} - -export interface PriceDetailsTableProps { - bookingCode?: string - fromDate: string - isMember: boolean - rooms: Room[] - toDate: string - totalPrice: Price - vat: number -} - -export default function PriceDetailsTable({ - bookingCode, - fromDate, - isMember, - rooms, - toDate, - totalPrice, - vat, -}: PriceDetailsTableProps) { - const intl = useIntl() - const lang = useLang() - - const diff = dt(toDate).diff(fromDate, "days") - const nights = intl.formatMessage( - { - defaultMessage: "{totalNights, plural, one {# night} other {# nights}}", - }, - { totalNights: diff } - ) - const vatPercentage = vat / 100 - const vatAmount = totalPrice.local.price * vatPercentage - - const priceExclVat = totalPrice.local.price - vatAmount - - const duration = ` ${dt(fromDate).locale(lang).format("ddd, D MMM")} - - - ${dt(toDate).locale(lang).format("ddd, D MMM")} (${nights})` - const noVatCurrencies = [ - CurrencyEnum.CC, - CurrencyEnum.POINTS, - CurrencyEnum.Voucher, - ] - return ( - - {rooms.map((room, idx) => { - const isMainRoom = idx === 0 - const getMemberRate = - room.guest?.join || - room.guest?.membershipNo || - (isMainRoom && isMember) - - let price - if ( - getMemberRate && - "member" in room.roomRate && - room.roomRate.member - ) { - price = room.roomRate.member - } else if ("public" in room.roomRate && room.roomRate.public) { - price = room.roomRate.public - } - const voucherPrice = - "voucher" in room.roomRate ? room.roomRate.voucher : undefined - const chequePrice = - "corporateCheque" in room.roomRate - ? room.roomRate.corporateCheque - : undefined - const redemptionPrice = - "redemption" in room.roomRate ? room.roomRate.redemption : undefined - if (!price && !voucherPrice && !chequePrice && !redemptionPrice) { - return null - } - return ( - - - {rooms.length > 1 && ( - - - - )} - - {price && ( - <> - - {room.roomFeatures - ? room.roomFeatures.map((feature) => ( - - )) - : null} - {room.bedType ? ( - - ) : null} - - - )} - {voucherPrice && ( - - )} - {chequePrice && ( - - )} - {redemptionPrice && ( - - )} - - - {room.breakfast ? ( - - - {room.childrenInRoom?.length ? ( - - ) : null} - - - ) : null} - - ) - })} - - - {!noVatCurrencies.includes(totalPrice.local.currency) ? ( - <> - - - - ) : null} - - - - - {totalPrice.local.regularPrice ? ( - - - - - - ) : null} - {bookingCode && ( - - - - )} - -
- - {intl.formatMessage({ - defaultMessage: "Room", - })} - { - /* eslint-disable-next-line formatjs/no-literal-string-in-jsx */ - " " - } - {idx + 1} - -
- - {intl.formatMessage({ - defaultMessage: "Price including VAT", - })} - - - - {formatPrice( - intl, - totalPrice.local.price, - totalPrice.local.currency, - totalPrice.local.additionalPrice, - totalPrice.local.additionalPriceCurrency - )} - -
-
- {formatPrice( - intl, - totalPrice.local.regularPrice, - totalPrice.local.currency - )} -
- - } - > - {intl.formatMessage( - { - defaultMessage: "Booking code: {value}", - }, - { - value: bookingCode, - strong: (text) => ( - - {text} - - ), - } - )} - - -
- ) -} diff --git a/apps/scandic-web/components/HotelReservation/EnterDetails/Summary/UI/index.tsx b/apps/scandic-web/components/HotelReservation/EnterDetails/Summary/UI/index.tsx index d2e850358..003b7a17a 100644 --- a/apps/scandic-web/components/HotelReservation/EnterDetails/Summary/UI/index.tsx +++ b/apps/scandic-web/components/HotelReservation/EnterDetails/Summary/UI/index.tsx @@ -48,13 +48,13 @@ export default function SummaryUI({ const intl = useIntl() const lang = useLang() - const diff = dt(booking.toDate).diff(booking.fromDate, "days") + const nights = dt(booking.toDate).diff(booking.fromDate, "days") - const nights = intl.formatMessage( + const nightsMsg = intl.formatMessage( { defaultMessage: "{totalNights, plural, one {# night} other {# nights}}", }, - { totalNights: diff } + { totalNights: nights } ) function handleToggleSummary() { @@ -95,7 +95,7 @@ export default function SummaryUI({ ? totalPrice.requested.currency === totalPrice.local.currency : false - const priceDetailsRooms = mapToPrice(rooms, isMember) + const priceDetailsRooms = mapToPrice(rooms, isMember, nights) return (
@@ -113,7 +113,7 @@ export default function SummaryUI({ size={15} /> {/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */} - {dt(booking.toDate).locale(lang).format("ddd, D MMM")} ({nights}) + {dt(booking.toDate).locale(lang).format("ddd, D MMM")} ({nightsMsg})