fix: calc total price for summary
This commit is contained in:
@@ -21,6 +21,10 @@ import { RoomsData } from "@/types/components/hotelReservation/enterDetails/book
|
||||
import { BreakfastPackage } from "@/types/components/hotelReservation/enterDetails/breakfast"
|
||||
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
|
||||
|
||||
function parsePrice(price: string | undefined) {
|
||||
return price ? parseInt(price) : 0
|
||||
}
|
||||
|
||||
export default function Summary({
|
||||
showMemberPrice,
|
||||
room,
|
||||
@@ -33,8 +37,8 @@ export default function Summary({
|
||||
BreakfastPackage | BreakfastPackageEnum.NO_BREAKFAST
|
||||
>()
|
||||
const [totalPrice, setTotalPrice] = useState({
|
||||
local: parseInt(room.localPrice.price ?? "0"),
|
||||
euro: parseInt(room.euroPrice.price ?? "0"),
|
||||
local: parsePrice(room.localPrice.price),
|
||||
euro: parsePrice(room.euroPrice.price),
|
||||
})
|
||||
const intl = useIntl()
|
||||
const lang = useLang()
|
||||
@@ -64,14 +68,19 @@ export default function Summary({
|
||||
|
||||
if (breakfast) {
|
||||
setChosenBreakfast(breakfast)
|
||||
if (breakfast !== BreakfastPackageEnum.NO_BREAKFAST) {
|
||||
if (breakfast === BreakfastPackageEnum.NO_BREAKFAST) {
|
||||
setTotalPrice({
|
||||
local: parsePrice(room.localPrice.price),
|
||||
euro: parsePrice(room.euroPrice.price),
|
||||
})
|
||||
} else {
|
||||
setTotalPrice({
|
||||
local:
|
||||
parseInt(room.localPrice.price ?? "0") +
|
||||
parseInt(breakfast.localPrice.price ?? "0"),
|
||||
parsePrice(room.localPrice.price) +
|
||||
parsePrice(breakfast.localPrice.totalPrice),
|
||||
euro:
|
||||
parseInt(room.euroPrice.price ?? "0") +
|
||||
parseInt(breakfast.requestedPrice.price ?? "0"),
|
||||
parsePrice(room.euroPrice.price) +
|
||||
parsePrice(breakfast.requestedPrice.totalPrice),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -164,7 +173,7 @@ export default function Summary({
|
||||
{intl.formatMessage(
|
||||
{ id: "{amount} {currency}" },
|
||||
{
|
||||
amount: chosenBreakfast.localPrice.price,
|
||||
amount: chosenBreakfast.localPrice.totalPrice,
|
||||
currency: chosenBreakfast.localPrice.currency,
|
||||
}
|
||||
)}
|
||||
|
||||
2
next-env.d.ts
vendored
2
next-env.d.ts
vendored
@@ -2,4 +2,4 @@
|
||||
/// <reference types="next/image-types/global" />
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
|
||||
// see https://nextjs.org/docs/basic-features/typescript for more information.
|
||||
|
||||
@@ -731,13 +731,11 @@ export const hotelQueryRouter = router({
|
||||
return null
|
||||
}
|
||||
|
||||
const memberRate = selectedRoom.products.find(
|
||||
(rate) => rate.productType.member?.rateCode === rateCode
|
||||
)?.productType.member
|
||||
|
||||
const publicRate = selectedRoom.products.find(
|
||||
(rate) => rate.productType.public?.rateCode === rateCode
|
||||
)?.productType.public
|
||||
const rateTypes = selectedRoom.products.find(
|
||||
(rate) =>
|
||||
rate.productType.public?.rateCode === rateCode ||
|
||||
rate.productType.member?.rateCode === rateCode
|
||||
)?.productType
|
||||
|
||||
const mustBeGuaranteed =
|
||||
validateAvailabilityData.data.rateDefinitions.filter(
|
||||
@@ -787,8 +785,8 @@ export const hotelQueryRouter = router({
|
||||
selectedRoom,
|
||||
mustBeGuaranteed,
|
||||
cancellationText,
|
||||
memberRate,
|
||||
publicRate,
|
||||
memberRate: rateTypes?.member,
|
||||
publicRate: rateTypes?.public,
|
||||
bedTypes,
|
||||
}
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user