Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add checkbox to custom form field
Marc Seitz53edd0362218
diff --git a/components/links/link-sheet/custom-fields-panel/custom-field.tsx b/components/links/link-sheet/custom-fields-panel/custom-field.tsxindex 86830571..a94f271e 100644--- a/components/links/link-sheet/custom-fields-panel/custom-field.tsx+++ b/components/links/link-sheet/custom-fields-panel/custom-field.tsx@@ -102,6 +102,7 @@ export default memo(function CustomField({<SelectItem value="NUMBER">Number</SelectItem><SelectItem value="PHONE_NUMBER">Phone</SelectItem><SelectItem value="URL">URL</SelectItem>+ <SelectItem value="CHECKBOX">Checkbox</SelectItem></SelectContent></Select></div>@@ -138,16 +139,18 @@ export default memo(function CustomField({/></div> */}- <div className="grid gap-2">- <Label htmlFor="placeholder">Placeholder</Label>- <Input- id="placeholder"- type="text"- value={localField.placeholder || ""}- onChange={(e) => handleInputChange(e, "placeholder")}- placeholder="e.g., Enter your company name"- />- </div>+ {localField.type !== "CHECKBOX" && (+ <div className="grid gap-2">+ <Label htmlFor="placeholder">Placeholder</Label>+ <Input+ id="placeholder"+ type="text"+ value={localField.placeholder || ""}+ onChange={(e) => handleInputChange(e, "placeholder")}+ placeholder="e.g., Enter your company name"+ />+ </div>+ )}<div className="flex items-center justify-between"><div className="flex flex-col space-y-1">diff --git a/components/view/access-form/custom-fields-section.tsx b/components/view/access-form/custom-fields-section.tsxindex ec8caeae..302f368b 100644--- a/components/view/access-form/custom-fields-section.tsx+++ b/components/view/access-form/custom-fields-section.tsx@@ -4,6 +4,7 @@ import { E164Number } from "libphonenumber-js";import { cn } from "@/lib/utils";import { determineTextColor } from "@/lib/utils/determine-text-color";+import { Checkbox } from "@/components/ui/checkbox";import { Input } from "@/components/ui/input";import { PhoneInput } from "@/components/ui/phone-input";import { Textarea } from "@/components/ui/textarea";@@ -30,6 +31,10 @@ export default function CustomFieldsSection({setData({ ...data, [identifier]: value || "" });};+ const handleCheckboxChange = (checked: boolean, identifier: string) => {+ setData({ ...data, [identifier]: String(checked) });+ };+if (!fields?.length) return null;return (@@ -40,19 +45,53 @@ export default function CustomFieldsSection({const value = data[field.identifier] || "";const isLongText = field.type === "LONG_TEXT";const isPhoneNumber = field.type === "PHONE_NUMBER";+ const isCheckbox = field.type === "CHECKBOX";return (<div key={field.identifier} className="relative space-y-2">- <label- htmlFor={field.identifier}- className="block text-sm font-medium leading-6 text-white"- style={{- color: determineTextColor(brand?.accentColor),- }}- >- {field.label}- </label>- {isPhoneNumber ? (+ {!isCheckbox && (+ <label+ htmlFor={field.identifier}+ className="block text-sm font-medium leading-6 text-white"+ style={{+ color: determineTextColor(brand?.accentColor),+ }}+ >+ {field.label}+ </label>+ )}+ {isCheckbox ? (+ <div className="flex items-center space-x-2">+ <Checkbox+ id={field.identifier}+ checked={value === "true"}+ onCheckedChange={(checked) =>+ handleCheckboxChange(!!checked, field.identifier!)+ }+ disabled={field.disabled}+ className={cn(+ "border-gray-600 data-[state=checked]:bg-gray-300 data-[state=checked]:text-black",+ )}+ style={{+ borderColor: brand?.accentColor+ ? determineTextColor(brand.accentColor)+ : undefined,+ }}+ />+ <label+ htmlFor={field.identifier}+ className="cursor-pointer text-sm font-medium leading-none text-white peer-disabled:cursor-not-allowed peer-disabled:opacity-70"+ style={{+ color: determineTextColor(brand?.accentColor),+ }}+ >+ {field.label}+ {field.required && (+ <span className="ml-1 text-red-500">*</span>+ )}+ </label>+ </div>+ ) : isPhoneNumber ? (<PhoneInputid={field.identifier}value={value as E164Number}diff --git a/components/view/access-form/index.tsx b/components/view/access-form/index.tsxindex 94512c2e..041de529 100644--- a/components/view/access-form/index.tsx+++ b/components/view/access-form/index.tsx@@ -88,8 +88,19 @@ export default function AccessForm({if (requireAgreement && requireName && !data.name) return false;if (customFields?.length) {for (const field of customFields) {- if (field.required && !data.customFields?.[field.identifier!]) {- return false;+ if (field.required) {+ const fieldValue = data.customFields?.[field.identifier!];+ // For checkbox fields, required means it must be checked (true)+ if (field.type === "CHECKBOX") {+ if (fieldValue !== "true") {+ return false;+ }+ } else {+ // For other field types, required means it must have a value+ if (!fieldValue) {+ return false;+ }+ }}}}diff --git a/lib/zod/schemas/presets.ts b/lib/zod/schemas/presets.tsindex b3dbbbf6..51b01d1b 100644--- a/lib/zod/schemas/presets.ts+++ b/lib/zod/schemas/presets.ts@@ -1,7 +1,14 @@import { z } from "zod";export const customFieldDataSchema = z.object({- type: z.enum(["SHORT_TEXT", "LONG_TEXT", "NUMBER", "URL"]),+ type: z.enum([+ "SHORT_TEXT",+ "LONG_TEXT",+ "NUMBER",+ "PHONE_NUMBER",+ "URL",+ "CHECKBOX",+ ]),identifier: z.string(),label: z.string(),placeholder: z.string().nullable().optional(),