Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
Add phone number support for custom fields in access form
Cursor Agent555c291981e4
diff --git a/components/links/link-sheet/custom-fields-panel/custom-field.tsx b/components/links/link-sheet/custom-fields-panel/custom-field.tsxindex 73a82f0f..86830571 100644--- a/components/links/link-sheet/custom-fields-panel/custom-field.tsx+++ b/components/links/link-sheet/custom-fields-panel/custom-field.tsx@@ -100,7 +100,7 @@ export default memo(function CustomField({<SelectItem value="SHORT_TEXT">Short Text</SelectItem><SelectItem value="LONG_TEXT">Long Text</SelectItem><SelectItem value="NUMBER">Number</SelectItem>- {/* <SelectItem value="PHONE_NUMBER">Phone</SelectItem> */}+ <SelectItem value="PHONE_NUMBER">Phone</SelectItem><SelectItem value="URL">URL</SelectItem></SelectContent></Select>diff --git a/components/links/link-sheet/custom-fields-panel/index.tsx b/components/links/link-sheet/custom-fields-panel/index.tsxindex 80c88c4a..56866e36 100644--- a/components/links/link-sheet/custom-fields-panel/index.tsx+++ b/components/links/link-sheet/custom-fields-panel/index.tsx@@ -24,7 +24,7 @@ export type CustomFieldData = Omit<> & {type: Omit<CustomFieldType,- "PHONE_NUMBER" | "CHECKBOX" | "SELECT" | "MULTI_SELECT"+ "CHECKBOX" | "SELECT" | "MULTI_SELECT">;};diff --git a/components/view/access-form/custom-fields-section.tsx b/components/view/access-form/custom-fields-section.tsxindex 9cd9bd72..e8949298 100644--- a/components/view/access-form/custom-fields-section.tsx+++ b/components/view/access-form/custom-fields-section.tsx@@ -1,6 +1,8 @@import { Brand, CustomField, DataroomBrand } from "@prisma/client";+import { E164Number } from "libphonenumber-js";import { Input } from "@/components/ui/input";+import { PhoneInput } from "@/components/ui/phone-input";import { Textarea } from "@/components/ui/textarea";import { cn } from "@/lib/utils";@@ -24,6 +26,10 @@ export default function CustomFieldsSection({setData({ ...data, [identifier]: e.target.value });};+ const handlePhoneChange = (value: E164Number | null, identifier: string) => {+ setData({ ...data, [identifier]: value || "" });+ };+if (!fields?.length) return null;return (@@ -33,7 +39,7 @@ export default function CustomFieldsSection({const value = data[field.identifier] || "";const isLongText = field.type === "LONG_TEXT";- const InputComponent = isLongText ? Textarea : Input;+ const isPhoneNumber = field.type === "PHONE_NUMBER";return (<div key={field.identifier} className="relative space-y-2">@@ -46,42 +52,65 @@ export default function CustomFieldsSection({>{field.label}</label>- <InputComponent- name={field.identifier || ""}- id={field.id || ""}- type={- field.type === "NUMBER"- ? "number"- : field.type === "URL"- ? "url"- : "text"- }- pattern={field.type === "URL" ? "https://.*" : undefined}- onInvalid={(e) => {- if (field.type === "URL") {- e.currentTarget.setCustomValidity(- "Please enter a valid URL starting with https://",- );- }- }}- onInput={(e) => e.currentTarget.setCustomValidity("")}- autoComplete="off"- data-1p-ignore- required={field.required}- disabled={field.disabled}- className={cn(- "flex w-full rounded-md border-0 bg-black py-1.5 text-gray-500 shadow-sm ring-1 ring-inset ring-gray-600 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-gray-300 sm:text-sm sm:leading-6",- isLongText && "min-h-[100px] resize-none",- )}- style={{- backgroundColor:- brand && brand.accentColor ? brand.accentColor : "black",- color: determineTextColor(brand?.accentColor),- }}- value={value}- placeholder={field.placeholder || ""}- onChange={(e) => handleInputChange(e, field.identifier!)}- />+ {isPhoneNumber ? (+ <PhoneInput+ value={value as E164Number}+ onChange={(phoneValue) => handlePhoneChange(phoneValue, field.identifier!)}+ placeholder={field.placeholder || "+1 123 456 7890"}+ defaultCountry="US"+ disabled={field.disabled}+ className={cn(+ "flex w-full rounded-md border-0 bg-black py-1.5 text-gray-500 shadow-sm ring-1 ring-inset ring-gray-600 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-gray-300 sm:text-sm sm:leading-6",+ )}+ style={{+ backgroundColor:+ brand && brand.accentColor ? brand.accentColor : "black",+ color: determineTextColor(brand?.accentColor),+ }}+ />+ ) : (+ (() => {+ const InputComponent = isLongText ? Textarea : Input;+ return (+ <InputComponent+ name={field.identifier || ""}+ id={field.id || ""}+ type={+ field.type === "NUMBER"+ ? "number"+ : field.type === "URL"+ ? "url"+ : "text"+ }+ pattern={field.type === "URL" ? "https://.*" : undefined}+ onInvalid={(e) => {+ if (field.type === "URL") {+ e.currentTarget.setCustomValidity(+ "Please enter a valid URL starting with https://",+ );+ }+ }}+ onInput={(e) => e.currentTarget.setCustomValidity("")}+ autoComplete="off"+ data-1p-ignore+ required={field.required}+ disabled={field.disabled}+ className={cn(+ "flex w-full rounded-md border-0 bg-black py-1.5 text-gray-500 shadow-sm ring-1 ring-inset ring-gray-600 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-gray-300 sm:text-sm sm:leading-6",+ isLongText && "min-h-[100px] resize-none",+ )}+ style={{+ backgroundColor:+ brand && brand.accentColor ? brand.accentColor : "black",+ color: determineTextColor(brand?.accentColor),+ }}+ value={value}+ placeholder={field.placeholder || ""}+ onChange={(e) => handleInputChange(e, field.identifier!)}+ />+ );+ })()+ )}</div>);})}