The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Replace the phone lead form field with a text field
Rafi58ec7da656d9
diff --git a/apps/web/tests/misc/submitted-lead-form-builder.test.ts b/apps/web/tests/misc/submitted-lead-form-builder.test.tsindex a094de0023..7158a5063b 100644--- a/apps/web/tests/misc/submitted-lead-form-builder.test.ts+++ b/apps/web/tests/misc/submitted-lead-form-builder.test.ts@@ -68,7 +68,6 @@ const STORED_FIELDS: FormField[] = [{ ...common, key: "website", label: "Website", type: "url", position: 5 },{ ...common, key: "start", label: "Start date", type: "date", position: 6 },{ ...common, key: "country", label: "Country", type: "country", position: 7 },- { ...common, key: "phone", label: "Phone", type: "phone", position: 8 },];function builderField(@@ -91,6 +90,33 @@ describe("lead form builder fields", () => {expect(result).toEqual({ success: true, fields: STORED_FIELDS });});+ it("opens a stored phone field as a text field", () => {+ const result = parseLeadFormBuilderFields([+ toLeadFormBuilderField({+ ...common,+ key: "phone",+ label: "Phone",+ type: "phone",+ position: 0,+ required: true,+ }),+ ]);++ expect(result).toEqual({+ success: true,+ fields: [+ {+ ...common,+ key: "phone",+ label: "Phone",+ type: "text",+ position: 0,+ required: true,+ },+ ],+ });+ });+it("sets the position from the order and unlocks custom fields", () => {const result = parseLeadFormBuilderFields([builderField({ key: "b", label: "B" }),diff --git a/apps/web/ui/submitted-leads/form-builder/lead-form-builder-fields.ts b/apps/web/ui/submitted-leads/form-builder/lead-form-builder-fields.tsindex 58479f534a..64a04d3af2 100644--- a/apps/web/ui/submitted-leads/form-builder/lead-form-builder-fields.ts+++ b/apps/web/ui/submitted-leads/form-builder/lead-form-builder-fields.ts@@ -4,7 +4,8 @@ import * as z from "zod/v4";type FormField = z.infer<typeof formFieldSchema>;-export type LeadFormFieldType = FormField["type"];+// The builder offers every stored type except phone, which it opens as a text field+export type LeadFormFieldType = Exclude<FormField["type"], "phone">;export type LeadFormBuilderOption = {value: string;@@ -61,7 +62,7 @@ export function changeLeadFormBuilderFieldType(export function toLeadFormBuilderField(field: FormField): LeadFormBuilderField {return {key: field.key,- type: field.type,+ type: field.type === "phone" ? "text" : field.type,label: field.label,required: field.required,options:diff --git a/apps/web/ui/submitted-leads/form-builder/lead-form-field-card.tsx b/apps/web/ui/submitted-leads/form-builder/lead-form-field-card.tsxindex f20cc387d1..4411a7d6b6 100644--- a/apps/web/ui/submitted-leads/form-builder/lead-form-field-card.tsx+++ b/apps/web/ui/submitted-leads/form-builder/lead-form-field-card.tsx@@ -130,9 +130,7 @@ function LeadFormFieldSettings({LeadFormFieldType,(typeof LEAD_FORM_FIELD_TYPES)[LeadFormFieldType],][]- )- .filter(([type, { hidden }]) => !hidden || type === field.type)- .map(([type, { label, icon }]) => ({ value: type, label, icon }));+ ).map(([type, { label, icon }]) => ({ value: type, label, icon }));return (<div className="flex flex-col gap-5 p-4">diff --git a/apps/web/ui/submitted-leads/form-builder/lead-form-field-types.ts b/apps/web/ui/submitted-leads/form-builder/lead-form-field-types.tsindex b6bb85e902..f1a0de1abf 100644--- a/apps/web/ui/submitted-leads/form-builder/lead-form-field-types.ts+++ b/apps/web/ui/submitted-leads/form-builder/lead-form-field-types.ts@@ -7,7 +7,6 @@ import {Icon,InputField,LinkChain,- MobilePhone,TextArea,} from "@dub/ui/icons";import { LeadFormFieldType } from "./lead-form-builder-fields";@@ -17,8 +16,6 @@ export const LEAD_FORM_FIELD_TYPES: Record<{label: string;icon: Icon;- // Hidden types are only shown for existing fields that already use them- hidden?: boolean;}> = {text: { label: "Text field", icon: InputField },@@ -29,5 +26,4 @@ export const LEAD_FORM_FIELD_TYPES: Record<country: { label: "Country", icon: Globe },multiSelect: { label: "Multiple choice", icon: CheckboxChecked },number: { label: "Number", icon: Hashtag },- phone: { label: "Phone number", icon: MobilePhone, hidden: true },};diff --git a/apps/web/ui/submitted-leads/form-fields/index.tsx b/apps/web/ui/submitted-leads/form-fields/index.tsxindex 9f9448a4ff..09e3945c47 100644--- a/apps/web/ui/submitted-leads/form-fields/index.tsx+++ b/apps/web/ui/submitted-leads/form-fields/index.tsx@@ -4,14 +4,13 @@ import { CountryField } from "./country-field";import { DateField } from "./date-field";import { MultiSelectField } from "./multi-select-field";import { NumberField } from "./number-field";-import { PhoneField } from "./phone-field";import { SelectField } from "./select-field";import { TextField } from "./text-field";import { TextareaField } from "./textarea-field";import { UrlField } from "./url-field";const FIELD_COMPONENTS: Record<- Exclude<z.infer<typeof formFieldSchema>["type"], "text">,+ Exclude<z.infer<typeof formFieldSchema>["type"], "text" | "phone">,React.ComponentType<any>> = {textarea: TextareaField,@@ -20,7 +19,6 @@ const FIELD_COMPONENTS: Record<date: DateField,multiSelect: MultiSelectField,number: NumberField,- phone: PhoneField,url: UrlField,};@@ -35,11 +33,12 @@ export const LeadFormField = ({keyPath,inputProps,}: LeadFormFieldProps) => {- // Handle text fields specially to pass inputProps- if (field.type === "text") {+ // Handle text fields specially to pass inputProps. Phone fields from older+ // forms show as text fields, because the builder no longer offers them.+ if (field.type === "text" || field.type === "phone") {return (<TextField- field={field}+ field={{ ...field, type: "text" }}keyPath={keyPath}{...(inputProps && { inputProps })}/>diff --git a/apps/web/ui/submitted-leads/form-fields/phone-field.tsx b/apps/web/ui/submitted-leads/form-fields/phone-field.tsxdeleted file mode 100644index 661c4e4784..0000000000--- a/apps/web/ui/submitted-leads/form-fields/phone-field.tsx+++ /dev/null@@ -1,42 +0,0 @@-import { phoneFieldSchema } from "@/lib/zod/schemas/submitted-lead-form";-import { cn } from "@dub/utils";-import { useFormContext } from "react-hook-form";-import * as z from "zod/v4";-import { FormControl, requiredFieldRule } from "./form-control";--type PhoneFieldData = z.infer<typeof phoneFieldSchema>;--export function PhoneField({- keyPath: keyPathProp,- field,-}: {- keyPath?: string;- field: PhoneFieldData;-}) {- const { register, getFieldState, formState } = useFormContext<any>();- const keyPath = keyPathProp || `formData.${field.key}`;- const state = getFieldState(keyPath, formState);- const error = !!state.error;-- return (- <FormControl- label={field.label}- required={field.required}- error={state.error?.message}- labelDir="auto"- >- <input- type="tel"- className={cn(- "mt-2 block w-full rounded-md text-sm focus:outline-none",- error- ? "border-red-400 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"- : "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-[var(--brand)] focus:ring-[var(--brand)]",- )}- {...register(keyPath, {- required: requiredFieldRule(field.required),- })}- />- </FormControl>- );-}