diff --git a/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/index.tsx b/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/index.tsx index b9fb1bce5..beca783d7 100644 --- a/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/index.tsx +++ b/apps/scandic-web/components/HotelReservation/SelectRate/RoomsContainer/index.tsx @@ -4,6 +4,7 @@ import { useSearchParams } from "next/navigation" import { useIntl } from "react-intl" import { trpc } from "@/lib/trpc/client" +import { selectRateRoomsAvailabilityInputSchema } from "@/server/routers/hotels/input" import Alert from "@/components/TempDesignSystem/Alert" import useLang from "@/hooks/useLang" @@ -33,29 +34,32 @@ export function RoomsContainer({ searchParamsToRecord(searchParams) ) - const { data, isFetching, isError, error } = - trpc.hotel.availability.selectRate.rooms.useQuery( - { - booking, - lang, - }, - { - retry(failureCount, error) { - if (error.data?.code === "BAD_REQUEST") { - return false - } + const bookingInput = selectRateRoomsAvailabilityInputSchema.safeParse({ + booking, + lang, + }) - return failureCount <= 3 - }, - } - ) + const { data, isFetching, isError, error } = + trpc.hotel.availability.selectRate.rooms.useQuery(bookingInput.data!, { + retry(failureCount, error) { + if (error.data?.code === "BAD_REQUEST") { + return false + } + + return failureCount <= 3 + }, + enabled: bookingInput.success, + }) if (isFetching) { return } - if (isError) { - const errorMessage = getErrorMessage(error.data?.zodError?.formErrors, intl) + if (isError || !bookingInput.success) { + const errorMessage = getErrorMessage( + error?.data?.zodError?.formErrors, + intl + ) return (
diff --git a/apps/scandic-web/server/routers/hotels/input.ts b/apps/scandic-web/server/routers/hotels/input.ts index f55901f62..3ca849ff8 100644 --- a/apps/scandic-web/server/routers/hotels/input.ts +++ b/apps/scandic-web/server/routers/hotels/input.ts @@ -142,12 +142,7 @@ const baseBookingSchema = z.object({ export const selectRateRoomsAvailabilityInputSchema = z .object({ booking: baseBookingSchema.extend({ - rooms: z.array( - baseRoomSchema.extend({ - rateCode: z.string().optional(), - roomTypeCode: z.string().optional(), - }) - ), + rooms: z.array(baseRoomSchema), }), lang: z.nativeEnum(Lang), }) @@ -196,10 +191,7 @@ export const selectRateRoomsAvailabilityInputSchema = z export const selectRateRoomAvailabilityInputSchema = z.object({ booking: baseBookingSchema.extend({ - room: baseRoomSchema.extend({ - rateCode: z.string().optional(), - roomTypeCode: z.string().optional(), - }), + room: baseRoomSchema, }), lang: z.nativeEnum(Lang), }) diff --git a/apps/scandic-web/server/routers/hotels/query.ts b/apps/scandic-web/server/routers/hotels/query.ts index ecc155b56..d28f0df07 100644 --- a/apps/scandic-web/server/routers/hotels/query.ts +++ b/apps/scandic-web/server/routers/hotels/query.ts @@ -431,10 +431,9 @@ export const hotelQueryRouter = router({ .query(async function ({ ctx, input }) { input.booking.rooms = input.booking.rooms.map((room) => ({ ...room, - bookingCode: room.rateCode - ? room.bookingCode - : input.booking.bookingCode, + bookingCode: room.bookingCode || input.booking.bookingCode, })) + const availability = await getRoomsAvailability( input, ctx.token, diff --git a/apps/scandic-web/server/routers/hotels/utils.ts b/apps/scandic-web/server/routers/hotels/utils.ts index 0a486e0bc..a7e405816 100644 --- a/apps/scandic-web/server/routers/hotels/utils.ts +++ b/apps/scandic-web/server/routers/hotels/utils.ts @@ -1038,9 +1038,6 @@ export async function getRoomsAvailability( headers: { Authorization: `Bearer ${token}`, }, - next: { - revalidate: 60, - }, }, params )