fix: lowercase identifier values in routing form editor (#26616)
* fix: lowercase identifier values in routing form editor Co-Authored-By: [email protected] <[email protected]> * fix: remove unused @ts-expect-error directives Co-Authored-By: [email protected] <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
2 files changed
+25
-32
No files matched your search
@@ -1,11 +1,5 @@
|
||||
"use client";
|
||||
|
||||
import { useAutoAnimate } from "@formkit/auto-animate/react";
|
||||
import type { UseFormReturn } from "react-hook-form";
|
||||
import { Controller, useFieldArray, useWatch } from "react-hook-form";
|
||||
import { Toaster } from "sonner";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
import { FieldTypes } from "@calcom/app-store/routing-forms/lib/FieldTypes";
|
||||
import type { RoutingFormWithResponseCount } from "@calcom/app-store/routing-forms/types/types";
|
||||
import { getFieldIdentifier } from "@calcom/features/form-builder/utils/getFieldIdentifier";
|
||||
@@ -16,17 +10,20 @@ import { FormCard, FormCardBody } from "@calcom/ui/components/card";
|
||||
import {
|
||||
BooleanToggleGroupField,
|
||||
Label,
|
||||
MultiOptionInput,
|
||||
SelectField,
|
||||
TextField,
|
||||
MultiOptionInput,
|
||||
} from "@calcom/ui/components/form";
|
||||
import { Icon } from "@calcom/ui/components/icon";
|
||||
import { Tooltip } from "@calcom/ui/components/tooltip";
|
||||
import type { getServerSidePropsForSingleFormView as getServerSideProps } from "@calcom/web/lib/apps/routing-forms/[...pages]/getServerSidePropsSingleForm";
|
||||
|
||||
import type { inferSSRProps } from "@lib/types/inferSSRProps";
|
||||
|
||||
import SingleForm from "@components/apps/routing-forms/SingleForm";
|
||||
import { useAutoAnimate } from "@formkit/auto-animate/react";
|
||||
import type { inferSSRProps } from "@lib/types/inferSSRProps";
|
||||
import type { UseFormReturn } from "react-hook-form";
|
||||
import { Controller, useFieldArray, useWatch } from "react-hook-form";
|
||||
import { Toaster } from "sonner";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
type HookForm = UseFormReturn<RoutingFormWithResponseCount>;
|
||||
|
||||
@@ -123,14 +120,14 @@ function Field({
|
||||
// Only auto-update identifier if it was auto-generated from the previous label
|
||||
// This preserves manual identifier changes
|
||||
const isIdentifierGeneratedFromPreviousLabel =
|
||||
currentIdentifier === getFieldIdentifier(previousLabel);
|
||||
currentIdentifier === getFieldIdentifier(previousLabel).toLowerCase();
|
||||
if (
|
||||
!currentIdentifier ||
|
||||
isIdentifierGeneratedFromPreviousLabel
|
||||
) {
|
||||
hookForm.setValue(
|
||||
`${hookFieldNamespace}.identifier`,
|
||||
getFieldIdentifier(newLabel),
|
||||
getFieldIdentifier(newLabel).toLowerCase(),
|
||||
{ shouldDirty: true }
|
||||
);
|
||||
}
|
||||
@@ -155,7 +152,7 @@ function Field({
|
||||
onChange={(e) => {
|
||||
hookForm.setValue(
|
||||
`${hookFieldNamespace}.identifier`,
|
||||
e.target.value,
|
||||
e.target.value.toLowerCase(),
|
||||
{ shouldDirty: true }
|
||||
);
|
||||
}}
|
||||
@@ -282,8 +279,6 @@ const FormEdit = ({
|
||||
append: appendHookFormField,
|
||||
remove: removeHookFormField,
|
||||
swap: swapHookFormField,
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore https://github.com/react-hook-form/react-hook-form/issues/6679
|
||||
} = useFieldArray({
|
||||
control: hookForm.control,
|
||||
name: fieldsNamespace,
|
||||
@@ -294,8 +289,6 @@ const FormEdit = ({
|
||||
|
||||
const addField = () => {
|
||||
appendHookFormField({
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
id: uuidv4(),
|
||||
// This is same type from react-awesome-query-builder
|
||||
type: "text",
|
||||
|
||||
Reference in new issue
Block a user