Skip to content

Commit 532c2f5

Browse files
authored
fix: show correct input type for location (calcom#23228)
1 parent efca905 commit 532c2f5

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

packages/features/form-builder/FormBuilder.tsx

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,30 @@ type RhfFormFields = RhfForm["fields"];
4242

4343
type RhfFormField = RhfFormFields[number];
4444

45+
type DataStore = {
46+
options: Record<
47+
string,
48+
{
49+
source: { label: string };
50+
value: { label: string; value: string; inputPlaceholder?: string }[];
51+
}
52+
>;
53+
};
54+
4555
function getCurrentFieldType(fieldForm: UseFormReturn<RhfFormField>) {
4656
return fieldTypesConfigMap[fieldForm.watch("type") || "text"];
4757
}
4858

59+
const getLocationFieldType = (field: RhfFormField) => {
60+
const baseFieldType = fieldTypesConfigMap[field.type];
61+
62+
if (field.name === "location") {
63+
return { ...baseFieldType, label: "Location" };
64+
}
65+
66+
return baseFieldType;
67+
};
68+
4969
/**
5070
* It works with a react-hook-form only.
5171
* `formProp` specifies the name of the property in the react-hook-form that has the fields. This is where fields would be updated.
@@ -71,15 +91,7 @@ export const FormBuilder = function FormBuilder({
7191
/**
7292
* A readonly dataStore that is used to lookup the options for the fields. It works in conjunction with the field.getOptionAt property which acts as the key in options
7393
*/
74-
dataStore: {
75-
options: Record<
76-
string,
77-
{
78-
source: { label: string };
79-
value: { label: string; value: string; inputPlaceholder?: string }[];
80-
}
81-
>;
82-
};
94+
dataStore: DataStore;
8395
/**
8496
* This is kind of a hack to allow certain fields to be just shown as required when they might not be required in a strict sense
8597
* e.g. Location field has a default value at backend so API can send no location but formBuilder in UI doesn't allow it.
@@ -226,7 +238,7 @@ export const FormBuilder = function FormBuilder({
226238
return null;
227239
}
228240

229-
const fieldType = fieldTypesConfigMap[field.type];
241+
const fieldType = getLocationFieldType(field);
230242
const isFieldEditableSystemButOptional = field.editable === "system-but-optional";
231243
const isFieldEditableSystemButHidden = field.editable === "system-but-hidden";
232244
const isFieldEditableSystem = field.editable === "system";
@@ -565,7 +577,7 @@ function FieldEditDialog({
565577
}
566578
fieldForm.setValue("type", value, { shouldDirty: true });
567579
}}
568-
value={fieldTypesConfigMap[formFieldType]}
580+
value={dialog.data ? getLocationFieldType(dialog.data) : fieldTypesConfigMap[formFieldType]}
569581
options={fieldTypes.filter((f) => !f.systemOnly)}
570582
label={t("input_type")}
571583
/>

0 commit comments

Comments
 (0)