Skip to content

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

feat: add agreement, custom fields to presets

Marc Seitzeb7300021def
diff --git a/components/links/link-sheet/agreement-section.tsx b/components/links/link-sheet/agreement-section.tsx
index b076bb53..5fbaa35a 100644
--- a/components/links/link-sheet/agreement-section.tsx
+++ b/components/links/link-sheet/agreement-section.tsx
@@ -1,7 +1,11 @@
-import { useEffect, useState, useMemo } from "react";
+import { useEffect, useMemo, useState } from "react";
+import { Agreement, LinkPreset } from "@prisma/client";
import { motion } from "motion/react";
+import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/constants";
+import { useAgreements } from "@/lib/swr/use-agreements";
+
import {
Select,
SelectContent,
@@ -10,14 +14,10 @@ import {
SelectValue,
} from "@/components/ui/select";
-import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/constants";
-import { useAgreements } from "@/lib/swr/use-agreements";
-
import { DEFAULT_LINK_TYPE } from ".";
import AgreementSheet from "./agreement-panel";
import LinkItem from "./link-item";
import { LinkUpgradeOptions } from "./link-options";
-import { Agreement } from "@prisma/client";
export default function AgreementSection({
data,
@@ -40,7 +40,14 @@ export default function AgreementSection({
const [isAgreementSheetVisible, setIsAgreementSheetVisible] =
useState<boolean>(false);
- const filteredAgreements = useMemo(() => agreements.filter((agreement: Agreement) => !agreement.deletedAt || agreement.id === agreementId), [agreements]);
+ const filteredAgreements = useMemo(
+ () =>
+ agreements.filter(
+ (agreement: Agreement) =>
+ !agreement.deletedAt || agreement.id === agreementId,
+ ),
+ [agreements],
+ );
useEffect(() => {
setEnabled(enableAgreement!);
diff --git a/components/links/link-sheet/custom-fields-section.tsx b/components/links/link-sheet/custom-fields-section.tsx
index 97a5db64..d840075d 100644
--- a/components/links/link-sheet/custom-fields-section.tsx
+++ b/components/links/link-sheet/custom-fields-section.tsx
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useMemo, useState } from "react";
-import { LinkPreset } from "@prisma/client";
+import { LinkPreset, Prisma } from "@prisma/client";
import { SettingsIcon } from "lucide-react";
import { motion } from "motion/react";
@@ -19,27 +19,17 @@ export default function CustomFieldsSection({
setData,
isAllowed,
handleUpgradeStateChange,
- // presets,
+ presets,
}: {
data: DEFAULT_LINK_TYPE;
setData: React.Dispatch<React.SetStateAction<DEFAULT_LINK_TYPE>>;
isAllowed: boolean;
handleUpgradeStateChange: (options: LinkUpgradeOptions) => void;
- // presets: LinkPreset | null;
+ presets: LinkPreset | null;
}) {
const [enabled, setEnabled] = useState<boolean>(false);
const [isConfigOpen, setIsConfigOpen] = useState<boolean>(false);
- // useEffect(() => {
- // if (isAllowed && presets?.watermarkConfig) {
- // setEnabled(true);
- // setData((prevData) => ({
- // ...prevData,
- // customFields: presets.customFields ? JSON.parse(presets.customFields as string) as CustomFieldData[] : [],
- // }));
- // }
- // }, [presets, isAllowed]);
-
useEffect(() => {
const hasCustomFields = data.customFields.length > 0;
if (enabled !== hasCustomFields) {
@@ -47,6 +37,19 @@ export default function CustomFieldsSection({
}
}, [data.customFields, enabled]);
+ useEffect(() => {
+ if (isAllowed && presets?.enableCustomFields && presets?.customFields) {
+ console.log("presets", presets.customFields);
+ setEnabled(true);
+ setData((prevData) => ({
+ ...prevData,
+ customFields: presets.customFields
+ ? (presets.customFields as CustomFieldData[])
+ : [],
+ }));
+ }
+ }, [presets, isAllowed]);
+
const handleCustomFieldsToggle = useCallback(() => {
const updatedEnabled = !enabled;
setData((prevData) => ({
diff --git a/components/links/link-sheet/index.tsx b/components/links/link-sheet/index.tsx
index 7f66ad1f..f3dfdfec 100644
--- a/components/links/link-sheet/index.tsx
+++ b/components/links/link-sheet/index.tsx
@@ -245,6 +245,8 @@ export default function LinkSheet({
metaImage: preset.metaImage || prev.metaImage,
metaFavicon: preset.metaFavicon || prev.metaFavicon,
allowDownload: preset.allowDownload || prev.allowDownload,
+ enableAgreement: preset.enableAgreement || prev.enableAgreement,
+ agreementId: preset.agreementId || prev.agreementId,
enableScreenshotProtection:
preset.enableScreenshotProtection || prev.enableScreenshotProtection,
};
diff --git a/components/links/link-sheet/link-options.tsx b/components/links/link-sheet/link-options.tsx
index ee40c88f..36883042 100644
--- a/components/links/link-sheet/link-options.tsx
+++ b/components/links/link-sheet/link-options.tsx
@@ -207,6 +207,7 @@ export const LinkOptions = ({
{...{ data, setData }}
isAllowed={isTrial || isBusiness || isDatarooms || isDataroomsPlus}
handleUpgradeStateChange={handleUpgradeStateChange}
+ presets={currentPreset}
/>
{linkType === LinkType.DOCUMENT_LINK ? (
<ProBannerSection
diff --git a/lib/zod/schemas/presets.ts b/lib/zod/schemas/presets.ts
index 2c7f1698..d94dd680 100644
--- a/lib/zod/schemas/presets.ts
+++ b/lib/zod/schemas/presets.ts
@@ -23,17 +23,17 @@ export const watermarkConfigSchema = z
.nullable();
export const presetDataSchema = z.object({
+ name: z.string(),
// Social Media Card
enableCustomMetaTag: z.boolean(),
- name: z.string(),
metaFavicon: z.string().nullable(),
metaImage: z.string().nullable(),
metaTitle: z.string().nullable(),
metaDescription: z.string().nullable(),
// // Custom Fields
- // enableCustomFields: z.boolean(),
- // customFields: z.array(customFieldDataSchema).nullable(),
+ enableCustomFields: z.boolean().optional(),
+ customFields: z.array(customFieldDataSchema).nullable().optional(),
// Watermark
enableWatermark: z.boolean(),
@@ -47,15 +47,19 @@ export const presetDataSchema = z.object({
// Email Protection
emailProtected: z.boolean(),
- emailAuthenticated: z.boolean(),
+ emailAuthenticated: z.boolean().optional(),
+
+ // Additional Options
allowDownload: z.boolean().optional(),
enablePassword: z.boolean(),
password: z.string().nullable(),
expiresAt: z.string().nullable(),
expiresIn: z.number().nullable().optional(),
+ enableScreenshotProtection: z.boolean().optional(),
- // Screenshot Protection
- enableScreenshotProtection: z.boolean(),
+ // Agreement
+ enableAgreement: z.boolean().optional(),
+ agreementId: z.string().nullable().optional(),
});
export type PresetDataSchema = z.infer<typeof presetDataSchema>;
diff --git a/package-lock.json b/package-lock.json
index 04e24176..9a3820e7 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -66,6 +66,7 @@
"base-x": "^5.0.1",
"bcryptjs": "^3.0.2",
"bottleneck": "^2.19.5",
+ "chrono-node": "^2.8.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"cmdk": "^1.1.1",
@@ -7639,6 +7640,18 @@
"node": ">=10"
}
},
+ "node_modules/chrono-node": {
+ "version": "2.8.0",
+ "resolved": "https://registry.npmjs.org/chrono-node/-/chrono-node-2.8.0.tgz",
+ "integrity": "sha512-//a/HhnCQ4zFHxRfi1m+jQwr8o0Gxsg0GUjZ39O6ud9lkhrnuLGX1oOKjGsivm9AVMS79cn0PmTa6JCRlzgfWA==",
+ "license": "MIT",
+ "dependencies": {
+ "dayjs": "^1.10.0"
+ },
+ "engines": {
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
+ }
+ },
"node_modules/cjs-module-lexer": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/cjs-module-lexer/-/cjs-module-lexer-1.4.1.tgz",
diff --git a/pages/api/teams/[teamId]/presets/[id].ts b/pages/api/teams/[teamId]/presets/[id].ts
index c50b8a9d..28baf43f 100644
--- a/pages/api/teams/[teamId]/presets/[id].ts
+++ b/pages/api/teams/[teamId]/presets/[id].ts
@@ -101,6 +101,8 @@ export default async function handle(
watermarkConfig: validatedData.watermarkConfig
? JSON.stringify(validatedData.watermarkConfig)
: Prisma.JsonNull,
+ customFields: validatedData.customFields
+ ? validatedData.customFields
: Prisma.JsonNull,
},
});
diff --git a/pages/api/teams/[teamId]/presets/index.ts b/pages/api/teams/[teamId]/presets/index.ts
index 9e90cc62..ee02f2fe 100644
--- a/pages/api/teams/[teamId]/presets/index.ts
+++ b/pages/api/teams/[teamId]/presets/index.ts
@@ -1,6 +1,7 @@
import { NextApiRequest, NextApiResponse } from "next";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
+import { Prisma } from "@prisma/client";
import { getServerSession } from "next-auth";
import { ZodError } from "zod";
@@ -83,6 +84,9 @@ export default async function handle(
watermarkConfig: validatedData.watermarkConfig
? JSON.stringify(validatedData.watermarkConfig)
: Prisma.JsonNull,
+ customFields: validatedData.customFields
+ ? validatedData.customFields
+ : Prisma.JsonNull,
},
});
return res
diff --git a/pages/settings/presets/[id].tsx b/pages/settings/presets/[id].tsx
index 1305c640..0a160133 100644
--- a/pages/settings/presets/[id].tsx
+++ b/pages/settings/presets/[id].tsx
@@ -1,11 +1,7 @@
import { useRouter } from "next/router";
-
-
import { FormEvent, useEffect, useState } from "react";
-
-
import { useTeam } from "@/context/team-context";
import { PlanEnum } from "@/ee/stripe/constants";
import { LinkPreset } from "@prisma/client";
@@ -13,24 +9,22 @@ import { AlertCircle, ArrowLeft, Trash2, X } from "lucide-react";
import { toast } from "sonner";
import useSWR from "swr";
-
-
import { usePlan } from "@/lib/swr/use-billing";
import useLimits from "@/lib/swr/use-limits";
import { WatermarkConfig } from "@/lib/types";
import { fetcher } from "@/lib/utils";
-
-
import { UpgradePlanModal } from "@/components/billing/upgrade-plan-modal";
import AppLayout from "@/components/layouts/app";
import { DEFAULT_LINK_TYPE } from "@/components/links/link-sheet";
+import AgreementSection from "@/components/links/link-sheet/agreement-section";
import AllowDownloadSection from "@/components/links/link-sheet/allow-download-section";
import AllowListSection from "@/components/links/link-sheet/allow-list-section";
+import { CustomFieldData } from "@/components/links/link-sheet/custom-fields-panel";
+import CustomFieldsSection from "@/components/links/link-sheet/custom-fields-section";
import DenyListSection from "@/components/links/link-sheet/deny-list-section";
import EmailAuthenticationSection from "@/components/links/link-sheet/email-authentication-section";
import EmailProtectionSection from "@/components/links/link-sheet/email-protection-section";
-import ExpirationSection from "@/components/links/link-sheet/expiration-section";
import ExpirationInSection from "@/components/links/link-sheet/expirationIn-section";
import { LinkUpgradeOptions } from "@/components/links/link-sheet/link-options";
import OGSection from "@/components/links/link-sheet/og-section";
@@ -39,16 +33,17 @@ import ScreenshotProtectionSection from "@/components/links/link-sheet/screensho
import WatermarkSection from "@/components/links/link-sheet/watermark-section";
import Preview from "@/components/settings/og-preview";
import { SettingsHeader } from "@/components/settings/settings-header";
-import { Alert, AlertClose, AlertDescription, AlertTitle } from "@/components/ui/alert";
+import {
+ Alert,
+ AlertClose,
+ AlertDescription,
+ AlertTitle,
+} from "@/components/ui/alert";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Separator } from "@/components/ui/separator";
-
-
-
-
export type PRESET_DATA = Partial<DEFAULT_LINK_TYPE> & {
name: string;
enableAllowList?: boolean;
@@ -56,6 +51,8 @@ export type PRESET_DATA = Partial<DEFAULT_LINK_TYPE> & {
expiresAt?: Date | null;
expiresIn?: number | null;
pId?: string | null;
+ enableCustomFields?: boolean;
+ customFields?: CustomFieldData[];
};
export default function EditPreset() {
@@ -114,6 +111,9 @@ export default function EditPreset() {
? (JSON.parse(preset.watermarkConfig as string) as WatermarkConfig)
: null;
+ const customFields = preset.customFields
+ ? (preset.customFields as CustomFieldData[])
+ : [];
setData({
id: null,
@@ -135,6 +135,10 @@ export default function EditPreset() {
watermarkConfig: watermarkConfig,
pId: preset.pId,
enableScreenshotProtection: preset.enableScreenshotProtection ?? false,
+ enableAgreement: preset.enableAgreement ?? false,
+ agreementId: preset.agreementId,
+ enableCustomFields: customFields.length > 0,
+ customFields: customFields,
});
}
}, [preset]);
@@ -179,6 +183,8 @@ export default function EditPreset() {
expiresIn: data.expiresIn,
pId: data.pId,
enableScreenshotProtection: data.enableScreenshotProtection,
+ enableCustomFields: data.enableCustomFields,
+ customFields: data.customFields,
}),
});
@@ -377,18 +383,6 @@ export default function EditPreset() {
data={data as any}
setData={setData as any}
/>
- <ScreenshotProtectionSection
- data={data as any}
- setData={setData as any}
- isAllowed={
- isTrial ||
- (isPro && allowAdvancedLinkControls) ||
- isBusiness ||
- isDatarooms ||
- isDataroomsPlus
- }
- handleUpgradeStateChange={handleUpgradeStateChange}
- />
<ExpirationInSection
data={data as any}
@@ -441,6 +435,37 @@ export default function EditPreset() {
handleUpgradeStateChange={handleUpgradeStateChange}
presets={null}
/>
+ <ScreenshotProtectionSection
+ data={data as any}
+ setData={setData as any}
+ isAllowed={
+ isTrial ||
+ (isPro && allowAdvancedLinkControls) ||
+ isBusiness ||
+ isDatarooms ||
+ isDataroomsPlus
+ }
+ handleUpgradeStateChange={handleUpgradeStateChange}
+ />
+ <AgreementSection
+ data={data as any}
+ setData={setData as any}
+ isAllowed={isTrial || isDatarooms || isDataroomsPlus}
+ handleUpgradeStateChange={handleUpgradeStateChange}
+ />
+ <CustomFieldsSection
+ data={data as any}
+ setData={setData as any}
+ isAllowed={
+ isTrial ||
+ (isPro && allowAdvancedLinkControls) ||
+ isBusiness ||
+ isDatarooms ||
+ isDataroomsPlus
+ }
+ handleUpgradeStateChange={handleUpgradeStateChange}
+ presets={null}
+ />
</div>
</div>
@@ -480,4 +505,4 @@ export default function EditPreset() {
/>
</AppLayout>
);
-}
\ No newline at end of file
+}
diff --git a/pages/settings/presets/new.tsx b/pages/settings/presets/new.tsx
index c9f3ec06..f3b30352 100644
--- a/pages/settings/presets/new.tsx
+++ b/pages/settings/presets/new.tsx
@@ -17,8 +17,11 @@ import {
DEFAULT_LINK_PROPS,
DEFAULT_LINK_TYPE,
} from "@/components/links/link-sheet";
+import AgreementSection from "@/components/links/link-sheet/agreement-section";
import AllowDownloadSection from "@/components/links/link-sheet/allow-download-section";
import AllowListSection from "@/components/links/link-sheet/allow-list-section";
+import { CustomFieldData } from "@/components/links/link-sheet/custom-fields-panel";
+import CustomFieldsSection from "@/components/links/link-sheet/custom-fields-section";
import DenyListSection from "@/components/links/link-sheet/deny-list-section";
import EmailAuthenticationSection from "@/components/links/link-sheet/email-authentication-section";
import EmailProtectionSection from "@/components/links/link-sheet/email-protection-section";
@@ -122,6 +125,12 @@ export default function NewPreset() {
expiresAt: data.expiresAt,
expiresIn: data.expiresIn || null,
enableScreenshotProtection: data.enableScreenshotProtection,
+ enableAgreement: data.enableAgreement,
+ agreementId: data.agreementId,
+ enableCustomFields: data.customFields
+ ? data.customFields.length > 0
+ : false,
+ customFields: data.customFields,
}),
});
@@ -215,18 +224,6 @@ export default function NewPreset() {
handleUpgradeStateChange={handleUpgradeStateChange}
/>
<AllowDownloadSection data={data} setData={setData} />
- <ScreenshotProtectionSection
- data={data}
- setData={setData}
- isAllowed={
- isTrial ||
- (isPro && allowAdvancedLinkControls) ||
- isBusiness ||
- isDatarooms ||
- isDataroomsPlus
- }
- handleUpgradeStateChange={handleUpgradeStateChange}
- />
<ExpirationInSection data={data} setData={setData} />
</div>
@@ -263,7 +260,9 @@ export default function NewPreset() {
</div>
<div className="rounded-lg border p-6">
- <h3 className="mb-4 text-lg font-medium">Watermark</h3>
+ <h3 className="mb-4 text-lg font-medium">
+ Additional Security
+ </h3>
<WatermarkSection
data={data}
setData={setData}
@@ -276,6 +275,37 @@ export default function NewPreset() {
handleUpgradeStateChange={handleUpgradeStateChange}
presets={null}
/>
+ <ScreenshotProtectionSection
+ data={data}
+ setData={setData}
+ isAllowed={
+ isTrial ||
+ (isPro && allowAdvancedLinkControls) ||
+ isBusiness ||
+ isDatarooms ||
+ isDataroomsPlus
+ }
+ handleUpgradeStateChange={handleUpgradeStateChange}
+ />
+ <AgreementSection
+ data={data}
+ setData={setData}
+ isAllowed={isTrial || isDatarooms || isDataroomsPlus}
+ handleUpgradeStateChange={handleUpgradeStateChange}
+ />
+ <CustomFieldsSection
+ data={data}
+ setData={setData}
+ isAllowed={
+ isTrial ||
+ (isPro && allowAdvancedLinkControls) ||
+ isBusiness ||
+ isDatarooms ||
+ isDataroomsPlus
+ }
+ handleUpgradeStateChange={handleUpgradeStateChange}
+ presets={null}
+ />
</div>
</div>
@@ -315,4 +345,4 @@ export default function NewPreset() {
/>
</AppLayout>
);
-}
\ No newline at end of file
+}
diff --git a/prisma/migrations/20250502000000_add_additional_present_fields/migration.sql b/prisma/migrations/20250502000000_add_additional_present_fields/migration.sql
new file mode 100644
index 00000000..032b52a8
--- /dev/null
+++ b/prisma/migrations/20250502000000_add_additional_present_fields/migration.sql
@@ -0,0 +1,8 @@
+-- AlterTable
+ALTER TABLE "LinkPreset" ADD COLUMN "agreementId" TEXT,
+ADD COLUMN "customFields" JSONB,
+ADD COLUMN "enableAgreement" BOOLEAN DEFAULT false,
+ADD COLUMN "enableCustomFields" BOOLEAN DEFAULT false,
+DROP COLUMN "expiresIn",
+ADD COLUMN "expiresIn" INTEGER;
+
diff --git a/prisma/schema/link.prisma b/prisma/schema/link.prisma
index 809f9abe..3975e2af 100644
--- a/prisma/schema/link.prisma
+++ b/prisma/schema/link.prisma
@@ -100,15 +100,19 @@ model LinkPreset {
allowList String[]
enableDenyList Boolean? @default(false)
denyList String[]
- expiresIn Json? // how many days from link creation until it expires in seconds {value: 604800, type: "natural | normal"}
+ expiresIn Int? // how many days from link creation until it expires in seconds {value: 604800, type: "natural | normal"}
enableScreenshotProtection Boolean? @default(false)
expiresAt DateTime?
enablePassword Boolean? @default(false)
password String?
enableWatermark Boolean? @default(false)
watermarkConfig Json? //{text: "Confidential", isTiled: false, color: "#000000", fontSize: 12, opacity: 0.5, rotation: 30, position: "top-right"}
- // enableCustomFields Boolean? @default(false)
- // customFields Json? //[{type: "SHORT_TEXT", identifier: "name", label: "Name", required: true}]
+
+ enableAgreement Boolean? @default(false)
+ agreementId String?
+
+ enableCustomFields Boolean? @default(false)
+ customFields Json? //[{type: "SHORT_TEXT", identifier: "name", label: "Name", required: true}]
isDefault Boolean @default(false)