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 { BreakfastPackage } from "@/types/components/hotelReservation/enterDetails/breakfast"
|
||||||
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
|
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
|
||||||
|
|
||||||
|
function parsePrice(price: string | undefined) {
|
||||||
|
return price ? parseInt(price) : 0
|
||||||
|
}
|
||||||
|
|
||||||
export default function Summary({
|
export default function Summary({
|
||||||
showMemberPrice,
|
showMemberPrice,
|
||||||
room,
|
room,
|
||||||
@@ -33,8 +37,8 @@ export default function Summary({
|
|||||||
BreakfastPackage | BreakfastPackageEnum.NO_BREAKFAST
|
BreakfastPackage | BreakfastPackageEnum.NO_BREAKFAST
|
||||||
>()
|
>()
|
||||||
const [totalPrice, setTotalPrice] = useState({
|
const [totalPrice, setTotalPrice] = useState({
|
||||||
local: parseInt(room.localPrice.price ?? "0"),
|
local: parsePrice(room.localPrice.price),
|
||||||
euro: parseInt(room.euroPrice.price ?? "0"),
|
euro: parsePrice(room.euroPrice.price),
|
||||||
})
|
})
|
||||||
const intl = useIntl()
|
const intl = useIntl()
|
||||||
const lang = useLang()
|
const lang = useLang()
|
||||||
@@ -64,14 +68,19 @@ export default function Summary({
|
|||||||
|
|
||||||
if (breakfast) {
|
if (breakfast) {
|
||||||
setChosenBreakfast(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({
|
setTotalPrice({
|
||||||
local:
|
local:
|
||||||
parseInt(room.localPrice.price ?? "0") +
|
parsePrice(room.localPrice.price) +
|
||||||
parseInt(breakfast.localPrice.price ?? "0"),
|
parsePrice(breakfast.localPrice.totalPrice),
|
||||||
euro:
|
euro:
|
||||||
parseInt(room.euroPrice.price ?? "0") +
|
parsePrice(room.euroPrice.price) +
|
||||||
parseInt(breakfast.requestedPrice.price ?? "0"),
|
parsePrice(breakfast.requestedPrice.totalPrice),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,7 +173,7 @@ export default function Summary({
|
|||||||
{intl.formatMessage(
|
{intl.formatMessage(
|
||||||
{ id: "{amount} {currency}" },
|
{ id: "{amount} {currency}" },
|
||||||
{
|
{
|
||||||
amount: chosenBreakfast.localPrice.price,
|
amount: chosenBreakfast.localPrice.totalPrice,
|
||||||
currency: chosenBreakfast.localPrice.currency,
|
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" />
|
/// <reference types="next/image-types/global" />
|
||||||
|
|
||||||
// NOTE: This file should not be edited
|
// 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
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const memberRate = selectedRoom.products.find(
|
const rateTypes = selectedRoom.products.find(
|
||||||
(rate) => rate.productType.member?.rateCode === rateCode
|
(rate) =>
|
||||||
)?.productType.member
|
rate.productType.public?.rateCode === rateCode ||
|
||||||
|
rate.productType.member?.rateCode === rateCode
|
||||||
const publicRate = selectedRoom.products.find(
|
)?.productType
|
||||||
(rate) => rate.productType.public?.rateCode === rateCode
|
|
||||||
)?.productType.public
|
|
||||||
|
|
||||||
const mustBeGuaranteed =
|
const mustBeGuaranteed =
|
||||||
validateAvailabilityData.data.rateDefinitions.filter(
|
validateAvailabilityData.data.rateDefinitions.filter(
|
||||||
@@ -787,8 +785,8 @@ export const hotelQueryRouter = router({
|
|||||||
selectedRoom,
|
selectedRoom,
|
||||||
mustBeGuaranteed,
|
mustBeGuaranteed,
|
||||||
cancellationText,
|
cancellationText,
|
||||||
memberRate,
|
memberRate: rateTypes?.member,
|
||||||
publicRate,
|
publicRate: rateTypes?.public,
|
||||||
bedTypes,
|
bedTypes,
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user