5444 cal 339 radio option in additional questions on public booking page (#5804)
* Use field array intro * WIP - form submitting wrong form * WIP with fake useFormHook * WORKING! OMG Co-authored-by: Alex <[email protected]> Co-authored-by: Jeroen Reumkens <[email protected]> * Booking Page styling * Fix duplicate fields * Radio string * Type error * Linting errors * Remove unused duplicate file * Fixed user related type error * remove log * Remove console logs * remove console log * fix dark mode text and comment style Co-authored-by: Alex <[email protected]> Co-authored-by: Jeroen Reumkens <[email protected]> Co-authored-by: Alex van Andel <[email protected]> Co-authored-by: alannnc <[email protected]>
This commit is contained in:
20 files changed
+259
-184
No files matched your search
@@ -42,7 +42,11 @@ import { checkBookingLimits, getLuckyUser } from "@calcom/lib/server";
|
||||
import { getTranslation } from "@calcom/lib/server/i18n";
|
||||
import { updateWebUser as syncServicesUpdateWebUser } from "@calcom/lib/sync/SyncServiceManager";
|
||||
import prisma, { userSelect } from "@calcom/prisma";
|
||||
import { EventTypeMetaDataSchema, extendedBookingCreateBody } from "@calcom/prisma/zod-utils";
|
||||
import {
|
||||
customInputSchema,
|
||||
EventTypeMetaDataSchema,
|
||||
extendedBookingCreateBody,
|
||||
} from "@calcom/prisma/zod-utils";
|
||||
import type { BufferedBusyTime } from "@calcom/types/BufferedBusyTime";
|
||||
import type { AdditionalInformation, AppsStatus, CalendarEvent } from "@calcom/types/Calendar";
|
||||
import type { EventResult, PartialReference } from "@calcom/types/EventManager";
|
||||
@@ -203,6 +207,7 @@ const getEventTypesFromDB = async (eventTypeId: number) => {
|
||||
...eventType,
|
||||
metadata: EventTypeMetaDataSchema.parse(eventType.metadata),
|
||||
recurringEvent: parseRecurringEvent(eventType.recurringEvent),
|
||||
customInputs: customInputSchema.array().parse(eventType.customInputs),
|
||||
locations: (eventType.locations ?? []) as LocationObject[],
|
||||
};
|
||||
};
|
||||
@@ -310,7 +315,7 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) {
|
||||
const stripeAppData = getStripeAppData(eventType);
|
||||
|
||||
// Check if required custom inputs exist
|
||||
handleCustomInputs(eventType.customInputs, reqBody.customInputs);
|
||||
handleCustomInputs(eventType.customInputs as EventTypeCustomInput[], reqBody.customInputs);
|
||||
|
||||
let timeOutOfBounds = false;
|
||||
try {
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import type { EventTypeCustomInput } from "@prisma/client";
|
||||
import { PeriodType, Prisma, SchedulingType, UserPlan } from "@prisma/client";
|
||||
|
||||
import { DailyLocationType } from "@calcom/app-store/locations";
|
||||
import { userSelect } from "@calcom/prisma/selects";
|
||||
import { _EventTypeModel } from "@calcom/prisma/zod";
|
||||
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||
import { CustomInputSchema, EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
type User = Prisma.UserGetPayload<typeof userSelect>;
|
||||
|
||||
@@ -50,7 +48,7 @@ const user: User = {
|
||||
allowDynamicBooking: true,
|
||||
};
|
||||
|
||||
const customInputs: EventTypeCustomInput[] = [];
|
||||
const customInputs: CustomInputSchema[] = [];
|
||||
|
||||
const commons = {
|
||||
isDynamic: true,
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- AlterEnum
|
||||
ALTER TYPE "EventTypeCustomInputType" ADD VALUE 'radio';
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "EventTypeCustomInput" ADD COLUMN "options" JSONB;
|
||||
@@ -347,6 +347,7 @@ enum EventTypeCustomInputType {
|
||||
TEXTLONG @map("textLong")
|
||||
NUMBER @map("number")
|
||||
BOOL @map("bool")
|
||||
RADIO @map("radio")
|
||||
}
|
||||
|
||||
model EventTypeCustomInput {
|
||||
@@ -355,6 +356,8 @@ model EventTypeCustomInput {
|
||||
eventType EventType @relation(fields: [eventTypeId], references: [id], onDelete: Cascade)
|
||||
label String
|
||||
type EventTypeCustomInputType
|
||||
// @zod.custom(imports.customInputOptionSchema)
|
||||
options Json?
|
||||
required Boolean
|
||||
placeholder String @default("")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { EventTypeCustomInputType } from "@prisma/client";
|
||||
import z, { ZodNullable, ZodObject, ZodOptional } from "zod";
|
||||
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
@@ -212,6 +213,25 @@ export const teamMetadataSchema = z
|
||||
.partial()
|
||||
.nullable();
|
||||
|
||||
export const customInputOptionSchema = z.array(
|
||||
z.object({
|
||||
label: z.string(),
|
||||
type: z.string(),
|
||||
})
|
||||
);
|
||||
|
||||
export const customInputSchema = z.object({
|
||||
id: z.number(),
|
||||
eventTypeId: z.number(),
|
||||
label: z.string(),
|
||||
type: z.nativeEnum(EventTypeCustomInputType),
|
||||
options: customInputOptionSchema.optional().nullable(),
|
||||
required: z.boolean(),
|
||||
placeholder: z.string(),
|
||||
});
|
||||
|
||||
export type CustomInputSchema = z.infer<typeof customInputSchema>;
|
||||
|
||||
/**
|
||||
* Ensures that it is a valid HTTP URL
|
||||
* It automatically avoids
|
||||
|
||||
@@ -11,7 +11,12 @@ import { validateBookingLimitOrder } from "@calcom/lib";
|
||||
import { CAL_URL } from "@calcom/lib/constants";
|
||||
import { baseEventTypeSelect, baseUserSelect } from "@calcom/prisma";
|
||||
import { _DestinationCalendarModel, _EventTypeCustomInputModel, _EventTypeModel } from "@calcom/prisma/zod";
|
||||
import { EventTypeMetaDataSchema, stringOrNumber } from "@calcom/prisma/zod-utils";
|
||||
import {
|
||||
customInputSchema,
|
||||
EventTypeMetaDataSchema,
|
||||
stringOrNumber,
|
||||
CustomInputSchema,
|
||||
} from "@calcom/prisma/zod-utils";
|
||||
import { createEventTypeInput } from "@calcom/prisma/zod/custom/eventtype";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
@@ -30,7 +35,7 @@ function handlePeriodType(periodType: string | undefined): PeriodType | undefine
|
||||
return PeriodType[passedPeriodType];
|
||||
}
|
||||
|
||||
function handleCustomInputs(customInputs: EventTypeCustomInput[], eventTypeId: number) {
|
||||
function handleCustomInputs(customInputs: CustomInputSchema[], eventTypeId: number) {
|
||||
const cInputsIdsToDelete = customInputs.filter((input) => input.id > 0).map((e) => e.id);
|
||||
const cInputsToCreate = customInputs
|
||||
.filter((input) => input.id < 0)
|
||||
@@ -39,6 +44,7 @@ function handleCustomInputs(customInputs: EventTypeCustomInput[], eventTypeId: n
|
||||
label: input.label,
|
||||
required: input.required,
|
||||
placeholder: input.placeholder,
|
||||
options: input.options || undefined,
|
||||
}));
|
||||
const cInputsToUpdate = customInputs
|
||||
.filter((input) => input.id > 0)
|
||||
@@ -48,6 +54,7 @@ function handleCustomInputs(customInputs: EventTypeCustomInput[], eventTypeId: n
|
||||
label: input.label,
|
||||
required: input.required,
|
||||
placeholder: input.placeholder,
|
||||
options: input.options || undefined,
|
||||
},
|
||||
where: {
|
||||
id: input.id,
|
||||
@@ -71,7 +78,7 @@ function handleCustomInputs(customInputs: EventTypeCustomInput[], eventTypeId: n
|
||||
const EventTypeUpdateInput = _EventTypeModel
|
||||
/** Optional fields */
|
||||
.extend({
|
||||
customInputs: z.array(_EventTypeCustomInputModel),
|
||||
customInputs: z.array(customInputSchema).optional(),
|
||||
destinationCalendar: _DestinationCalendarModel.pick({
|
||||
integration: true,
|
||||
externalId: true,
|
||||
|
||||
@@ -86,7 +86,7 @@ export {
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "./v2/core/Dropdown";
|
||||
export { RadioGroup } from "./v2/core/form";
|
||||
export { RadioGroup, Radio, Group, RadioField } from "./v2/core/form";
|
||||
export { BooleanToggleGroupField } from "./v2/core/form/BooleanToggleGroup";
|
||||
export { DateRangePickerLazy as DateRangePicker } from "./v2/core/form/date-range-picker";
|
||||
export { default as DatePickerField } from "./v2/core/form/DatePicker";
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
export { RadioGroup, /* TODO: solve this conflict -> Select, */ Radio } from "./radio-area";
|
||||
export {
|
||||
RadioGroup,
|
||||
/* TODO: solve this conflict -> Select, */
|
||||
Radio,
|
||||
Group,
|
||||
RadioField,
|
||||
} from "./radio-area";
|
||||
export { default as Checkbox } from "../../../components/form/checkbox/Checkbox";
|
||||
export { default as DatePicker } from "./DatePicker";
|
||||
export { default as Select, SelectWithValidation, SelectField, getReactSelectProps } from "./select";
|
||||
|
||||
@@ -29,7 +29,7 @@ export const Label = (props: JSX.IntrinsicElements["label"] & { disabled?: boole
|
||||
<label
|
||||
{...props}
|
||||
className={classNames(
|
||||
"ml-2 text-sm font-medium leading-5 text-gray-900",
|
||||
"ml-2 text-sm font-medium leading-5 text-gray-900 dark:text-white",
|
||||
props.disabled && "text-gray-500"
|
||||
)}
|
||||
/>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * as RadioGroup from "./RadioAreaGroup";
|
||||
export { default as Select } from "./Select";
|
||||
export * as Radio from "./Radio";
|
||||
export { Group, Indicator, Label, Radio, RadioField } from "./Radio";
|
||||
Reference in new issue
Block a user