Merged in feat/SW-2079-update-booking-page-to-show-points- (pull request #1683)
feat: SW-2079 Show points in confirmation page * feat: SW-2079 Show points in confirmation page * feat: SW-2079 Optimized code * feat: SW-2079 Updated Body to Typography * feat: SW-2079 Multi-room total cost display * feat: SW-2079 Add reward nights condition rate title * feat: SW-2079 Removed extra checks * feat: SW-2079 Optimmized formatPrice function * feat: SW-2079 Typo fix Approved-by: Christian Andolf
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
"use client"
|
||||
|
||||
import { useRef } from "react"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { createBookingConfirmationStore } from "@/stores/booking-confirmation"
|
||||
|
||||
import { BookingConfirmationContext } from "@/contexts/BookingConfirmation"
|
||||
import { formatPrice } from "@/utils/numberFormatting"
|
||||
|
||||
import type { BookingConfirmationStore } from "@/types/contexts/booking-confirmation"
|
||||
import { CurrencyEnum } from "@/types/enums/currency"
|
||||
import type { BookingConfirmationProviderProps } from "@/types/providers/booking-confirmation"
|
||||
|
||||
export default function BookingConfirmationProvider({
|
||||
@@ -18,9 +21,29 @@ export default function BookingConfirmationProvider({
|
||||
rooms,
|
||||
vat,
|
||||
}: BookingConfirmationProviderProps) {
|
||||
const intl = useIntl()
|
||||
const storeRef = useRef<BookingConfirmationStore>()
|
||||
|
||||
if (!storeRef.current) {
|
||||
const totalBookingPrice = rooms.reduce((acc, room) => {
|
||||
const reservationTotalPrice = room?.totalPrice || 0
|
||||
return acc + reservationTotalPrice
|
||||
}, 0)
|
||||
let formattedTotalCost = formatPrice(intl, totalBookingPrice, currencyCode)
|
||||
const totalBookingPoints = rooms.reduce((acc, room) => {
|
||||
return acc + (room?.roomPoints ?? 0)
|
||||
}, 0)
|
||||
let isVatCurrency = true
|
||||
if (totalBookingPoints) {
|
||||
isVatCurrency = false
|
||||
formattedTotalCost = formatPrice(
|
||||
intl,
|
||||
totalBookingPoints,
|
||||
CurrencyEnum.POINTS,
|
||||
totalBookingPrice,
|
||||
currencyCode
|
||||
)
|
||||
}
|
||||
const initialData = {
|
||||
bookingCode,
|
||||
currencyCode,
|
||||
@@ -28,6 +51,9 @@ export default function BookingConfirmationProvider({
|
||||
toDate,
|
||||
rooms,
|
||||
vat,
|
||||
isVatCurrency,
|
||||
formattedTotalCost,
|
||||
totalBookingPrice,
|
||||
}
|
||||
|
||||
storeRef.current = createBookingConfirmationStore(initialData)
|
||||
|
||||
Reference in New Issue
Block a user