fix: move logic to BookingFields

fix/organizer-location
Udit Takkar 2023-10-26 14:44:49 +05:30
parent 38638f99f3
commit 52b3120fd9
2 changed files with 20 additions and 15 deletions

View File

@ -1,6 +1,7 @@
import { useFormContext } from "react-hook-form";
import type { LocationObject } from "@calcom/app-store/locations";
import { DefaultEventLocationTypeEnum } from "@calcom/app-store/locations";
import type { GetBookingType } from "@calcom/features/bookings/lib/get-booking";
import getLocationOptionsForSelect from "@calcom/features/bookings/lib/getLocationOptionsForSelect";
import { FormBuilderField } from "@calcom/features/form-builder/FormBuilderField";
@ -105,6 +106,24 @@ export const BookingFields = ({
);
}
if (field?.options) {
const moreThanOneInPersonOptions = !!(
field.options.filter((field) => {
return field.value === DefaultEventLocationTypeEnum.InPerson;
}).length > 1
);
field.options = field.options.map((field) => {
return {
...field,
value:
field.value === DefaultEventLocationTypeEnum.InPerson && moreThanOneInPersonOptions
? field.label
: field.value,
};
});
}
return (
<FormBuilderField className="mb-4" field={{ ...field, hidden }} readOnly={readOnly} key={index} />
);

View File

@ -3,7 +3,6 @@ import type { TFunction } from "next-i18next";
import { Controller, useFormContext } from "react-hook-form";
import type { z } from "zod";
import { DefaultEventLocationTypeEnum } from "@calcom/app-store/locations";
import { classNames } from "@calcom/lib";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Label } from "@calcom/ui";
@ -312,21 +311,8 @@ export const ComponentForField = ({
if (!field.optionsInputs) {
throw new Error("Field optionsInputs is not defined");
}
const moreThanOneInPersonOptions = !!(
field.options.filter((field) => {
return field.value === DefaultEventLocationTypeEnum.InPerson;
}).length > 1
);
const options = field.options.map((field) => {
return {
...field,
value:
field.value === DefaultEventLocationTypeEnum.InPerson && moreThanOneInPersonOptions
? field.label
: field.value,
};
});
const options = field.options;
return field.options.length ? (
<WithLabel field={field} readOnly={readOnly}>