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

Co-authored-by: Tushar Bhatt <95581504+TusharBhatt1@users.noreply.github.com>
This commit is contained in:
Amit SharmaandTushar Bhatt authored and GitHub committed 2025-02-18 16:11:40 +05:30
1 parent 43ba47a122
commit d2c4c45137
1 file changed
+6 -5
@@ -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({