fix: breakout selector for enter details in summary

This commit is contained in:
Christel Westerberg
2024-11-12 10:09:59 +01:00
parent 32d12bae58
commit 060f6b6a82
2 changed files with 19 additions and 15 deletions

View File

@@ -5,7 +5,7 @@ import { ChevronDown } from "react-feather"
import { useIntl } from "react-intl"
import { dt } from "@/lib/dt"
import { useEnterDetailsStore } from "@/stores/enter-details"
import { EnterDetailsState, useEnterDetailsStore } from "@/stores/enter-details"
import { ArrowRightIcon } from "@/components/Icons"
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 { 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) {
return price ? parseInt(price) : 0
}
@@ -48,15 +60,7 @@ export default function Summary({
setTotalPrice,
totalPrice,
toggleSummaryOpen,
} = useEnterDetailsStore((state) => ({
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,
}))
} = useEnterDetailsStore(storeSelector)
const diff = dt(toDate).diff(fromDate, "days")
@@ -79,11 +83,11 @@ export default function Summary({
setTotalPrice({
local: {
price: parsePrice(room.localPrice.price),
currency: room.localPrice.currency!,
currency: room.localPrice.currency,
},
euro: {
price: parsePrice(room.euroPrice.price),
currency: room.euroPrice.currency!,
currency: room.euroPrice.currency,
},
})
} else {
@@ -92,13 +96,13 @@ export default function Summary({
price:
parsePrice(room.localPrice.price) +
parsePrice(breakfast.localPrice.totalPrice),
currency: room.localPrice.currency!,
currency: room.localPrice.currency,
},
euro: {
price:
parsePrice(room.euroPrice.price) +
parsePrice(breakfast.requestedPrice.totalPrice),
currency: room.euroPrice.currency!,
currency: room.euroPrice.currency,
},
})
}

View File

@@ -28,7 +28,7 @@ type TotalPrice = {
euro: { price: number; currency: string }
}
interface EnterDetailsState {
export interface EnterDetailsState {
userData: {
bedType: BedTypeSchema | undefined
breakfast: BreakfastPackage | BreakfastPackageEnum.NO_BREAKFAST | undefined