From 060f6b6a82196b20baf8806ac8524536963f075a Mon Sep 17 00:00:00 2001 From: Christel Westerberg Date: Tue, 12 Nov 2024 10:09:59 +0100 Subject: [PATCH] fix: breakout selector for enter details in summary --- .../EnterDetails/Summary/index.tsx | 32 +++++++++++-------- stores/enter-details.ts | 2 +- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/components/HotelReservation/EnterDetails/Summary/index.tsx b/components/HotelReservation/EnterDetails/Summary/index.tsx index 72a4dded8..818c54e8c 100644 --- a/components/HotelReservation/EnterDetails/Summary/index.tsx +++ b/components/HotelReservation/EnterDetails/Summary/index.tsx @@ -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, }, }) } diff --git a/stores/enter-details.ts b/stores/enter-details.ts index 0649fd837..374f1dc89 100644 --- a/stores/enter-details.ts +++ b/stores/enter-details.ts @@ -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