fix: breakout selector for enter details in summary
This commit is contained in:
@@ -5,7 +5,7 @@ import { ChevronDown } from "react-feather"
|
|||||||
import { useIntl } from "react-intl"
|
import { useIntl } from "react-intl"
|
||||||
|
|
||||||
import { dt } from "@/lib/dt"
|
import { dt } from "@/lib/dt"
|
||||||
import { useEnterDetailsStore } from "@/stores/enter-details"
|
import { EnterDetailsState, useEnterDetailsStore } from "@/stores/enter-details"
|
||||||
|
|
||||||
import { ArrowRightIcon } from "@/components/Icons"
|
import { ArrowRightIcon } from "@/components/Icons"
|
||||||
import Button from "@/components/TempDesignSystem/Button"
|
import Button from "@/components/TempDesignSystem/Button"
|
||||||
@@ -23,6 +23,18 @@ 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 storeSelector(state: EnterDetailsState) {
|
||||||
|
return {
|
||||||
|
fromDate: state.roomData.fromDate,
|
||||||
|
toDate: state.roomData.toDate,
|
||||||
|
bedType: state.userData.bedType,
|
||||||
|
breakfast: state.userData.breakfast,
|
||||||
|
toggleSummaryOpen: state.toggleSummaryOpen,
|
||||||
|
setTotalPrice: state.setTotalPrice,
|
||||||
|
totalPrice: state.totalPrice,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function parsePrice(price: string | undefined) {
|
function parsePrice(price: string | undefined) {
|
||||||
return price ? parseInt(price) : 0
|
return price ? parseInt(price) : 0
|
||||||
}
|
}
|
||||||
@@ -48,15 +60,7 @@ export default function Summary({
|
|||||||
setTotalPrice,
|
setTotalPrice,
|
||||||
totalPrice,
|
totalPrice,
|
||||||
toggleSummaryOpen,
|
toggleSummaryOpen,
|
||||||
} = useEnterDetailsStore((state) => ({
|
} = useEnterDetailsStore(storeSelector)
|
||||||
fromDate: state.roomData.fromDate,
|
|
||||||
toDate: state.roomData.toDate,
|
|
||||||
bedType: state.userData.bedType,
|
|
||||||
breakfast: state.userData.breakfast,
|
|
||||||
toggleSummaryOpen: state.toggleSummaryOpen,
|
|
||||||
setTotalPrice: state.setTotalPrice,
|
|
||||||
totalPrice: state.totalPrice,
|
|
||||||
}))
|
|
||||||
|
|
||||||
const diff = dt(toDate).diff(fromDate, "days")
|
const diff = dt(toDate).diff(fromDate, "days")
|
||||||
|
|
||||||
@@ -79,11 +83,11 @@ export default function Summary({
|
|||||||
setTotalPrice({
|
setTotalPrice({
|
||||||
local: {
|
local: {
|
||||||
price: parsePrice(room.localPrice.price),
|
price: parsePrice(room.localPrice.price),
|
||||||
currency: room.localPrice.currency!,
|
currency: room.localPrice.currency,
|
||||||
},
|
},
|
||||||
euro: {
|
euro: {
|
||||||
price: parsePrice(room.euroPrice.price),
|
price: parsePrice(room.euroPrice.price),
|
||||||
currency: room.euroPrice.currency!,
|
currency: room.euroPrice.currency,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@@ -92,13 +96,13 @@ export default function Summary({
|
|||||||
price:
|
price:
|
||||||
parsePrice(room.localPrice.price) +
|
parsePrice(room.localPrice.price) +
|
||||||
parsePrice(breakfast.localPrice.totalPrice),
|
parsePrice(breakfast.localPrice.totalPrice),
|
||||||
currency: room.localPrice.currency!,
|
currency: room.localPrice.currency,
|
||||||
},
|
},
|
||||||
euro: {
|
euro: {
|
||||||
price:
|
price:
|
||||||
parsePrice(room.euroPrice.price) +
|
parsePrice(room.euroPrice.price) +
|
||||||
parsePrice(breakfast.requestedPrice.totalPrice),
|
parsePrice(breakfast.requestedPrice.totalPrice),
|
||||||
currency: room.euroPrice.currency!,
|
currency: room.euroPrice.currency,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ type TotalPrice = {
|
|||||||
euro: { price: number; currency: string }
|
euro: { price: number; currency: string }
|
||||||
}
|
}
|
||||||
|
|
||||||
interface EnterDetailsState {
|
export interface EnterDetailsState {
|
||||||
userData: {
|
userData: {
|
||||||
bedType: BedTypeSchema | undefined
|
bedType: BedTypeSchema | undefined
|
||||||
breakfast: BreakfastPackage | BreakfastPackageEnum.NO_BREAKFAST | undefined
|
breakfast: BreakfastPackage | BreakfastPackageEnum.NO_BREAKFAST | undefined
|
||||||
|
|||||||
Reference in New Issue
Block a user