Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: create custom fields on links

Marc Seitzf79c0bcb83ea
diff --git a/components/links/link-sheet/custom-fields-panel/custom-field.tsx b/components/links/link-sheet/custom-fields-panel/custom-field.tsx
new file mode 100644
index 00000000..2a6d565b
--- /dev/null
+++ b/components/links/link-sheet/custom-fields-panel/custom-field.tsx
@@ -0,0 +1,169 @@
+import { useEffect, useState } from "react";
+
+import { ChevronDown, ChevronUp, Trash2 } from "lucide-react";
+
+import { Button } from "@/components/ui/button";
+import { Input } from "@/components/ui/input";
+import { Label } from "@/components/ui/label";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
+import { Switch } from "@/components/ui/switch";
+
+import { type CustomFieldData } from ".";
+
+interface CustomFieldProps {
+ field: CustomFieldData;
+ onUpdate: (field: CustomFieldData) => void;
+ onDelete: () => void;
+ onMoveUp?: () => void;
+ onMoveDown?: () => void;
+ isFirst?: boolean;
+ isLast?: boolean;
+}
+
+export default function CustomField({
+ field,
+ onUpdate,
+ onDelete,
+ onMoveUp,
+ onMoveDown,
+ isFirst,
+ isLast,
+}: CustomFieldProps) {
+ const [localField, setLocalField] = useState<CustomFieldData>(field);
+
+ useEffect(() => {
+ onUpdate(localField);
+ }, [localField, onUpdate]);
+
+ const handleInputChange = (
+ e: React.ChangeEvent<HTMLInputElement>,
+ key: keyof CustomFieldData,
+ ) => {
+ if (key === "label") {
+ setLocalField((prev) => ({
+ ...prev,
+ [key]: e.target.value,
+ identifier: e.target.value.toLowerCase().replace(/[^a-z0-9-]/g, "-"),
+ }));
+ } else {
+ setLocalField((prev) => ({
+ ...prev,
+ [key]: e.target.value,
+ }));
+ }
+ };
+
+ const handleSelectChange = (value: string, key: keyof CustomFieldData) => {
+ setLocalField((prev) => ({
+ ...prev,
+ [key]: value,
+ }));
+ };
+
+ const handleSwitchChange = (checked: boolean, key: keyof CustomFieldData) => {
+ setLocalField((prev) => ({
+ ...prev,
+ [key]: checked,
+ }));
+ };
+
+ return (
+ <div className="group relative flex flex-col space-y-4 rounded-lg border border-border bg-card p-4">
+ <div className="absolute -right-2 -top-2 hidden group-hover:block">
+ <Button
+ variant="ghost"
+ size="icon"
+ className="h-8 w-8 bg-background text-muted-foreground hover:bg-background hover:text-destructive"
+ onClick={onDelete}
+ >
+ <Trash2 className="h-4 w-4" />
+ </Button>
+ </div>
+
+ <div className="grid gap-4">
+ <div className="grid gap-2">
+ <Label htmlFor="type">Input Type</Label>
+ <Select
+ value={localField.type}
+ onValueChange={(value) => handleSelectChange(value, "type")}
+ >
+ <SelectTrigger>
+ <SelectValue placeholder="Select field type" />
+ </SelectTrigger>
+ <SelectContent>
+ <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="URL">URL</SelectItem>
+ </SelectContent>
+ </Select>
+ </div>
+
+ <div className="grid gap-2">
+ <Label htmlFor="label">Label</Label>
+ <Input
+ id="label"
+ type="text"
+ required
+ value={localField.label}
+ onChange={(e) => handleInputChange(e, "label")}
+ placeholder="e.g., Company Name"
+ />
+ </div>
+
+ {/* <div className="grid gap-2">
+ <Label htmlFor="identifier">Identifier</Label>
+ <Input
+ id="identifier"
+ value={localField.identifier}
+ type="text"
+ disabled
+ onChange={(e) => {
+ const value = e.target.value
+ .toLowerCase()
+ .replace(/[^a-z0-9-]/g, "-");
+ handleInputChange(
+ { ...e, target: { ...e.target, value } },
+ "identifier",
+ );
+ }}
+ placeholder="e.g., company-name"
+ />
+ </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>
+
+ <div className="flex items-center justify-between">
+ <div className="flex flex-col space-y-1">
+ <Label>Required Field</Label>
+ <span className="text-sm text-muted-foreground">
+ Make this field mandatory
+ </span>
+ </div>
+ <Switch
+ checked={localField.required}
+ onCheckedChange={(checked) =>
+ handleSwitchChange(checked, "required")
+ }
+ />
+ </div>
+ </div>
+ </div>
+ );
+}
diff --git a/components/links/link-sheet/custom-fields-panel/index.tsx b/components/links/link-sheet/custom-fields-panel/index.tsx
new file mode 100644
index 00000000..a8274873
--- /dev/null
+++ b/components/links/link-sheet/custom-fields-panel/index.tsx
@@ -0,0 +1,164 @@
+import { CustomField, CustomFieldType } from "@prisma/client";
+import { Plus } from "lucide-react";
+import { toast } from "sonner";
+
+import { Button } from "@/components/ui/button";
+import { ScrollArea } from "@/components/ui/scroll-area";
+import { Separator } from "@/components/ui/separator";
+import {
+ Sheet,
+ SheetContent,
+ SheetDescription,
+ SheetHeader,
+ SheetTitle,
+} from "@/components/ui/sheet";
+
+import { usePlan } from "@/lib/swr/use-billing";
+
+import CustomFieldComponent from "./custom-field";
+
+export type CustomFieldData = Omit<
+ CustomField,
+ "id" | "createdAt" | "updatedAt" | "linkId"
+> & {
+ type: Omit<
+ CustomFieldType,
+ "PHONE_NUMBER" | "CHECKBOX" | "SELECT" | "MULTI_SELECT"
+ >;
+};
+
+export default function CustomFieldsPanel({
+ fields,
+ onChange,
+ isConfigOpen,
+ setIsConfigOpen,
+}: {
+ fields: CustomFieldData[];
+ onChange: (fields: CustomFieldData[]) => void;
+ isConfigOpen: boolean;
+ setIsConfigOpen: (open: boolean) => void;
+}) {
+ const { plan } = usePlan();
+
+ const getFieldLimit = () => {
+ if (plan === "datarooms") return 3;
+ if (plan === "business") return 1;
+ return 0;
+ };
+
+ const addField = () => {
+ const fieldLimit = getFieldLimit();
+ if (fields.length >= fieldLimit) {
+ toast.error(
+ `You can only add up to ${fieldLimit} custom field${fieldLimit === 1 ? "" : "s"} on the ${plan === "datarooms" ? "Data Rooms" : "Business"} plan`,
+ );
+ return;
+ }
+
+ const newField: CustomFieldData = {
+ type: "SHORT_TEXT",
+ identifier: "",
+ label: "",
+ placeholder: "",
+ required: false,
+ disabled: false,
+ orderIndex: fields.length,
+ };
+ onChange([...fields, newField]);
+ };
+
+ const updateField = (index: number, updatedField: CustomFieldData) => {
+ const newFields = [...fields];
+ newFields[index] = updatedField;
+ onChange(newFields);
+ };
+
+ const removeField = (index: number) => {
+ const newFields = fields.filter((_, i) => i !== index);
+ // Update orderIndex for remaining fields
+ newFields.forEach((field, i) => {
+ field.orderIndex = i;
+ });
+ onChange(newFields);
+ };
+
+ const moveField = (index: number, direction: "up" | "down") => {
+ if (
+ (direction === "up" && index === 0) ||
+ (direction === "down" && index === fields.length - 1)
+ )
+ return;
+
+ const newFields = [...fields];
+ const newIndex = direction === "up" ? index - 1 : index + 1;
+ [newFields[index], newFields[newIndex]] = [
+ newFields[newIndex],
+ newFields[index],
+ ];
+
+ // Update orderIndex for all fields
+ newFields.forEach((field, i) => {
+ field.orderIndex = i;
+ });
+
+ onChange(newFields);
+ };
+
+ const fieldLimit = getFieldLimit();
+
+ return (
+ <Sheet open={isConfigOpen} onOpenChange={setIsConfigOpen}>
+ <SheetContent className="flex h-full flex-col">
+ <SheetHeader>
+ <SheetTitle>Configure Custom Fields</SheetTitle>
+ <SheetDescription>
+ Configure the custom fields that will be shown to viewers.
+ {fieldLimit > 0 && (
+ <span className="mt-1 block text-sm text-muted-foreground">
+ You can add up to {fieldLimit} custom field
+ {fieldLimit === 1 ? "" : "s"} on the{" "}
+ {plan === "datarooms" ? "Data Rooms" : "Business"} plan.
+ </span>
+ )}
+ </SheetDescription>
+ </SheetHeader>
+
+ <div className="flex items-center justify-between">
+ <div className="text-sm text-muted-foreground">
+ {fields.length} of {fieldLimit} custom field
+ {fields.length === 1 ? "" : "s"}
+ </div>
+ <Button
+ variant="outline"
+ size="sm"
+ onClick={addField}
+ className="flex items-center gap-2"
+ disabled={fields.length >= fieldLimit}
+ >
+ <Plus className="h-4 w-4" />
+ Add Field
+ </Button>
+ </div>
+
+ <Separator />
+
+ <ScrollArea className="flex-1">
+ <div className="space-y-4">
+ {fields.map((field, index) => (
+ <CustomFieldComponent
+ key={index}
+ field={field}
+ onUpdate={(updatedField) => updateField(index, updatedField)}
+ onDelete={() => removeField(index)}
+ onMoveUp={() => moveField(index, "up")}
+ onMoveDown={() => moveField(index, "down")}
+ isFirst={index === 0}
+ isLast={index === fields.length - 1}
+ />
+ ))}
+ </div>
+ </ScrollArea>
+ </SheetContent>
+ </Sheet>
+ );
+}
diff --git a/components/links/link-sheet/custom-fields-section.tsx b/components/links/link-sheet/custom-fields-section.tsx
new file mode 100644
index 00000000..9a44ceb1
--- /dev/null
+++ b/components/links/link-sheet/custom-fields-section.tsx
@@ -0,0 +1,124 @@
+import { useEffect, useState } from "react";
+
+import { SettingsIcon } from "lucide-react";
+import { motion } from "motion/react";
+
+import { DEFAULT_LINK_TYPE } from "@/components/links/link-sheet";
+import { Button } from "@/components/ui/button";
+
+import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/constants";
+
+import { CustomFieldData } from "./custom-fields-panel";
+import CustomFieldsPanel from "./custom-fields-panel";
+import LinkItem from "./link-item";
+import { LinkUpgradeOptions } from "./link-options";
+
+export default function CustomFieldsSection({
+ data,
+ setData,
+ isAllowed,
+ handleUpgradeStateChange,
+}: {
+ data: DEFAULT_LINK_TYPE;
+ setData: React.Dispatch<React.SetStateAction<DEFAULT_LINK_TYPE>>;
+ isAllowed: boolean;
+ handleUpgradeStateChange: (options: LinkUpgradeOptions) => void;
+}) {
+ const [enabled, setEnabled] = useState<boolean>(false);
+ const [isConfigOpen, setIsConfigOpen] = useState<boolean>(false);
+
+ useEffect(() => {
+ setEnabled(data.customFields.length > 0);
+ }, [data.customFields]);
+
+ const handleCustomFieldsToggle = () => {
+ const updatedEnabled = !enabled;
+ setData({
+ ...data,
+ customFields: updatedEnabled
+ ? [
+ {
+ type: "SHORT_TEXT",
+ identifier: "",
+ label: "",
+ placeholder: "",
+ required: false,
+ disabled: false,
+ orderIndex: 0,
+ },
+ ]
+ : [],
+ });
+ setEnabled(updatedEnabled);
+ };
+
+ const handleConfigSave = (fields: CustomFieldData[]) => {
+ setData({
+ ...data,
+ customFields: fields,
+ });
+ };
+
+ return (
+ <div className="pb-5">
+ <LinkItem
+ title="Custom Fields"
+ tooltipContent="Add custom fields to collect additional information from viewers"
+ enabled={enabled}
+ action={handleCustomFieldsToggle}
+ isAllowed={isAllowed}
+ requiredPlan="business"
+ upgradeAction={() =>
+ handleUpgradeStateChange({
+ state: true,
+ trigger: "custom_fields",
+ plan: "Business",
+ })
+ }
+ />
+
+ {enabled && (
+ <motion.div
+ className="relative mt-4 space-y-3"
+ {...FADE_IN_ANIMATION_SETTINGS}
+ >
+ <div className="mt-2 flex w-full items-center justify-between">
+ <div className="space-y-1">
+ {data.customFields.map((field) => (
+ <p
+ key={field.identifier || field.orderIndex}
+ className="text-sm text-muted-foreground"
+ >
+ {field.orderIndex + 1}. {field.label || "Untitled Field"}
+ {field.required && (
+ <span className="italic"> (required)</span>
+ )}
+ </p>
+ ))}
+ </div>
+ <Button
+ onClick={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ setIsConfigOpen(true);
+ }}
+ variant="outline"
+ className="h-8"
+ size="sm"
+ >
+ <SettingsIcon className="mr-2 h-4 w-4" />
+ Configure
+ </Button>
+ </div>
+ </motion.div>
+ )}
+
+ <CustomFieldsPanel
+ fields={data.customFields}
+ onChange={handleConfigSave}
+ isConfigOpen={isConfigOpen}
+ setIsConfigOpen={setIsConfigOpen}
+ />
+ </div>
+ );
+}
diff --git a/components/links/link-sheet/index.tsx b/components/links/link-sheet/index.tsx
index 7f35deb6..243ceaf9 100644
--- a/components/links/link-sheet/index.tsx
+++ b/components/links/link-sheet/index.tsx
@@ -38,6 +38,7 @@ import { useDomains } from "@/lib/swr/use-domains";
import { LinkWithViews, WatermarkConfig } from "@/lib/types";
import { convertDataUrlToFile, uploadImage } from "@/lib/utils";
+import { CustomFieldData } from "./custom-fields-panel";
import DomainSection from "./domain-section";
import { LinkOptions } from "./link-options";
@@ -72,6 +73,7 @@ export const DEFAULT_LINK_PROPS = (linkType: LinkType) => ({
audienceType: LinkAudienceType.GENERAL,
groupId: null,
screenShieldPercentage: null,
+ customFields: [],
});
export type DEFAULT_LINK_TYPE = {
@@ -105,6 +107,7 @@ export type DEFAULT_LINK_TYPE = {
audienceType: LinkAudienceType;
groupId: string | null;
screenShieldPercentage: number | null;
+ customFields: CustomFieldData[];
};
export default function LinkSheet({
@@ -133,6 +136,7 @@ export default function LinkSheet({
DEFAULT_LINK_PROPS(linkType),
);
const [isLoading, setIsLoading] = useState<boolean>(false);
+ const [isSaving, setIsSaving] = useState<boolean>(false);
const router = useRouter();
const targetId = router.query.id as string;
@@ -141,10 +145,36 @@ export default function LinkSheet({
setData(currentLink || DEFAULT_LINK_PROPS(linkType));
}, [currentLink]);
- const handleSubmit = async (event: any) => {
- event.preventDefault();
+ const handlePreviewLink = async (link: LinkWithViews) => {
+ if (link.domainId && plan === "free") {
+ toast.error("You need to upgrade to preview this link");
+ return;
+ }
setIsLoading(true);
+ const response = await fetch(`/api/links/${link.id}/preview`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ });
+
+ if (!response.ok) {
+ toast.error("Failed to generate preview link");
+ setIsLoading(false);
+ return;
+ }
+
+ const { previewToken } = await response.json();
+ const previewLink = `${process.env.NEXT_PUBLIC_MARKETING_URL}/view/${link.id}?previewToken=${previewToken}`;
+ setIsLoading(false);
+ window.open(previewLink, "_blank");
+ };
+
+ const handleSubmit = async (event: any, shouldPreview: boolean = false) => {
+ event.preventDefault();
+
+ setIsSaving(true);
// Upload the image if it's a data URL
let blobUrl: string | null =
@@ -201,7 +231,7 @@ export default function LinkSheet({
// handle error with toast message
const { error } = await response.json();
toast.error(error);
- setIsLoading(false);
+ setIsSaving(false);
return;
}
@@ -243,7 +273,11 @@ export default function LinkSheet({
}
setData(DEFAULT_LINK_PROPS(linkType));
- setIsLoading(false);
+ setIsSaving(false);
+
+ if (shouldPreview) {
+ await handlePreviewLink(returnedLink);
+ }
};
return (
@@ -257,7 +291,10 @@ export default function LinkSheet({
</SheetTitle>
</SheetHeader>
- <form className="flex grow flex-col" onSubmit={handleSubmit}>
+ <form
+ className="flex grow flex-col"
+ onSubmit={(e) => handleSubmit(e, false)}
+ >
<ScrollArea className="flex-grow">
<div className="h-0 flex-1">
<div className="flex flex-1 flex-col justify-between">
@@ -457,10 +494,22 @@ export default function LinkSheet({
</ScrollArea>
<SheetFooter>
- <div className="flex items-center pt-2">
- <Button type="submit" loading={isLoading}>
+ <div className="flex flex-row-reverse items-center gap-2 pt-2">
+ <Button
+ type="submit"
+ loading={isSaving}
+ onClick={(e) => handleSubmit(e, false)}
+ >
{currentLink ? "Update Link" : "Save Link"}
</Button>
+ <Button
+ type="button"
+ variant="outline"
+ loading={isLoading}
+ onClick={(e) => handleSubmit(e, true)}
+ >
+ {currentLink ? "Update & Preview" : "Save & Preview"}
+ </Button>
</div>
</SheetFooter>
</form>
diff --git a/components/links/link-sheet/link-options.tsx b/components/links/link-sheet/link-options.tsx
index d377898e..4110ef59 100644
--- a/components/links/link-sheet/link-options.tsx
+++ b/components/links/link-sheet/link-options.tsx
@@ -20,6 +20,7 @@ import { usePlan } from "@/lib/swr/use-billing";
import useLimits from "@/lib/swr/use-limits";
import AgreementSection from "./agreement-section";
+import CustomFieldsSection from "./custom-fields-section";
import QuestionSection from "./question-section";
import ScreenShieldSection from "./screen-shield-section";
import ScreenshotProtectionSection from "./screenshot-protection-section";
@@ -156,6 +157,11 @@ export const LinkOptions = ({
}
handleUpgradeStateChange={handleUpgradeStateChange}
/>
+ <CustomFieldsSection
+ {...{ data, setData }}
+ isAllowed={isTrial || isBusiness || isDatarooms}
+ handleUpgradeStateChange={handleUpgradeStateChange}
+ />
{linkType === LinkType.DOCUMENT_LINK ? (
<ProBannerSection
{...{ data, setData }}
diff --git a/components/links/links-table.tsx b/components/links/links-table.tsx
index 27bd137a..ab2d40a4 100644
--- a/components/links/links-table.tsx
+++ b/components/links/links-table.tsx
@@ -135,6 +135,7 @@ export default function LinksTable({
audienceType: link.audienceType,
groupId: link.groupId,
screenShieldPercentage: link.screenShieldPercentage,
+ customFields: link.customFields || [],
});
//wait for dropdown to close before opening the link sheet
setTimeout(() => {
diff --git a/lib/types.ts b/lib/types.ts
index cab3e01f..267be04f 100644
--- a/lib/types.ts
+++ b/lib/types.ts
@@ -1,5 +1,6 @@
import {
Agreement,
+ CustomField,
Dataroom,
DataroomDocument,
DataroomFolder,
@@ -41,6 +42,7 @@ export interface LinkWithViews extends Link {
};
views: View[];
feedback: { id: true; data: { question: string; type: string } } | null;
+ customFields: CustomField[];
}
export interface LinkWithDocument extends Link {
@@ -65,6 +67,7 @@ export interface LinkWithDocument extends Link {
};
} | null;
agreement: Agreement | null;
+ customFields: CustomField[];
}
export interface LinkWithDataroom extends Link {
@@ -93,6 +96,7 @@ export interface LinkWithDataroom extends Link {
lastUpdatedAt: Date;
};
agreement: Agreement | null;
+ customFields: CustomField[];
}
export interface Geo {
diff --git a/pages/api/links/[id]/index.ts b/pages/api/links/[id]/index.ts
index 1e20cbdb..d27be277 100644
--- a/pages/api/links/[id]/index.ts
+++ b/pages/api/links/[id]/index.ts
@@ -248,6 +248,23 @@ export default async function handle(
metaDescription: linkData.metaDescription || null,
metaImage: linkData.metaImage || null,
metaFavicon: linkData.metaFavicon || null,
+ ...(linkData.customFields && {
+ customFields: {
+ deleteMany: {}, // Delete all existing custom fields
+ createMany: {
+ data: linkData.customFields.map((field: any, index: number) => ({
+ type: field.type,
+ identifier: field.identifier,
+ label: field.label,
+ placeholder: field.placeholder,
+ required: field.required,
+ disabled: field.disabled,
+ orderIndex: index,
+ })),
+ skipDuplicates: true,
+ },
+ },
+ }),
enableQuestion: linkData.enableQuestion,
...(linkData.enableQuestion && {
feedback: {
diff --git a/pages/api/links/index.ts b/pages/api/links/index.ts
index 499c510d..5b3738d8 100644
--- a/pages/api/links/index.ts
+++ b/pages/api/links/index.ts
@@ -165,6 +165,23 @@ export default async function handler(
watermarkConfig: linkData.watermarkConfig,
}),
showBanner: linkData.showBanner,
+ ...(linkData.customFields && {
+ customFields: {
+ createMany: {
+ data: linkData.customFields.map(
+ (field: any, index: number) => ({
+ type: field.type,
+ identifier: field.identifier,
+ label: field.label,
+ placeholder: field.placeholder,
+ required: field.required,
+ disabled: field.disabled,
+ orderIndex: index,
+ }),
+ ),
+ },
+ },
+ }),
},
});
diff --git a/pages/api/teams/[teamId]/documents/[id]/links.ts b/pages/api/teams/[teamId]/documents/[id]/links.ts
index 65077b05..6c5e541b 100644
--- a/pages/api/teams/[teamId]/documents/[id]/links.ts
+++ b/pages/api/teams/[teamId]/documents/[id]/links.ts
@@ -50,6 +50,19 @@ export default async function handle(
data: true,
},
},
+ customFields: {
+ select: {
+ orderIndex: true,
+ label: true,
+ identifier: true,
+ placeholder: true,
+ type: true,
+ required: true,
+ },
+ orderBy: {
+ orderIndex: "asc",
+ },
+ },
_count: {
select: { views: true },
},
diff --git a/prisma/migrations/20250113000000_add_custom_fields/migration.sql b/prisma/migrations/20250113000000_add_custom_fields/migration.sql
new file mode 100644
index 00000000..a12ee957
--- /dev/null
+++ b/prisma/migrations/20250113000000_add_custom_fields/migration.sql
@@ -0,0 +1,46 @@
+-- CreateEnum
+CREATE TYPE "CustomFieldType" AS ENUM ('SHORT_TEXT', 'LONG_TEXT', 'NUMBER', 'PHONE_NUMBER', 'URL', 'CHECKBOX', 'SELECT', 'MULTI_SELECT');
+
+-- CreateTable
+CREATE TABLE "CustomField" (
+ "id" TEXT NOT NULL,
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "updatedAt" TIMESTAMP(3) NOT NULL,
+ "type" "CustomFieldType" NOT NULL,
+ "identifier" TEXT NOT NULL,
+ "label" TEXT NOT NULL,
+ "placeholder" TEXT,
+ "required" BOOLEAN NOT NULL DEFAULT false,
+ "disabled" BOOLEAN NOT NULL DEFAULT false,
+ "linkId" TEXT NOT NULL,
+ "orderIndex" INTEGER NOT NULL DEFAULT 0,
+
+ CONSTRAINT "CustomField_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateTable
+CREATE TABLE "CustomFieldResponse" (
+ "id" TEXT NOT NULL,
+ "data" JSONB NOT NULL,
+ "viewId" TEXT NOT NULL,
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "updatedAt" TIMESTAMP(3) NOT NULL,
+
+ CONSTRAINT "CustomFieldResponse_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateIndex
+CREATE INDEX "CustomField_linkId_idx" ON "CustomField"("linkId");
+
+-- CreateIndex
+CREATE UNIQUE INDEX "CustomFieldResponse_viewId_key" ON "CustomFieldResponse"("viewId");
+
+-- CreateIndex
+CREATE INDEX "CustomFieldResponse_viewId_idx" ON "CustomFieldResponse"("viewId");
+
+-- AddForeignKey
+ALTER TABLE "CustomField" ADD CONSTRAINT "CustomField_linkId_fkey" FOREIGN KEY ("linkId") REFERENCES "Link"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "CustomFieldResponse" ADD CONSTRAINT "CustomFieldResponse_viewId_fkey" FOREIGN KEY ("viewId") REFERENCES "View"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index d5b96e99..be17e274 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -89,7 +89,7 @@ model Team {
incomingWebhooks IncomingWebhook[]
restrictedTokens RestrictedToken[]
- webhooks Webhook[]
+ webhooks Webhook[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -279,6 +279,8 @@ model Link {
teamId String?
team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)
+ customFields CustomField[]
+
@@unique([domainSlug, slug])
@@index([documentId])
@@index([teamId])
@@ -342,6 +344,7 @@ model View {
group ViewerGroup? @relation(fields: [groupId], references: [id], onDelete: SetNull)
feedbackResponse FeedbackResponse?
agreementResponse AgreementResponse?
+ customFieldResponse CustomFieldResponse?
isArchived Boolean @default(false) // Indicates if the view is archived and not counted in the analytics
@@ -365,7 +368,7 @@ model Viewer {
email String
verified Boolean @default(false) // Whether the viewer email has been verified
invitedAt DateTime? // This is the time the viewer was invited
- notificationPreferences Json? // Format: { dataroom: {"dr_123": { "enabled": false }, "dr_456": { "enabled": true } } }
+ notificationPreferences Json? // Format: { dataroom: {"dr_123": { "enabled": false }, "dr_456": { "enabled": true } } } }
dataroomId String?
dataroom Dataroom? @relation(fields: [dataroomId], references: [id], onDelete: SetNull)
@@ -696,15 +699,15 @@ model RestrictedToken {
}
model Webhook {
- id String @id @default(cuid())
- pId String @unique // public ID for the webhook
- name String
- url String
- secret String // signing secret for the webhook
- triggers Json
+ id String @id @default(cuid())
+ pId String @unique // public ID for the webhook
+ name String
+ url String
+ secret String // signing secret for the webhook
+ triggers Json
- teamId String
- team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
+ teamId String
+ team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -712,12 +715,11 @@ model Webhook {
@@index([teamId])
}
-
model YearInReview {
- id String @id @default(cuid())
- teamId String
- status String @default("pending") // pending, processing, completed, failed
- attempts Int @default(0)
+ id String @id @default(cuid())
+ teamId String
+ status String @default("pending") // pending, processing, completed, failed
+ attempts Int @default(0)
lastAttempted DateTime?
error String?
@@ -729,3 +731,42 @@ model YearInReview {
@@index([status, attempts])
@@index([teamId])
}
+
+enum CustomFieldType {
+ SHORT_TEXT
+ LONG_TEXT
+ NUMBER
+ PHONE_NUMBER
+ URL
+ CHECKBOX
+ SELECT
+ MULTI_SELECT
+}
+
+model CustomField {
+ id String @id @default(cuid())
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+ type CustomFieldType
+ identifier String
+ label String
+ placeholder String?
+ required Boolean @default(false)
+ disabled Boolean @default(false)
+ link Link @relation(fields: [linkId], references: [id], onDelete: Cascade)
+ linkId String
+ orderIndex Int @default(0)
+
+ @@index([linkId])
+}
+
+model CustomFieldResponse {
+ id String @id @default(cuid())
+ data Json // Store the custom field responses as a JSON object [{ "identifier": "value", "label": "value", "response:" }]
+ viewId String @unique
+ view View @relation(fields: [viewId], references: [id], onDelete: Cascade)
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+
+ @@index([viewId])
+}