chore(SW-3321): Moved Select rate context to booking-flow package * chore(SW-3321): Moved Select rate context to booking-flow package * chore(SW-3321): Optimised code Approved-by: Joakim Jäderberg
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
"use client"
|
|
import { sumPackages } from "@scandic-hotels/booking-flow/utils/SelectRate"
|
|
|
|
import { useMyStayStore } from "@/stores/my-stay"
|
|
|
|
import PriceType from "../PriceType"
|
|
|
|
import type { PriceType as _PriceType } from "@/types/components/hotelReservation/myStay/myStay"
|
|
|
|
export default function 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.totalPoints, 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={totalCheques}
|
|
formattedTotalPrice={formattedTotalPrice}
|
|
isCancelled={bookedRoom.isCancelled}
|
|
currencyCode={bookedRoom.currencyCode}
|
|
priceType={bookedRoom.priceType}
|
|
rateDefinition={bookedRoom.rateDefinition}
|
|
totalPoints={totalPoints}
|
|
totalPrice={totalPrice}
|
|
vouchers={bookedRoom.vouchers}
|
|
/>
|
|
)
|
|
}
|