fix: add required property on input (#3934)
* fix: add required property on input * chore: remove console * fix: add check in /api/book for custom inputs * chore: var name * wip:try zod * fix: change zod validation Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
parent
85cc62d0cb
commit
00c00a9aee
|
@ -692,6 +692,7 @@ const BookingPage = ({
|
||||||
{...bookingForm.register(`customInputs.${input.id}`, {
|
{...bookingForm.register(`customInputs.${input.id}`, {
|
||||||
required: input.required,
|
required: input.required,
|
||||||
})}
|
})}
|
||||||
|
required={input.required}
|
||||||
id={"custom_" + input.id}
|
id={"custom_" + input.id}
|
||||||
rows={3}
|
rows={3}
|
||||||
className={inputClassName}
|
className={inputClassName}
|
||||||
|
@ -705,6 +706,7 @@ const BookingPage = ({
|
||||||
{...bookingForm.register(`customInputs.${input.id}`, {
|
{...bookingForm.register(`customInputs.${input.id}`, {
|
||||||
required: input.required,
|
required: input.required,
|
||||||
})}
|
})}
|
||||||
|
required={input.required}
|
||||||
id={"custom_" + input.id}
|
id={"custom_" + input.id}
|
||||||
className={inputClassName}
|
className={inputClassName}
|
||||||
placeholder={input.placeholder}
|
placeholder={input.placeholder}
|
||||||
|
@ -717,6 +719,7 @@ const BookingPage = ({
|
||||||
{...bookingForm.register(`customInputs.${input.id}`, {
|
{...bookingForm.register(`customInputs.${input.id}`, {
|
||||||
required: input.required,
|
required: input.required,
|
||||||
})}
|
})}
|
||||||
|
required={input.required}
|
||||||
id={"custom_" + input.id}
|
id={"custom_" + input.id}
|
||||||
className={inputClassName}
|
className={inputClassName}
|
||||||
placeholder=""
|
placeholder=""
|
||||||
|
@ -730,6 +733,7 @@ const BookingPage = ({
|
||||||
{...bookingForm.register(`customInputs.${input.id}`, {
|
{...bookingForm.register(`customInputs.${input.id}`, {
|
||||||
required: input.required,
|
required: input.required,
|
||||||
})}
|
})}
|
||||||
|
required={input.required}
|
||||||
id={"custom_" + input.id}
|
id={"custom_" + input.id}
|
||||||
className="h-4 w-4 rounded border-gray-300 text-black focus:ring-black disabled:bg-gray-200 ltr:mr-2 rtl:ml-2 disabled:dark:text-gray-500"
|
className="h-4 w-4 rounded border-gray-300 text-black focus:ring-black disabled:bg-gray-200 ltr:mr-2 rtl:ml-2 disabled:dark:text-gray-500"
|
||||||
placeholder=""
|
placeholder=""
|
||||||
|
|
|
@ -30,7 +30,7 @@ import { defaultResponder, getLuckyUser } from "@calcom/lib/server";
|
||||||
import { updateWebUser as syncServicesUpdateWebUser } from "@calcom/lib/sync/SyncServiceManager";
|
import { updateWebUser as syncServicesUpdateWebUser } from "@calcom/lib/sync/SyncServiceManager";
|
||||||
import getSubscribers from "@calcom/lib/webhooks/subscriptions";
|
import getSubscribers from "@calcom/lib/webhooks/subscriptions";
|
||||||
import prisma, { userSelect } from "@calcom/prisma";
|
import prisma, { userSelect } from "@calcom/prisma";
|
||||||
import { extendedBookingCreateBody } from "@calcom/prisma/zod-utils";
|
import { extendedBookingCreateBody, requiredCustomInputSchema } from "@calcom/prisma/zod-utils";
|
||||||
import type { BufferedBusyTime } from "@calcom/types/BufferedBusyTime";
|
import type { BufferedBusyTime } from "@calcom/types/BufferedBusyTime";
|
||||||
import type { AdditionalInformation, CalendarEvent } from "@calcom/types/Calendar";
|
import type { AdditionalInformation, CalendarEvent } from "@calcom/types/Calendar";
|
||||||
import type { EventResult, PartialReference } from "@calcom/types/EventManager";
|
import type { EventResult, PartialReference } from "@calcom/types/EventManager";
|
||||||
|
@ -119,6 +119,7 @@ const getEventTypesFromDB = async (eventTypeId: number) => {
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
customInputs: true,
|
||||||
users: userSelect,
|
users: userSelect,
|
||||||
team: {
|
team: {
|
||||||
select: {
|
select: {
|
||||||
|
@ -251,8 +252,20 @@ async function handler(req: NextApiRequest) {
|
||||||
|
|
||||||
const eventType =
|
const eventType =
|
||||||
!eventTypeId && !!eventTypeSlug ? getDefaultEvent(eventTypeSlug) : await getEventTypesFromDB(eventTypeId);
|
!eventTypeId && !!eventTypeSlug ? getDefaultEvent(eventTypeSlug) : await getEventTypesFromDB(eventTypeId);
|
||||||
|
|
||||||
if (!eventType) throw new HttpError({ statusCode: 404, message: "eventType.notFound" });
|
if (!eventType) throw new HttpError({ statusCode: 404, message: "eventType.notFound" });
|
||||||
|
|
||||||
|
// Check if required custom inputs exist
|
||||||
|
if (eventType.customInputs) {
|
||||||
|
eventType.customInputs.forEach((customInput) => {
|
||||||
|
if (customInput.required) {
|
||||||
|
requiredCustomInputSchema.parse(
|
||||||
|
reqBody.customInputs.find((userInput) => userInput.label === customInput.label)?.value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let timeOutOfBounds = false;
|
let timeOutOfBounds = false;
|
||||||
try {
|
try {
|
||||||
timeOutOfBounds = isOutOfBounds(reqBody.start, {
|
timeOutOfBounds = isOutOfBounds(reqBody.start, {
|
||||||
|
|
|
@ -87,6 +87,13 @@ export const bookingCreateBodySchema = z.object({
|
||||||
hashedLink: z.string().nullish(),
|
hashedLink: z.string().nullish(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const requiredCustomInputSchema = z.union([
|
||||||
|
// string must be given & nonempty
|
||||||
|
z.string().trim().min(1),
|
||||||
|
// boolean must be true if set.
|
||||||
|
z.boolean().refine((v) => v === true),
|
||||||
|
]);
|
||||||
|
|
||||||
export type BookingCreateBody = z.input<typeof bookingCreateBodySchema>;
|
export type BookingCreateBody = z.input<typeof bookingCreateBodySchema>;
|
||||||
|
|
||||||
export const bookingConfirmPatchBodySchema = z.object({
|
export const bookingConfirmPatchBodySchema = z.object({
|
||||||
|
|
Loading…
Reference in New Issue
Block a user