Skip to content

Scheduling infrastructure for absolutely everyone.

fix: Can't use unsaved booking question as variable in event name (#18604)

Amit Sharmad2c4c4513768
diff --git a/packages/platform/atoms/event-types/hooks/useEventTypeForm.ts b/packages/platform/atoms/event-types/hooks/useEventTypeForm.ts
index 4c5f22bced3..0899637d8c7 100644
--- a/packages/platform/atoms/event-types/hooks/useEventTypeForm.ts
+++ b/packages/platform/atoms/event-types/hooks/useEventTypeForm.ts
@@ -32,15 +32,10 @@ export const useEventTypeForm = ({
onSubmit: (data: EventTypeUpdateInput) => void;
}) => {
const { t } = useLocale();
- const bookingFields: Record<string, Fields[number]["name"]> = {};
const [periodDates] = useState<{ startDate: Date; endDate: Date }>({
startDate: new Date(eventType.periodStartDate || Date.now()),
endDate: new Date(eventType.periodEndDate || Date.now()),
});
- eventType.bookingFields.forEach(({ name }: { name: string }) => {
- bookingFields[name] = name;
- });
-
// this is a nightmare to type, will do in follow up PR
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const defaultValues: any = useMemo(() => {
@@ -145,6 +140,12 @@ export const useEventTypeForm = ({
eventName: z
.string()
.superRefine((val, ctx) => {
+ const bookingFields: Record<string, Fields[number]["name"]> = {};
+ const _bookingFields = form.getValues("bookingFields");
+ _bookingFields.forEach(({ name }: { name: string }) => {
+ bookingFields[name] = name;
+ });
+
const validationResult = validateCustomEventName(val, bookingFields);
if (validationResult !== true) {
ctx.addIssue({