Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Add URL field type to the submitted lead form

Rafi95868a6b4792
diff --git a/apps/web/lib/zod/schemas/submitted-lead-form.ts b/apps/web/lib/zod/schemas/submitted-lead-form.ts
index ad5351955c..ce46b0f854 100644
--- a/apps/web/lib/zod/schemas/submitted-lead-form.ts
+++ b/apps/web/lib/zod/schemas/submitted-lead-form.ts
@@ -9,6 +9,7 @@ const fieldTypeSchema = z.enum([
"multiSelect",
"number",
"phone",
+ "url",
]);
export const fieldCommonSchema = z.object({
@@ -77,6 +78,11 @@ export const phoneFieldSchema = fieldCommonSchema.extend({
type: z.literal("phone"),
});
+// URL
+export const urlFieldSchema = fieldCommonSchema.extend({
+ type: z.literal("url"),
+});
+
export const formFieldSchema = z.discriminatedUnion("type", [
textFieldSchema,
textareaFieldSchema,
@@ -86,6 +92,7 @@ export const formFieldSchema = z.discriminatedUnion("type", [
multiSelectFieldSchema,
numberFieldSchema,
phoneFieldSchema,
+ urlFieldSchema,
]);
export const formFieldsSchema = z
diff --git a/apps/web/ui/submitted-leads/form-fields/index.tsx b/apps/web/ui/submitted-leads/form-fields/index.tsx
index e17f563a66..9f9448a4ff 100644
--- a/apps/web/ui/submitted-leads/form-fields/index.tsx
+++ b/apps/web/ui/submitted-leads/form-fields/index.tsx
@@ -8,6 +8,7 @@ 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">,
@@ -20,6 +21,7 @@ const FIELD_COMPONENTS: Record<
multiSelect: MultiSelectField,
number: NumberField,
phone: PhoneField,
+ url: UrlField,
};
interface LeadFormFieldProps {
diff --git a/apps/web/ui/submitted-leads/form-fields/url-field.tsx b/apps/web/ui/submitted-leads/form-fields/url-field.tsx
new file mode 100644
index 0000000000..0c8f4509a6
--- /dev/null
+++ b/apps/web/ui/submitted-leads/form-fields/url-field.tsx
@@ -0,0 +1,47 @@
+import { urlFieldSchema } from "@/lib/zod/schemas/submitted-lead-form";
+import { cn, isValidUrl } from "@dub/utils";
+import { useFormContext } from "react-hook-form";
+import * as z from "zod/v4";
+import { FormControl } from "./form-control";
+
+type UrlFieldData = z.infer<typeof urlFieldSchema>;
+
+export function UrlField({
+ keyPath: keyPathProp,
+ field,
+}: {
+ keyPath?: string;
+ field: UrlFieldData;
+}) {
+ const { register, getFieldState } = useFormContext<any>();
+ const keyPath = keyPathProp || `formData.${field.key}`;
+ const state = getFieldState(keyPath);
+ const error = !!state.error;
+
+ return (
+ <FormControl
+ label={field.label}
+ required={field.required}
+ error={state.error?.message}
+ labelDir="auto"
+ >
+ <input
+ type="url"
+ placeholder="https://"
+ 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: field.required,
+ validate: (value: string) => {
+ if (!value) return true;
+ return isValidUrl(value) || "Please enter a valid URL";
+ },
+ })}
+ />
+ </FormControl>
+ );
+}