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