From 04df824ea194fbf5555a9bf2959cb429b46618b1 Mon Sep 17 00:00:00 2001 From: Pontus Dreij Date: Mon, 4 Nov 2024 16:09:31 +0100 Subject: [PATCH] feat(697): Made new fields optional --- .../EnterDetails/Breakfast/index.tsx | 8 ++++---- .../HotelReservation/EnterDetails/Summary/index.tsx | 4 ++-- .../FlexibilityOption/PriceList/index.tsx | 4 ++-- .../SelectRate/RoomSelection/RateSummary/index.tsx | 4 ++-- server/routers/hotels/output.ts | 12 +++++++----- server/routers/hotels/query.ts | 7 +++++-- server/routers/hotels/schemas/packages.ts | 12 +++++++----- 7 files changed, 29 insertions(+), 22 deletions(-) diff --git a/components/HotelReservation/EnterDetails/Breakfast/index.tsx b/components/HotelReservation/EnterDetails/Breakfast/index.tsx index 00d5ab4cc..3881340e0 100644 --- a/components/HotelReservation/EnterDetails/Breakfast/index.tsx +++ b/components/HotelReservation/EnterDetails/Breakfast/index.tsx @@ -78,8 +78,8 @@ export default function Breakfast({ packages }: BreakfastProps) { ? intl.formatMessage( { id: "breakfast.price.free" }, { - amount: pkg.localPrice.price, - currency: pkg.localPrice.currency, + amount: pkg.localPrice?.price, + currency: pkg.localPrice?.currency, free: (str) => {str}, strikethrough: (str) => {str}, } @@ -87,8 +87,8 @@ export default function Breakfast({ packages }: BreakfastProps) { : intl.formatMessage( { id: "breakfast.price" }, { - amount: pkg.localPrice.price, - currency: pkg.localPrice.currency, + amount: pkg.localPrice?.price, + currency: pkg.localPrice?.currency, } ) } diff --git a/components/HotelReservation/EnterDetails/Summary/index.tsx b/components/HotelReservation/EnterDetails/Summary/index.tsx index ca2891912..ba42f1d96 100644 --- a/components/HotelReservation/EnterDetails/Summary/index.tsx +++ b/components/HotelReservation/EnterDetails/Summary/index.tsx @@ -150,8 +150,8 @@ export default function Summary({ {intl.formatMessage( { id: "{amount} {currency}" }, { - amount: chosenBreakfast.localPrice.price, - currency: chosenBreakfast.localPrice.currency, + amount: chosenBreakfast.localPrice?.price, + currency: chosenBreakfast.localPrice?.currency, } )} diff --git a/components/HotelReservation/SelectRate/RoomSelection/FlexibilityOption/PriceList/index.tsx b/components/HotelReservation/SelectRate/RoomSelection/FlexibilityOption/PriceList/index.tsx index 6ec68426f..6cb1c647b 100644 --- a/components/HotelReservation/SelectRate/RoomSelection/FlexibilityOption/PriceList/index.tsx +++ b/components/HotelReservation/SelectRate/RoomSelection/FlexibilityOption/PriceList/index.tsx @@ -1,4 +1,5 @@ import { differenceInCalendarDays } from "date-fns" +import { useSearchParams } from "next/navigation" import { useIntl } from "react-intl" import Body from "@/components/TempDesignSystem/Text/Body" @@ -27,8 +28,7 @@ export default function PriceList({ const petRoomRequestedPrice = petRoomPackage?.requestedPrice const showRequestedPrice = publicRequestedPrice && memberRequestedPrice - - const searchParams = new URLSearchParams(window.location.search) + const searchParams = useSearchParams() const fromDate = searchParams.get("fromDate") const toDate = searchParams.get("toDate") diff --git a/components/HotelReservation/SelectRate/RoomSelection/RateSummary/index.tsx b/components/HotelReservation/SelectRate/RoomSelection/RateSummary/index.tsx index 9f2dc4a4f..9db162ec5 100644 --- a/components/HotelReservation/SelectRate/RoomSelection/RateSummary/index.tsx +++ b/components/HotelReservation/SelectRate/RoomSelection/RateSummary/index.tsx @@ -36,8 +36,8 @@ export default function RateSummary({ (pkg) => pkg.code === RoomPackageCodeEnum.PET_ROOM ) - const petRoomPrice = petRoomPackage?.localPrice.totalPrice ?? null - const petRoomCurrency = petRoomPackage?.localPrice.currency ?? null + const petRoomPrice = petRoomPackage?.localPrice?.totalPrice ?? null + const petRoomCurrency = petRoomPackage?.localPrice?.currency ?? null const checkInDate = new Date(roomsAvailability.checkInDate) const checkOutDate = new Date(roomsAvailability.checkOutDate) diff --git a/server/routers/hotels/output.ts b/server/routers/hotels/output.ts index dad7abe49..aed677b57 100644 --- a/server/routers/hotels/output.ts +++ b/server/routers/hotels/output.ts @@ -774,11 +774,13 @@ export const apiLocationsSchema = z.object({ ), }) -const breakfastPackagePriceSchema = z.object({ - currency: z.nativeEnum(CurrencyEnum), - price: z.string(), - totalPrice: z.string(), -}) +const breakfastPackagePriceSchema = z + .object({ + currency: z.nativeEnum(CurrencyEnum), + price: z.string(), + totalPrice: z.string(), + }) + .optional() // TODO: Remove optional when the API change has been deployed export const breakfastPackageSchema = z.object({ code: z.string(), diff --git a/server/routers/hotels/query.ts b/server/routers/hotels/query.ts index f282840da..a9b382bd0 100644 --- a/server/routers/hotels/query.ts +++ b/server/routers/hotels/query.ts @@ -1095,8 +1095,11 @@ export const hotelQueryRouter = router({ const freeBreakfastPackage = breakfastPackages.data.find( (pkg) => pkg.code === BreakfastPackageEnum.FREE_MEMBER_BREAKFAST ) - if (freeBreakfastPackage) { - if (originalBreakfastPackage) { + if (freeBreakfastPackage && freeBreakfastPackage.localPrice) { + if ( + originalBreakfastPackage && + originalBreakfastPackage.localPrice + ) { freeBreakfastPackage.localPrice.price = originalBreakfastPackage.localPrice.price } diff --git a/server/routers/hotels/schemas/packages.ts b/server/routers/hotels/schemas/packages.ts index 9de3c0574..b4ff7d57e 100644 --- a/server/routers/hotels/schemas/packages.ts +++ b/server/routers/hotels/schemas/packages.ts @@ -11,11 +11,13 @@ export const getRoomPackagesInputSchema = z.object({ packageCodes: z.array(z.string()).optional().default([]), }) -export const packagePriceSchema = z.object({ - currency: z.string(), - price: z.string(), - totalPrice: z.string(), -}) +export const packagePriceSchema = z + .object({ + currency: z.string(), + price: z.string(), + totalPrice: z.string(), + }) + .optional() // TODO: Remove optional when the API change has been deployed export const packagesSchema = z.object({ code: z.nativeEnum(RoomPackageCodeEnum),