Skip to content

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

feat: add access screen for custom fields

Marc Seitz8044f3017846
diff --git a/components/view/access-form/index.tsx b/components/view/access-form/index.tsx
index 30c3f346..c61a71e9 100644
--- a/components/view/access-form/index.tsx
+++ b/components/view/access-form/index.tsx
@@ -1,15 +1,13 @@
-import Image from "next/image";
-import Link from "next/link";
-
import { useEffect, useState } from "react";
-import { Brand, DataroomBrand } from "@prisma/client";
+import { Brand, CustomField, DataroomBrand } from "@prisma/client";
import { Button } from "@/components/ui/button";
import { determineTextColor } from "@/lib/utils/determine-text-color";
import AgreementSection from "./agreement-section";
+import CustomFieldsSection from "./custom-fields-section";
import EmailSection from "./email-section";
import NameSection from "./name-section";
import PasswordSection from "./password-section";
@@ -24,6 +22,7 @@ export type DEFAULT_ACCESS_FORM_TYPE = {
password: string | null;
hasConfirmedAgreement?: boolean;
name?: string | null;
+ customFields?: { [key: string]: string };
};
export default function AccessForm({
@@ -42,6 +41,7 @@ export default function AccessForm({
linkId,
disableEditEmail,
useCustomAccessForm,
+ customFields,
}: {
data: DEFAULT_ACCESS_FORM_TYPE;
email: string | null | undefined;
@@ -58,6 +58,7 @@ export default function AccessForm({
linkId?: string;
disableEditEmail?: boolean;
useCustomAccessForm?: boolean;
+ customFields?: Partial<CustomField>[];
}) {
const [isEmailValid, setIsEmailValid] = useState(true);
@@ -78,49 +79,37 @@ export default function AccessForm({
if (requirePassword && !data.password) return false;
if (requireAgreement && !data.hasConfirmedAgreement) return false;
if (requireAgreement && requireName && !data.name) return false;
+ if (customFields?.length) {
+ for (const field of customFields) {
+ if (field.required && !data.customFields?.[field.identifier!]) {
+ return false;
+ }
+ }
+ }
return true;
};
+ const updateCustomFields = (fields: { [key: string]: string }) => {
+ setData((prevData) => ({
+ ...prevData,
+ customFields: fields,
+ }));
+ };
+
return (
<div
- className="flex h-dvh flex-col justify-between pb-4 pt-12"
+ className="flex h-full min-h-dvh flex-col justify-between pb-4 pt-12"
style={{
backgroundColor:
brand && brand.accentColor ? brand.accentColor : "black",
}}
>
- <div className="flex flex-1 flex-col px-6 lg:px-8">
- {/* <div className="bg-gray-950" style={{ backgroundColor: accentColor }}> */}
-
- {/* <div className="relative flex h-16 w-full flex-shrink-0 items-center justify-center">
- {brand && brand.logo ? (
- <Image
- className="object-contain"
- src={brand.logo}
- alt="Logo"
- fill
- quality={100}
- priority
- />
- ) : (
- <Link
- href={`https://www.papermark.io?utm_campaign=navbar&utm_medium=navbar&utm_source=papermark-${linkId}`}
- target="_blank"
- className="text-2xl font-bold tracking-tighter text-white"
- >
- Papermark
- </Link>
- )}
- </div> */}
-
+ <div className="flex flex-1 flex-col px-6 pb-12 lg:px-8">
<div className="sm:mx-auto sm:w-full sm:max-w-md">
<h1
className="mt-10 text-2xl font-bold leading-9 tracking-tight text-white"
style={{
- color:
- brand && brand.accentColor
- ? determineTextColor(brand.accentColor)
- : "white",
+ color: determineTextColor(brand?.accentColor),
}}
>
Your action is requested to continue
@@ -143,6 +132,14 @@ export default function AccessForm({
{requirePassword ? (
<PasswordSection {...{ data, setData, brand }} />
) : null}
+ {customFields?.length ? (
+ <CustomFieldsSection
+ fields={customFields}
+ data={data.customFields || {}}
+ setData={updateCustomFields}
+ brand={brand}
+ />
+ ) : null}
{requireAgreement && agreementContent && agreementName ? (
<AgreementSection
{...{ data, setData, brand }}
@@ -152,18 +149,14 @@ export default function AccessForm({
/>
) : null}
- <div className="flex justify-center">
+ <div className="flex justify-center pt-5">
<Button
type="submit"
disabled={!isFormValid()}
className="w-1/3 min-w-fit bg-white text-gray-950 hover:bg-white/90"
loading={isLoading}
style={{
- backgroundColor:
- brand && brand.accentColor
- ? determineTextColor(brand.accentColor)
- : "white",
-
+ backgroundColor: determineTextColor(brand?.accentColor),
color:
brand && brand.accentColor ? brand.accentColor : "black",
}}
@@ -176,10 +169,15 @@ export default function AccessForm({
</div>
{!useCustomAccessForm ? (
<div className="flex justify-center">
- <p className="text-sm leading-9 tracking-tight text-gray-500">
- <a href="/" target="_blank" rel="noopener noreferrer">
- This document is securely shared with you using{" "}
- <span className="font-semibold">Papermark</span>
+ <p className="text-center text-sm tracking-tight text-gray-500">
+ This document is securely shared with you using{" "}
+ <a
+ href="https://papermark.com"
+ target="_blank"
+ rel="noopener noreferrer"
+ className="font-semibold"
+ >
+ Papermark
</a>
</p>
</div>
diff --git a/components/view/dataroom/dataroom-view.tsx b/components/view/dataroom/dataroom-view.tsx
index 69bcf8f1..9e4f3c8a 100644
--- a/components/view/dataroom/dataroom-view.tsx
+++ b/components/view/dataroom/dataroom-view.tsx
@@ -325,6 +325,7 @@ export default function DataroomView({
disableEditEmail={disableEditEmail}
useCustomAccessForm={useCustomAccessForm}
brand={brand}
+ customFields={link.customFields}
/>
);
}
diff --git a/components/view/document-view.tsx b/components/view/document-view.tsx
index e1993e9a..8063e4d3 100644
--- a/components/view/document-view.tsx
+++ b/components/view/document-view.tsx
@@ -257,6 +257,7 @@ export default function DocumentView({
brand={brand}
disableEditEmail={disableEditEmail}
useCustomAccessForm={useCustomAccessForm}
+ customFields={link.customFields}
/>
);
}
diff --git a/lib/utils/determine-text-color.ts b/lib/utils/determine-text-color.ts
index ceb29204..732fb0fb 100644
--- a/lib/utils/determine-text-color.ts
+++ b/lib/utils/determine-text-color.ts
@@ -21,7 +21,8 @@ function luminance(r: number, g: number, b: number) {
return (0.299 * r + 0.587 * g + 0.114 * b) / 255;
}
-export function determineTextColor(hexColor: string) {
+export function determineTextColor(hexColor: string | null | undefined) {
+ if (!hexColor) return "white";
const [r, g, b] = hexToRgb(hexColor);
return luminance(r, g, b) > 0.5 ? "black" : "white";
}
diff --git a/pages/api/links/[id]/index.ts b/pages/api/links/[id]/index.ts
index d27be277..7bfed592 100644
--- a/pages/api/links/[id]/index.ts
+++ b/pages/api/links/[id]/index.ts
@@ -62,6 +62,26 @@ export default async function handle(
groupId: true,
audienceType: true,
teamId: true,
+ team: {
+ select: {
+ plan: true,
+ },
+ },
+ customFields: {
+ select: {
+ id: true,
+ type: true,
+ identifier: true,
+ label: true,
+ placeholder: true,
+ required: true,
+ disabled: true,
+ orderIndex: true,
+ },
+ orderBy: {
+ orderIndex: "asc",
+ },
+ },
},
});
@@ -100,9 +120,16 @@ export default async function handle(
brand = data.brand;
}
+ const teamPlan = link.team?.plan || "free";
+
const returnLink = {
...link,
...linkData,
+ ...(teamPlan === "free" && {
+ customFields: [], // reset custom fields for free plan
+ enableAgreement: false,
+ enableWatermark: false,
+ }),
};
return res.status(200).json({ linkType, link: returnLink, brand });
diff --git a/pages/api/links/domains/[...domainSlug].ts b/pages/api/links/domains/[...domainSlug].ts
index a6715b30..889e71f8 100644
--- a/pages/api/links/domains/[...domainSlug].ts
+++ b/pages/api/links/domains/[...domainSlug].ts
@@ -74,6 +74,21 @@ export default async function handle(
plan: true,
},
},
+ customFields: {
+ select: {
+ id: true,
+ type: true,
+ identifier: true,
+ label: true,
+ placeholder: true,
+ required: true,
+ disabled: true,
+ orderIndex: true,
+ },
+ orderBy: {
+ orderIndex: "asc",
+ },
+ },
},
});
@@ -143,6 +158,11 @@ export default async function handle(
team: undefined,
document: undefined,
dataroom: undefined,
+ ...(teamPlan === "free" && {
+ customFields: [], // reset custom fields for free plan
+ enableAgreement: false,
+ enableWatermark: false,
+ }),
};
// clean up the link return object
diff --git a/pages/api/views-dataroom.ts b/pages/api/views-dataroom.ts
index 64a49cb2..bc9176f7 100644
--- a/pages/api/views-dataroom.ts
+++ b/pages/api/views-dataroom.ts
@@ -77,6 +77,11 @@ export default async function handle(
hasConfirmedAgreement?: boolean;
};
+ // Add customFields to the data extraction
+ const { customFields } = data as {
+ customFields?: { [key: string]: string };
+ };
+
// INFO: for using the advanced excel viewer
let { useAdvancedExcelViewer } = data as {
useAdvancedExcelViewer: boolean;
@@ -122,6 +127,12 @@ export default async function handle(
plan: true,
},
},
+ customFields: {
+ select: {
+ identifier: true,
+ label: true,
+ },
+ },
},
});
@@ -496,6 +507,18 @@ export default async function handle(
link.groupId && {
groupId: link.groupId,
}),
+ ...(customFields &&
+ link.customFields.length > 0 && {
+ customFieldResponse: {
+ create: {
+ data: link.customFields.map((field) => ({
+ identifier: field.identifier,
+ label: field.label,
+ response: customFields[field.identifier] || "",
+ })),
+ },
+ },
+ }),
},
select: { id: true },
});
diff --git a/pages/api/views.ts b/pages/api/views.ts
index 42aebc2d..78716075 100644
--- a/pages/api/views.ts
+++ b/pages/api/views.ts
@@ -61,6 +61,11 @@ export default async function handle(
hasConfirmedAgreement?: boolean;
};
+ // Add customFields to the data extraction
+ const { customFields } = data as {
+ customFields?: { [key: string]: string };
+ };
+
// INFO: for using the advanced excel viewer
const { useAdvancedExcelViewer } = data as {
useAdvancedExcelViewer: boolean;
@@ -103,6 +108,12 @@ export default async function handle(
plan: true,
},
},
+ customFields: {
+ select: {
+ identifier: true,
+ label: true,
+ },
+ },
},
});
@@ -441,6 +452,18 @@ export default async function handle(
},
},
}),
+ ...(customFields &&
+ link.customFields.length > 0 && {
+ customFieldResponse: {
+ create: {
+ data: link.customFields.map((field) => ({
+ identifier: field.identifier,
+ label: field.label,
+ response: customFields[field.identifier] || "",
+ })),
+ },
+ },
+ }),
},
select: { id: true },
});