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:
authored and GitHub committed 2026-01-27 17:39:11 +05:30
1 parent e3c0e11eb1
commit 9b1f86a671
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",
@@ -271,21 +271,21 @@ test.describe("Routing Forms", () => {
label: "Test Field",
});
const queryString =
"firstField=456&Test-Field-Number=456&Test-Field-Single-choice-selection=456&Test-Field-Multiple-choice-selection=456&Test-Field-Multiple-choice-selection=789&Test-Field-Phone=456&Test-Field-E[email protected]";
"firstfield=456&test-field-number=456&test-field-single-choice-selection=456&test-field-multiple-choice-selection=456&test-field-multiple-choice-selection=789&test-field-phone=456&test-field-e[email protected]";
await gotoRoutingLink({ page, queryString });
await page.fill('[data-testid="form-field-Test-Field-Long-text"]', "manual-fill");
await page.fill('[data-testid="form-field-test-field-long-text"]', "manual-fill");
await expect(page.locator('[data-testid="form-field-firstField"]')).toHaveValue("456");
await expect(page.locator('[data-testid="form-field-Test-Field-Number"]')).toHaveValue("456");
await expect(page.locator('[data-testid="form-field-firstfield"]')).toHaveValue("456");
await expect(page.locator('[data-testid="form-field-test-field-number"]')).toHaveValue("456");
// TODO: Verify select and multiselect has prefilled values.
// expect(await page.locator(`[data-testid="form-field-Test-Field-Select"]`).inputValue()).toBe("456");
// expect(await page.locator(`[data-testid="form-field-Test-Field-MultiSelect"]`).inputValue()).toBe("456");
// expect(await page.locator(`[data-testid="form-field-test-field-select"]`).inputValue()).toBe("456");
// expect(await page.locator(`[data-testid="form-field-test-field-multiselect"]`).inputValue()).toBe("456");
await expect(page.locator('[data-testid="form-field-Test-Field-Phone"]')).toHaveValue("456");
await expect(page.locator('[data-testid="form-field-Test-Field-Email"]')).toHaveValue(
await expect(page.locator('[data-testid="form-field-test-field-phone"]')).toHaveValue("456");
await expect(page.locator('[data-testid="form-field-test-field-email"]')).toHaveValue(
"[email protected]"
);
@@ -297,15 +297,15 @@ test.describe("Routing Forms", () => {
const url = new URL(page.url());
// Coming from the response filled by booker
expect(url.searchParams.get("firstField")).toBe("456");
expect(url.searchParams.get("firstfield")).toBe("456");
// All other params come from prefill URL
expect(url.searchParams.get("Test-Field-Number")).toBe("456");
expect(url.searchParams.get("Test-Field-Long-text")).toBe("manual-fill");
expect(url.searchParams.get("Test-Field-Multiple-choice-selection")).toBe("456");
expect(url.searchParams.getAll("Test-Field-Multiple-choice-selection")).toMatchObject(["456", "789"]);
expect(url.searchParams.get("Test-Field-Phone")).toBe("456");
expect(url.searchParams.get("Test-Field-Email")).toBe("[email protected]");
expect(url.searchParams.get("test-field-number")).toBe("456");
expect(url.searchParams.get("test-field-long-text")).toBe("manual-fill");
expect(url.searchParams.get("test-field-multiple-choice-selection")).toBe("456");
expect(url.searchParams.getAll("test-field-multiple-choice-selection")).toMatchObject(["456", "789"]);
expect(url.searchParams.get("test-field-phone")).toBe("456");
expect(url.searchParams.get("test-field-email")).toBe("[email protected]");
});
// TODO: How to install the app just once?