From 421021885242d52a108c2a960561f3003b393cf5 Mon Sep 17 00:00:00 2001 From: Christel Westerberg Date: Wed, 4 Dec 2024 16:16:32 +0100 Subject: [PATCH] fix: persist selection of bed and breakfast if same room --- .../EnterDetails/BedType/index.tsx | 8 +- .../EnterDetails/Breakfast/index.tsx | 17 +- .../EnterDetails/Details/index.tsx | 5 +- .../Payment/PaymentCallback/index.tsx | 9 +- .../Form/ChoiceCard/_Card/card.ts | 1 - .../Form/ChoiceCard/_Card/index.tsx | 7 +- providers/EnterDetailsProvider.tsx | 95 ++- server/routers/hotels/query.ts | 8 +- stores/enter-details/helpers.ts | 54 +- stores/enter-details/index.ts | 634 +++++++----------- types/stores/enter-details.ts | 11 + 11 files changed, 410 insertions(+), 439 deletions(-) diff --git a/components/HotelReservation/EnterDetails/BedType/index.tsx b/components/HotelReservation/EnterDetails/BedType/index.tsx index 0b5dca2aa..4f89eb2f0 100644 --- a/components/HotelReservation/EnterDetails/BedType/index.tsx +++ b/components/HotelReservation/EnterDetails/BedType/index.tsx @@ -22,10 +22,7 @@ export default function BedType({ bedTypes }: BedTypeProps) { const initialBedType = useEnterDetailsStore( (state) => state.formValues?.bedType?.roomTypeCode ) - const bedType = useEnterDetailsStore((state) => state.bedType?.roomTypeCode) - const completeStep = useEnterDetailsStore( - (state) => state.actions.completeStep - ) + const updateBedType = useEnterDetailsStore( (state) => state.actions.updateBedType ) @@ -81,9 +78,6 @@ export default function BedType({ bedTypes }: BedTypeProps) { subtitle={width} title={roomType.description} value={roomType.value} - handleSelectedOnClick={ - bedType === roomType.value ? completeStep : undefined - } /> ) })} diff --git a/components/HotelReservation/EnterDetails/Breakfast/index.tsx b/components/HotelReservation/EnterDetails/Breakfast/index.tsx index bae37071c..f413b841d 100644 --- a/components/HotelReservation/EnterDetails/Breakfast/index.tsx +++ b/components/HotelReservation/EnterDetails/Breakfast/index.tsx @@ -31,16 +31,7 @@ export default function Breakfast({ packages }: BreakfastProps) { ? "false" : undefined ) - const breakfast = useEnterDetailsStore((state) => - state.breakfast - ? state.breakfast.code - : state.breakfast === false - ? "false" - : undefined - ) - const completeStep = useEnterDetailsStore( - (state) => state.actions.completeStep - ) + const updateBreakfast = useEnterDetailsStore( (state) => state.actions.updateBreakfast ) @@ -119,9 +110,6 @@ export default function Breakfast({ packages }: BreakfastProps) { })} title={intl.formatMessage({ id: "Breakfast buffet" })} value={pkg.code} - handleSelectedOnClick={ - breakfast === pkg.code ? completeStep : undefined - } /> ))} diff --git a/components/HotelReservation/EnterDetails/Details/index.tsx b/components/HotelReservation/EnterDetails/Details/index.tsx index 2aef91185..4dc55859c 100644 --- a/components/HotelReservation/EnterDetails/Details/index.tsx +++ b/components/HotelReservation/EnterDetails/Details/index.tsx @@ -26,8 +26,7 @@ import type { const formID = "enter-details" export default function Details({ user, memberPrice }: DetailsProps) { const intl = useIntl() - const initialData = useEnterDetailsStore((state) => state.formValues.guest) - const join = useEnterDetailsStore((state) => state.guest.join) + const initialData = useEnterDetailsStore((state) => state.guest) const updateDetails = useEnterDetailsStore( (state) => state.actions.updateDetails ) @@ -42,7 +41,7 @@ export default function Details({ user, memberPrice }: DetailsProps) { dateOfBirth: initialData.dateOfBirth, email: user?.email ?? initialData.email, firstName: user?.firstName ?? initialData.firstName, - join, + join: initialData.join, lastName: user?.lastName ?? initialData.lastName, membershipNo: initialData.membershipNo, phoneNumber: user?.phoneNumber ?? initialData.phoneNumber, diff --git a/components/HotelReservation/EnterDetails/Payment/PaymentCallback/index.tsx b/components/HotelReservation/EnterDetails/Payment/PaymentCallback/index.tsx index 2ad17ac12..8fd613d5e 100644 --- a/components/HotelReservation/EnterDetails/Payment/PaymentCallback/index.tsx +++ b/components/HotelReservation/EnterDetails/Payment/PaymentCallback/index.tsx @@ -8,7 +8,7 @@ import { detailsStorageName } from "@/stores/enter-details" import { createQueryParamsForEnterDetails } from "@/components/HotelReservation/SelectRate/RoomSelection/utils" import LoadingSpinner from "@/components/LoadingSpinner" -import type { DetailsState } from "@/types/stores/enter-details" +import type { PersistedState } from "@/types/stores/enter-details" export default function PaymentCallback({ returnUrl, @@ -23,12 +23,9 @@ export default function PaymentCallback({ const bookingData = window.sessionStorage.getItem(detailsStorageName) if (bookingData) { - const detailsStorage: Record< - "state", - Pick - > = JSON.parse(bookingData) + const detailsStorage: PersistedState = JSON.parse(bookingData) const searchParams = createQueryParamsForEnterDetails( - detailsStorage.state.booking, + detailsStorage.booking, searchObject ) diff --git a/components/TempDesignSystem/Form/ChoiceCard/_Card/card.ts b/components/TempDesignSystem/Form/ChoiceCard/_Card/card.ts index c733dac50..7d24e46d7 100644 --- a/components/TempDesignSystem/Form/ChoiceCard/_Card/card.ts +++ b/components/TempDesignSystem/Form/ChoiceCard/_Card/card.ts @@ -12,7 +12,6 @@ interface BaseCardProps title: React.ReactNode type: "checkbox" | "radio" value?: string - handleSelectedOnClick?: () => void } interface ListCardProps extends BaseCardProps { diff --git a/components/TempDesignSystem/Form/ChoiceCard/_Card/index.tsx b/components/TempDesignSystem/Form/ChoiceCard/_Card/index.tsx index 013f1a373..6c604f725 100644 --- a/components/TempDesignSystem/Form/ChoiceCard/_Card/index.tsx +++ b/components/TempDesignSystem/Form/ChoiceCard/_Card/index.tsx @@ -24,21 +24,20 @@ export default function Card({ title, type, value, - handleSelectedOnClick, }: CardProps) { - const { register } = useFormContext() + const { register, setValue } = useFormContext() function onLabelClick(event: React.MouseEvent) { // Preventing click event on label elements firing twice: https://github.com/facebook/react/issues/14295 event.preventDefault() - handleSelectedOnClick?.() + setValue(name, value) } return (