fix: More Stability for FormBuilder by unit tests (#16129)

* Remove use of location from FormBuilder

* Add tests

* Improve error message in test

* Bust cache
This commit is contained in:
Hariom Balhara authored and GitHub committed 2024-08-27 08:14:19 -04:00
1 parent 7aae55f417
commit 6104add6bd
9 files changed
+463 -200

No files matched your search

@@ -15,6 +15,7 @@ import {
} from "@calcom/features/ee/workflows/lib/allowDisablingStandardEmails";
import type { FormValues } from "@calcom/features/eventtypes/lib/types";
import { FormBuilder } from "@calcom/features/form-builder/FormBuilder";
import type { fieldSchema } from "@calcom/features/form-builder/schema";
import type { EditableSchema } from "@calcom/features/form-builder/schema";
import { BookerLayoutSelector } from "@calcom/features/settings/BookerLayoutSelector";
import { classNames } from "@calcom/lib";
@@ -46,6 +47,8 @@ import {
import RequiresConfirmationController from "./RequiresConfirmationController";
import { DisableAllEmailsSetting } from "./settings/DisableAllEmailsSetting";
type BookingField = z.infer<typeof fieldSchema>;
const CustomEventTypeModal = dynamic(() => import("@components/eventtype/CustomEventTypeModal"));
export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupProps, "eventType" | "team">) => {
@@ -163,7 +166,6 @@ export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupProps,
.map((secondaryEmail) => ({ label: secondaryEmail.email, value: secondaryEmail.id })),
];
const selectedSecondaryEmailId = formMethods.getValues("secondaryEmailId") || -1;
return (
<div className="flex flex-col space-y-4">
{/**
@@ -269,9 +271,17 @@ export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupProps,
{...shouldLockDisableProps("bookingFields")}
dataStore={{
options: {
locations: getLocationsOptionsForSelect(formMethods.getValues("locations") ?? [], t),
locations: {
// FormBuilder doesn't handle plural for non-english languages. So, use english(Location) only. This is similar to 'Workflow'
source: { label: "Location" },
value: getLocationsOptionsForSelect(formMethods.getValues("locations") ?? [], t),
},
},
}}
shouldConsiderRequired={(field: BookingField) => {
// Location field has a default value at backend so API can send no location but we don't allow it in UI and thus we want to show it as required to user
return field.name === "location" ? true : field.required;
}}
/>
</div>
<RequiresConfirmationController