diff --git a/app/[lang]/(live)/(public)/hotelreservation/(standard)/[step]/@summary/page.tsx b/app/[lang]/(live)/(public)/hotelreservation/(standard)/[step]/@summary/page.tsx index 946aea241..ed36a8476 100644 --- a/app/[lang]/(live)/(public)/hotelreservation/(standard)/[step]/@summary/page.tsx +++ b/app/[lang]/(live)/(public)/hotelreservation/(standard)/[step]/@summary/page.tsx @@ -1,5 +1,3 @@ -import { notFound } from "next/navigation" - import { getProfileSafely, getSelectedRoomAvailability, @@ -12,7 +10,6 @@ import { SelectRateSearchParams } from "@/types/components/hotelReservation/sele import { LangParams, PageArgs, SearchParams } from "@/types/params" export default async function SummaryPage({ - params, searchParams, }: PageArgs>) { const selectRoomParams = new URLSearchParams(searchParams) @@ -38,25 +35,25 @@ export default async function SummaryPage({ const prices = user ? { - local: { - price: availability.memberRate?.localPrice.pricePerStay, - currency: availability.memberRate?.localPrice.currency, - }, - euro: { - price: availability.memberRate?.requestedPrice?.pricePerStay, - currency: availability.memberRate?.requestedPrice?.currency, - }, - } + local: { + price: availability.memberRate?.localPrice.pricePerStay, + currency: availability.memberRate?.localPrice.currency, + }, + euro: { + price: availability.memberRate?.requestedPrice?.pricePerStay, + currency: availability.memberRate?.requestedPrice?.currency, + }, + } : { - local: { - price: availability.publicRate?.localPrice.pricePerStay, - currency: availability.publicRate?.localPrice.currency, - }, - euro: { - price: availability.publicRate?.requestedPrice?.pricePerStay, - currency: availability.publicRate?.requestedPrice?.currency, - }, - } + local: { + price: availability.publicRate?.localPrice.pricePerStay, + currency: availability.publicRate?.localPrice.currency, + }, + euro: { + price: availability.publicRate?.requestedPrice?.pricePerStay, + currency: availability.publicRate?.requestedPrice?.currency, + }, + } return ( { - setValue(name, value.phone) - trigger(name) + // If not checked trigger(name) forces validation on mount + // which shows error message before user even can see the form + if (value.inputValue) { + setValue(name, value.phone) + trigger(name) + } else { + setValue(name, "") + } }, }) diff --git a/lib/trpc/memoizedRequests/index.ts b/lib/trpc/memoizedRequests/index.ts index 63cde2d84..d54339801 100644 --- a/lib/trpc/memoizedRequests/index.ts +++ b/lib/trpc/memoizedRequests/index.ts @@ -9,6 +9,8 @@ import { import { serverClient } from "../server" +import type { BreackfastPackagesInput } from "@/types/requests/packages" + export const getLocations = cache(async function getMemoizedLocations() { return serverClient().hotel.locations.get() }) @@ -135,7 +137,7 @@ export const getSiteConfig = cache(async function getMemoizedSiteConfig() { }) export const getBreakfastPackages = cache(async function getMemoizedPackages( - hotelId: string + input: BreackfastPackagesInput ) { - return serverClient().hotel.packages.breakfast({ hotelId }) + return serverClient().hotel.packages.breakfast(input) }) diff --git a/server/routers/hotels/input.ts b/server/routers/hotels/input.ts index bfff4cd97..d4fa1a109 100644 --- a/server/routers/hotels/input.ts +++ b/server/routers/hotels/input.ts @@ -68,6 +68,15 @@ export const getHotelDataInputSchema = z.object({ include: z.array(z.nativeEnum(HotelIncludeEnum)).optional(), }) -export const getBreakfastPackageInput = z.object({ +export const getBreakfastPackageInputSchema = z.object({ + adults: z.number().min(1, { message: "at least one adult is required" }), + fromDate: z + .string() + .min(1, { message: "fromDate is required" }) + .pipe(z.coerce.date()), hotelId: z.string().min(1, { message: "hotelId is required" }), + toDate: z + .string() + .min(1, { message: "toDate is required" }) + .pipe(z.coerce.date()), }) diff --git a/server/routers/hotels/query.ts b/server/routers/hotels/query.ts index b4dc240a5..a8d21ca22 100644 --- a/server/routers/hotels/query.ts +++ b/server/routers/hotels/query.ts @@ -2,6 +2,7 @@ import { metrics } from "@opentelemetry/api" import { Lang } from "@/constants/languages" import * as api from "@/lib/api" +import { dt } from "@/lib/dt" import { GetHotelPage } from "@/lib/graphql/Query/HotelPage/HotelPage.graphql" import { request } from "@/lib/graphql/request" import { @@ -31,7 +32,7 @@ import { getRoomPackagesSchema, } from "./schemas/packages" import { - getBreakfastPackageInput, + getBreakfastPackageInputSchema, getHotelDataInputSchema, getHotelInputSchema, getHotelsAvailabilityInputSchema, @@ -982,14 +983,14 @@ export const hotelQueryRouter = router({ return validatedPackagesData.data }), breakfast: safeProtectedServiceProcedure - .input(getBreakfastPackageInput) + .input(getBreakfastPackageInputSchema) .query(async function ({ ctx, input }) { const params = { - Adults: 2, - EndDate: "2024-10-28", - StartDate: "2024-10-25", + Adults: input.adults, + EndDate: dt(input.toDate).format("YYYY-MM-DD"), + StartDate: dt(input.fromDate).format("YYYY-MM-DD"), } - const metricsData = { ...input, ...params } + const metricsData = { ...params, hotelId: input.hotelId } breakfastPackagesCounter.add(1, metricsData) console.info( "api.package.breakfast start", diff --git a/types/requests/packages.ts b/types/requests/packages.ts new file mode 100644 index 000000000..3d794e0f3 --- /dev/null +++ b/types/requests/packages.ts @@ -0,0 +1,6 @@ +import { z } from "zod" + +import { getBreakfastPackageInputSchema } from "@/server/routers/hotels/input" + +export interface BreackfastPackagesInput + extends z.input {}