feat: move room charge to top in price details modal
This commit is contained in:
committed by
Michael Zetterberg
parent
194a401a56
commit
a99e434d84
@@ -6,6 +6,7 @@ import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
import { useMyStayStore } from "@/stores/my-stay"
|
||||
|
||||
import PriceType from "@/components/HotelReservation/MyStay/PriceType"
|
||||
import { sumPackages } from "@/components/HotelReservation/utils"
|
||||
|
||||
import styles from "./details.module.css"
|
||||
|
||||
@@ -17,6 +18,7 @@ export default function PriceDetails() {
|
||||
formattedTotalPrice: state.totalPrice,
|
||||
isCancelled: state.bookedRoom.isCancelled,
|
||||
currencyCode: state.bookedRoom.currencyCode,
|
||||
packages: state.bookedRoom.packages,
|
||||
priceType: state.bookedRoom.priceType,
|
||||
rateDefinition: state.bookedRoom.rateDefinition,
|
||||
roomPoints: state.bookedRoom.roomPoints,
|
||||
@@ -24,6 +26,14 @@ export default function PriceDetails() {
|
||||
vouchers: state.bookedRoom.vouchers,
|
||||
}))
|
||||
|
||||
let totalPrice = pricing.totalPrice
|
||||
// API returns negative values for totalPrice
|
||||
// on voucher bookings (╯°□°)╯︵ ┻━┻
|
||||
if (pricing.vouchers && totalPrice < 0) {
|
||||
const pkgsSum = sumPackages(pricing.packages)
|
||||
totalPrice = pkgsSum.price
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={styles.priceDetails}>
|
||||
<div className={styles.price}>
|
||||
@@ -34,7 +44,7 @@ export default function PriceDetails() {
|
||||
})}
|
||||
</p>
|
||||
</Typography>
|
||||
<PriceType {...pricing} />
|
||||
<PriceType {...pricing} totalPrice={totalPrice} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -1,26 +1,39 @@
|
||||
"use client"
|
||||
import { useMyStayStore } from "@/stores/my-stay"
|
||||
|
||||
import { sumPackages } from "../../utils"
|
||||
import PriceType from "../PriceType"
|
||||
|
||||
import type { PriceType as _PriceType } from "@/types/components/hotelReservation/myStay/myStay"
|
||||
|
||||
export default function TotalPrice() {
|
||||
const { bookedRoom, formattedTotalPrice } = useMyStayStore((state) => ({
|
||||
bookedRoom: state.bookedRoom,
|
||||
formattedTotalPrice: state.totalPrice,
|
||||
}))
|
||||
const { bookedRoom, formattedTotalPrice, rooms } = useMyStayStore(
|
||||
(state) => ({
|
||||
bookedRoom: state.bookedRoom,
|
||||
formattedTotalPrice: state.totalPrice,
|
||||
rooms: state.rooms,
|
||||
})
|
||||
)
|
||||
|
||||
const totalCheques = rooms.reduce((total, room) => total + room.cheques, 0)
|
||||
const totalPoints = rooms.reduce((total, room) => total + room.roomPoints, 0)
|
||||
|
||||
let totalPrice = rooms.reduce((total, room) => total + room.totalPrice, 0)
|
||||
if (rooms.some((room) => room.vouchers)) {
|
||||
const pkgsSum = sumPackages(rooms.flatMap((r) => r.packages || []))
|
||||
totalPrice = pkgsSum.price
|
||||
}
|
||||
|
||||
return (
|
||||
<PriceType
|
||||
cheques={bookedRoom.cheques}
|
||||
cheques={totalCheques}
|
||||
formattedTotalPrice={formattedTotalPrice}
|
||||
isCancelled={bookedRoom.isCancelled}
|
||||
currencyCode={bookedRoom.currencyCode}
|
||||
priceType={bookedRoom.priceType}
|
||||
rateDefinition={bookedRoom.rateDefinition}
|
||||
roomPoints={bookedRoom.roomPoints}
|
||||
totalPrice={bookedRoom.totalPrice}
|
||||
roomPoints={totalPoints}
|
||||
totalPrice={totalPrice}
|
||||
vouchers={bookedRoom.vouchers}
|
||||
/>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user