From 6ca56f3138ebd3dc343a0f6439635102e70749ac Mon Sep 17 00:00:00 2001 From: Tobias Johansson Date: Wed, 8 Jan 2025 12:34:20 +0000 Subject: [PATCH] Merged in feat/SW-822-handle-breakfast-included (pull request #1138) Feat/SW-822 handle breakfast included * feat(SW-822): Added flag for breakfast included and hide breakfast step if included * fix: check if window is defined to avoid error during SSR * fix: remove return if rate definition is not found because its expected if input is undefined Approved-by: Christel Westerberg Approved-by: Arvid Norlin --- .../hotelreservation/(standard)/step/page.tsx | 13 ++++-- .../EnterDetails/Summary/UI/index.tsx | 9 ++++- providers/EnterDetailsProvider.tsx | 4 +- server/routers/hotels/query.ts | 40 ++++++++++++------- types/components/hotelReservation/summary.ts | 1 + types/providers/enter-details.ts | 2 +- utils/tracking.ts | 7 +++- 7 files changed, 52 insertions(+), 24 deletions(-) diff --git a/app/[lang]/(live)/(public)/hotelreservation/(standard)/step/page.tsx b/app/[lang]/(live)/(public)/hotelreservation/(standard)/step/page.tsx index 27d570042..075e79766 100644 --- a/app/[lang]/(live)/(public)/hotelreservation/(standard)/step/page.tsx +++ b/app/[lang]/(live)/(public)/hotelreservation/(standard)/step/page.tsx @@ -126,7 +126,7 @@ export default async function StepPage({ return notFound() } - const mustBeGuaranteed = roomAvailability?.mustBeGuaranteed ?? false + const { mustBeGuaranteed, breakfastIncluded } = roomAvailability const paymentGuarantee = intl.formatMessage({ id: "Payment Guarantee", @@ -191,13 +191,18 @@ export default async function StepPage({ isMember: !!user, rateDetails: roomAvailability.rateDetails, roomType: roomAvailability.selectedRoom.roomType, + breakfastIncluded, } + const showBreakfastStep = Boolean( + breakfastPackages?.length && !breakfastIncluded + ) + return ( ) : null} - {breakfastPackages?.length ? ( + {showBreakfastStep ? ( - + ) : null} diff --git a/components/HotelReservation/EnterDetails/Summary/UI/index.tsx b/components/HotelReservation/EnterDetails/Summary/UI/index.tsx index d61563fdd..d828f6c55 100644 --- a/components/HotelReservation/EnterDetails/Summary/UI/index.tsx +++ b/components/HotelReservation/EnterDetails/Summary/UI/index.tsx @@ -51,6 +51,7 @@ export default function SummaryUI({ isMember, rateDetails, roomType, + breakfastIncluded, }: SummaryProps) { const intl = useIntl() const lang = useLang() @@ -242,7 +243,13 @@ export default function SummaryUI({ ) : null} - {breakfast === false ? ( + {breakfastIncluded ? ( +
+ + {intl.formatMessage({ id: "Breakfast included" })} + +
+ ) : breakfast === false ? (
{intl.formatMessage({ id: "No breakfast" })} diff --git a/providers/EnterDetailsProvider.tsx b/providers/EnterDetailsProvider.tsx index 547130e7e..826116eb3 100644 --- a/providers/EnterDetailsProvider.tsx +++ b/providers/EnterDetailsProvider.tsx @@ -25,7 +25,7 @@ import type { DetailsState, InitialState } from "@/types/stores/enter-details" export default function EnterDetailsProvider({ bedTypes, booking, - breakfastPackages, + showBreakfastStep, children, packages, roomRate, @@ -44,7 +44,7 @@ export default function EnterDetailsProvider({ roomTypeCode: bedTypes[0].value, } } - if (!breakfastPackages?.length) { + if (!showBreakfastStep) { initialData.breakfast = false } diff --git a/server/routers/hotels/query.ts b/server/routers/hotels/query.ts index 86d615ebd..e17f1a51f 100644 --- a/server/routers/hotels/query.ts +++ b/server/routers/hotels/query.ts @@ -554,14 +554,20 @@ export const hotelQueryRouter = router({ (room) => room.roomType === selectedRoom?.roomType ) if (!selectedRoom) { + selectedRoomAvailabilityFailCounter.add(1, { + hotelId, + roomStayStartDate, + roomStayEndDate, + adults, + children, + bookingCode, + error_type: "not_found", + error: `Couldn't find selected room with input: ${roomTypeCode}`, + }) console.error("No matching room found") return null } - const rateDetails = validateAvailabilityData.data.rateDefinitions.find( - (rateDef) => rateDef.rateCode === rateCode - )?.generalTerms - const rateTypes = selectedRoom.products.find( (rate) => rate.productType.public?.rateCode === rateCode || @@ -569,20 +575,25 @@ export const hotelQueryRouter = router({ ) if (!rateTypes) { + selectedRoomAvailabilityFailCounter.add(1, { + hotelId, + roomStayStartDate, + roomStayEndDate, + adults, + children, + bookingCode, + error_type: "not_found", + error: `Couldn't find rateTypes for selected room: ${JSON.stringify(selectedRoom)}`, + }) console.error("No matching rate found") return null } const rates = rateTypes.productType - const mustBeGuaranteed = - validateAvailabilityData.data.rateDefinitions.filter( - (rate) => rate.rateCode === rateCode - )[0].mustBeGuaranteed - - const cancellationText = + const rateDefinition = validateAvailabilityData.data.rateDefinitions.find( (rate) => rate.rateCode === rateCode - )?.cancellationText ?? "" + ) const bedTypes = availableRoomsInCategory .map((availRoom) => { @@ -623,9 +634,10 @@ export const hotelQueryRouter = router({ return { selectedRoom, - rateDetails, - mustBeGuaranteed, - cancellationText, + rateDetails: rateDefinition?.generalTerms, + cancellationText: rateDefinition?.cancellationText ?? "", + mustBeGuaranteed: !!rateDefinition?.mustBeGuaranteed, + breakfastIncluded: !!rateDefinition?.breakfastIncluded, memberRate: rates?.member, publicRate: rates.public, bedTypes, diff --git a/types/components/hotelReservation/summary.ts b/types/components/hotelReservation/summary.ts index e705f3751..50fd2ed66 100644 --- a/types/components/hotelReservation/summary.ts +++ b/types/components/hotelReservation/summary.ts @@ -15,4 +15,5 @@ export interface SummaryProps extends Pick, Pick { isMember: boolean + breakfastIncluded: boolean } diff --git a/types/providers/enter-details.ts b/types/providers/enter-details.ts index 0862abb4d..0659d77ed 100644 --- a/types/providers/enter-details.ts +++ b/types/providers/enter-details.ts @@ -9,7 +9,7 @@ import type { Packages } from "../requests/packages" export interface DetailsProviderProps extends React.PropsWithChildren { booking: BookingData bedTypes: BedTypeSelection[] - breakfastPackages: BreakfastPackage[] | null + showBreakfastStep: boolean packages: Packages | null roomRate: Pick searchParamsStr: string diff --git a/utils/tracking.ts b/utils/tracking.ts index 53da7d744..59b7dd965 100644 --- a/utils/tracking.ts +++ b/utils/tracking.ts @@ -1,4 +1,7 @@ -import type { TrackingPosition, TrackingSDKData } from "@/types/components/tracking" +import type { + TrackingPosition, + TrackingSDKData, +} from "@/types/components/tracking" export function trackClick(name: string) { pushToDataLayer({ @@ -60,7 +63,7 @@ export function createSDKPageObject( return { ...trackingData, - domain: window.location.host, + domain: typeof window !== "undefined" ? window.location.host : "", pageName: pageName, siteSections: siteSections, }