fix: summarize prices
This commit is contained in:
@@ -22,16 +22,20 @@ import { BreakfastPackage } from "@/types/components/hotelReservation/enterDetai
|
||||
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
|
||||
|
||||
export default function Summary({
|
||||
isMember,
|
||||
showMemberPrice,
|
||||
room,
|
||||
}: {
|
||||
isMember: boolean
|
||||
showMemberPrice: boolean
|
||||
room: RoomsData
|
||||
}) {
|
||||
const [chosenBed, setChosenBed] = useState<string>()
|
||||
const [chosenBreakfast, setChosenBreakfast] = useState<
|
||||
BreakfastPackage | BreakfastPackageEnum.NO_BREAKFAST
|
||||
>()
|
||||
const [totalPrice, setTotalPrice] = useState({
|
||||
local: parseInt(room.localPrice.price ?? "0"),
|
||||
euro: parseInt(room.euroPrice.price ?? "0"),
|
||||
})
|
||||
const intl = useIntl()
|
||||
const lang = useLang()
|
||||
const { fromDate, toDate, bedType, breakfast } = useEnterDetailsStore(
|
||||
@@ -51,7 +55,7 @@ export default function Summary({
|
||||
)
|
||||
|
||||
let color: "uiTextHighContrast" | "red" = "uiTextHighContrast"
|
||||
if (isMember) {
|
||||
if (showMemberPrice) {
|
||||
color = "red"
|
||||
}
|
||||
|
||||
@@ -60,8 +64,18 @@ export default function Summary({
|
||||
|
||||
if (breakfast) {
|
||||
setChosenBreakfast(breakfast)
|
||||
if (breakfast !== BreakfastPackageEnum.NO_BREAKFAST) {
|
||||
setTotalPrice({
|
||||
local:
|
||||
parseInt(room.localPrice.price ?? "0") +
|
||||
parseInt(breakfast.localPrice.price ?? "0"),
|
||||
euro:
|
||||
parseInt(room.euroPrice.price ?? "0") +
|
||||
parseInt(breakfast.requestedPrice.price ?? "0"),
|
||||
})
|
||||
}
|
||||
}
|
||||
}, [bedType, breakfast])
|
||||
}, [bedType, breakfast, room.localPrice, room.euroPrice])
|
||||
|
||||
return (
|
||||
<section className={styles.summary}>
|
||||
@@ -178,7 +192,7 @@ export default function Summary({
|
||||
{intl.formatMessage(
|
||||
{ id: "{amount} {currency}" },
|
||||
{
|
||||
amount: formatNumber(parseInt(room.localPrice.price ?? "0")),
|
||||
amount: formatNumber(totalPrice.local),
|
||||
currency: room.localPrice.currency,
|
||||
}
|
||||
)}
|
||||
@@ -188,7 +202,7 @@ export default function Summary({
|
||||
{intl.formatMessage(
|
||||
{ id: "{amount} {currency}" },
|
||||
{
|
||||
amount: formatNumber(parseInt(room.euroPrice.price ?? "0")),
|
||||
amount: formatNumber(totalPrice.euro),
|
||||
currency: room.euroPrice.currency,
|
||||
}
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user