fix: prevent phone input from running validation on mount when empty
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
import { notFound } from "next/navigation"
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getProfileSafely,
|
getProfileSafely,
|
||||||
getSelectedRoomAvailability,
|
getSelectedRoomAvailability,
|
||||||
@@ -12,7 +10,6 @@ import { SelectRateSearchParams } from "@/types/components/hotelReservation/sele
|
|||||||
import { LangParams, PageArgs, SearchParams } from "@/types/params"
|
import { LangParams, PageArgs, SearchParams } from "@/types/params"
|
||||||
|
|
||||||
export default async function SummaryPage({
|
export default async function SummaryPage({
|
||||||
params,
|
|
||||||
searchParams,
|
searchParams,
|
||||||
}: PageArgs<LangParams, SearchParams<SelectRateSearchParams>>) {
|
}: PageArgs<LangParams, SearchParams<SelectRateSearchParams>>) {
|
||||||
const selectRoomParams = new URLSearchParams(searchParams)
|
const selectRoomParams = new URLSearchParams(searchParams)
|
||||||
|
|||||||
@@ -49,7 +49,8 @@ export default async function StepPage({
|
|||||||
toDate,
|
toDate,
|
||||||
} = getQueryParamsForEnterDetails(selectRoomParams)
|
} = getQueryParamsForEnterDetails(selectRoomParams)
|
||||||
|
|
||||||
void getBreakfastPackages(searchParams.hotel)
|
const breakfastInput = { adults, fromDate, hotelId, toDate }
|
||||||
|
void getBreakfastPackages(breakfastInput)
|
||||||
void getSelectedRoomAvailability({
|
void getSelectedRoomAvailability({
|
||||||
hotelId: parseInt(searchParams.hotel),
|
hotelId: parseInt(searchParams.hotel),
|
||||||
adults,
|
adults,
|
||||||
@@ -74,7 +75,7 @@ export default async function StepPage({
|
|||||||
rateCode,
|
rateCode,
|
||||||
roomTypeCode,
|
roomTypeCode,
|
||||||
})
|
})
|
||||||
const breakfastPackages = await getBreakfastPackages(searchParams.hotel)
|
const breakfastPackages = await getBreakfastPackages(breakfastInput)
|
||||||
const user = await getProfileSafely()
|
const user = await getProfileSafely()
|
||||||
const savedCreditCards = await getCreditCardsSafely()
|
const savedCreditCards = await getCreditCardsSafely()
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import CountrySelect from "@/components/TempDesignSystem/Form/Country"
|
|||||||
import Input from "@/components/TempDesignSystem/Form/Input"
|
import Input from "@/components/TempDesignSystem/Form/Input"
|
||||||
import Phone from "@/components/TempDesignSystem/Form/Phone"
|
import Phone from "@/components/TempDesignSystem/Form/Phone"
|
||||||
import Body from "@/components/TempDesignSystem/Text/Body"
|
import Body from "@/components/TempDesignSystem/Text/Body"
|
||||||
import { toast } from "@/components/TempDesignSystem/Toasts"
|
|
||||||
|
|
||||||
import { detailsSchema, signedInDetailsSchema } from "./schema"
|
import { detailsSchema, signedInDetailsSchema } from "./schema"
|
||||||
import Signup from "./Signup"
|
import Signup from "./Signup"
|
||||||
|
|||||||
@@ -58,8 +58,14 @@ export default function Phone({
|
|||||||
forceDialCode: true,
|
forceDialCode: true,
|
||||||
value: phone,
|
value: phone,
|
||||||
onChange: (value) => {
|
onChange: (value) => {
|
||||||
|
// 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)
|
setValue(name, value.phone)
|
||||||
trigger(name)
|
trigger(name)
|
||||||
|
} else {
|
||||||
|
setValue(name, "")
|
||||||
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import {
|
|||||||
|
|
||||||
import { serverClient } from "../server"
|
import { serverClient } from "../server"
|
||||||
|
|
||||||
|
import type { BreackfastPackagesInput } from "@/types/requests/packages"
|
||||||
|
|
||||||
export const getLocations = cache(async function getMemoizedLocations() {
|
export const getLocations = cache(async function getMemoizedLocations() {
|
||||||
return serverClient().hotel.locations.get()
|
return serverClient().hotel.locations.get()
|
||||||
})
|
})
|
||||||
@@ -135,7 +137,7 @@ export const getSiteConfig = cache(async function getMemoizedSiteConfig() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
export const getBreakfastPackages = cache(async function getMemoizedPackages(
|
export const getBreakfastPackages = cache(async function getMemoizedPackages(
|
||||||
hotelId: string
|
input: BreackfastPackagesInput
|
||||||
) {
|
) {
|
||||||
return serverClient().hotel.packages.breakfast({ hotelId })
|
return serverClient().hotel.packages.breakfast(input)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -68,6 +68,15 @@ export const getHotelDataInputSchema = z.object({
|
|||||||
include: z.array(z.nativeEnum(HotelIncludeEnum)).optional(),
|
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" }),
|
hotelId: z.string().min(1, { message: "hotelId is required" }),
|
||||||
|
toDate: z
|
||||||
|
.string()
|
||||||
|
.min(1, { message: "toDate is required" })
|
||||||
|
.pipe(z.coerce.date()),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { metrics } from "@opentelemetry/api"
|
|||||||
|
|
||||||
import { Lang } from "@/constants/languages"
|
import { Lang } from "@/constants/languages"
|
||||||
import * as api from "@/lib/api"
|
import * as api from "@/lib/api"
|
||||||
|
import { dt } from "@/lib/dt"
|
||||||
import { GetHotelPage } from "@/lib/graphql/Query/HotelPage/HotelPage.graphql"
|
import { GetHotelPage } from "@/lib/graphql/Query/HotelPage/HotelPage.graphql"
|
||||||
import { request } from "@/lib/graphql/request"
|
import { request } from "@/lib/graphql/request"
|
||||||
import {
|
import {
|
||||||
@@ -31,7 +32,7 @@ import {
|
|||||||
getRoomPackagesSchema,
|
getRoomPackagesSchema,
|
||||||
} from "./schemas/packages"
|
} from "./schemas/packages"
|
||||||
import {
|
import {
|
||||||
getBreakfastPackageInput,
|
getBreakfastPackageInputSchema,
|
||||||
getHotelDataInputSchema,
|
getHotelDataInputSchema,
|
||||||
getHotelInputSchema,
|
getHotelInputSchema,
|
||||||
getHotelsAvailabilityInputSchema,
|
getHotelsAvailabilityInputSchema,
|
||||||
@@ -982,14 +983,14 @@ export const hotelQueryRouter = router({
|
|||||||
return validatedPackagesData.data
|
return validatedPackagesData.data
|
||||||
}),
|
}),
|
||||||
breakfast: safeProtectedServiceProcedure
|
breakfast: safeProtectedServiceProcedure
|
||||||
.input(getBreakfastPackageInput)
|
.input(getBreakfastPackageInputSchema)
|
||||||
.query(async function ({ ctx, input }) {
|
.query(async function ({ ctx, input }) {
|
||||||
const params = {
|
const params = {
|
||||||
Adults: 2,
|
Adults: input.adults,
|
||||||
EndDate: "2024-10-28",
|
EndDate: dt(input.toDate).format("YYYY-MM-DD"),
|
||||||
StartDate: "2024-10-25",
|
StartDate: dt(input.fromDate).format("YYYY-MM-DD"),
|
||||||
}
|
}
|
||||||
const metricsData = { ...input, ...params }
|
const metricsData = { ...params, hotelId: input.hotelId }
|
||||||
breakfastPackagesCounter.add(1, metricsData)
|
breakfastPackagesCounter.add(1, metricsData)
|
||||||
console.info(
|
console.info(
|
||||||
"api.package.breakfast start",
|
"api.package.breakfast start",
|
||||||
|
|||||||
6
types/requests/packages.ts
Normal file
6
types/requests/packages.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
import { getBreakfastPackageInputSchema } from "@/server/routers/hotels/input"
|
||||||
|
|
||||||
|
export interface BreackfastPackagesInput
|
||||||
|
extends z.input<typeof getBreakfastPackageInputSchema> {}
|
||||||
Reference in New Issue
Block a user