Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add agreements to links
Marc Seitz3013be694cba
diff --git a/components/links/link-sheet/agreement-panel/index.tsx b/components/links/link-sheet/agreement-panel/index.tsxnew file mode 100644index 00000000..0e37609a--- /dev/null+++ b/components/links/link-sheet/agreement-panel/index.tsx@@ -0,0 +1,156 @@+import { useRouter } from "next/router";++import {+ Dispatch,+ FormEvent,+ SetStateAction,+ useEffect,+ useState,+} from "react";++import { useTeam } from "@/context/team-context";+import { toast } from "sonner";+import { mutate } from "swr";+import { set } from "ts-pattern/dist/patterns";++import { Button } from "@/components/ui/button";+import { Input } from "@/components/ui/input";+import { Label } from "@/components/ui/label";+import { ScrollArea } from "@/components/ui/scroll-area";+import { Separator } from "@/components/ui/separator";+import {+ Sheet,+ SheetContent,+ SheetDescription,+ SheetFooter,+ SheetHeader,+ SheetTitle,+} from "@/components/ui/sheet";++import { useAnalytics } from "@/lib/analytics";+import { usePlan } from "@/lib/swr/use-billing";+import { useDocumentLinks } from "@/lib/swr/use-document";+import { useDomains } from "@/lib/swr/use-domains";+import { LinkWithViews } from "@/lib/types";+import { convertDataUrlToFile, uploadImage } from "@/lib/utils";++export default function AgreementSheet({+ isOpen,+ setIsOpen,+}: {+ isOpen: boolean;+ setIsOpen: Dispatch<SetStateAction<boolean>>;+}) {+ const teamInfo = useTeam();+ const teamId = teamInfo?.currentTeam?.id;+ const [data, setData] = useState({ name: "", link: "" });+ const [isLoading, setIsLoading] = useState<boolean>(false);++ const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {+ e.preventDefault();+ e.stopPropagation();++ setIsLoading(true);++ try {+ const response = await fetch(`/api/teams/${teamId}/agreements`, {+ method: "POST",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify({+ ...data,+ }),+ });++ if (!response.ok) {+ // handle error with toast message+ toast.error("Error creating agreement");+ return;+ }++ // Update the agreements list+ mutate(`/api/teams/${teamId}/agreements`);+ } catch (error) {+ console.error(error);+ toast.error("An error occurred. Please try again.");+ } finally {+ setIsLoading(false);+ setIsOpen(false);+ }+ };++ return (+ <Sheet open={isOpen} onOpenChange={setIsOpen}>+ <SheetContent className="flex w-[85%] flex-col justify-between bg-background px-4 text-foreground sm:w-[500px] md:px-5">+ <SheetHeader className="text-start">+ <SheetTitle>Create a new agreement</SheetTitle>+ <SheetDescription>+ An agreement is a special document that visitors must accept before+ accessing your link. You can create a new agreement here.+ </SheetDescription>+ </SheetHeader>++ <form className="flex grow flex-col" onSubmit={handleSubmit}>+ <div className="flex-grow space-y-6">+ <div className="w-full space-y-2">+ <Label htmlFor="name">Name</Label>+ <Input+ className="flex w-full rounded-md border-0 bg-background py-1.5 text-foreground shadow-sm ring-1 ring-inset ring-input placeholder:text-muted-foreground focus:ring-2 focus:ring-inset focus:ring-gray-400 sm:text-sm sm:leading-6"+ id="name"+ type="text"+ name="name"+ required+ autoComplete="off"+ data-1p-ignore+ placeholder="Standard NDA"+ value={data.name || ""}+ onChange={(e) =>+ setData({+ ...data,+ name: e.target.value,+ })+ }+ />+ </div>++ <div className="w-full space-y-2">+ <Label htmlFor="link">Link</Label>+ <Input+ className="flex w-full rounded-md border-0 bg-background py-1.5 text-foreground shadow-sm ring-1 ring-inset ring-input placeholder:text-muted-foreground focus:ring-2 focus:ring-inset focus:ring-gray-400 sm:text-sm sm:leading-6"+ id="link"+ type="url"+ pattern="https://.*"+ name="link"+ required+ autoComplete="off"+ data-1p-ignore+ placeholder="https://www.papermark.io/nda"+ value={data.link || ""}+ onChange={(e) =>+ setData({+ ...data,+ link: e.target.value,+ })+ }+ onInvalid={(e) =>+ e.currentTarget.setCustomValidity(+ "Please enter a valid URL starting with https://",+ )+ }+ />+ </div>+ </div>++ <SheetFooter>+ <div className="flex items-center">+ <Button type="submit" loading={isLoading}>+ Create Agreement+ </Button>+ </div>+ </SheetFooter>+ </form>+ </SheetContent>+ </Sheet>+ );+}diff --git a/components/links/link-sheet/agreement-section.tsx b/components/links/link-sheet/agreement-section.tsxnew file mode 100644index 00000000..eecec442--- /dev/null+++ b/components/links/link-sheet/agreement-section.tsx@@ -0,0 +1,161 @@+import {+ Dispatch,+ SetStateAction,+ useCallback,+ useEffect,+ useState,+} from "react";++import { Button } from "@react-email/components";+import { motion } from "framer-motion";++import { Label } from "@/components/ui/label";+import {+ Select,+ SelectContent,+ SelectItem,+ SelectTrigger,+ SelectValue,+} from "@/components/ui/select";+import { Switch } from "@/components/ui/switch";++import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/constants";+import { useAgreements } from "@/lib/swr/use-agreements";+import { cn } from "@/lib/utils";++import { DEFAULT_LINK_TYPE } from ".";+import AgreementSheet from "./agreement-panel";++export default function AgreementSection({+ data,+ setData,+ hasFreePlan,+ handleUpgradeStateChange,+}: {+ data: DEFAULT_LINK_TYPE;+ setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;+ hasFreePlan: boolean;+ handleUpgradeStateChange: (+ state: boolean,+ trigger: string,+ plan?: "Pro" | "Business" | "Data Rooms",+ ) => void;+}) {+ const { agreements } = useAgreements();+ const { enableAgreement, agreementId, emailProtected } = data;+ const [enabled, setEnabled] = useState<boolean>(false);+ const [isAgreementSheetVisible, setIsAgreementSheetVisible] =+ useState<boolean>(false);++ useEffect(() => {+ setEnabled(enableAgreement!);+ }, [enableAgreement]);++ const handleAgreement = async () => {+ const updatedAgreement = !enabled;++ setData({+ ...data,+ enableAgreement: updatedAgreement,+ emailProtected: updatedAgreement ? true : emailProtected,+ });+ setEnabled(updatedAgreement);+ };++ const handleAgreementChange = (value: string) => {+ if (value === "add_agreement") {+ // Open the agreement sheet+ setIsAgreementSheetVisible(true);+ return;+ }++ setData({ ...data, agreementId: value });+ };++ return (+ <div className="pb-5">+ <div className="flex items-center justify-between">+ <div className="flex items-center justify-between space-x-2">+ <h2+ className={cn(+ "flex items-center gap-x-2 text-sm font-medium leading-6",+ enabled ? "text-foreground" : "text-muted-foreground",+ hasFreePlan ? "cursor-pointer" : undefined,+ )}+ onClick={+ hasFreePlan+ ? () =>+ handleUpgradeStateChange(+ true,+ "link_sheet_agreement_section",+ "Data Rooms",+ )+ : undefined+ }+ >+ Require NDA to view+ {/* <span>+ <HelpCircleIcon className="text-muted-foreground h-4 w-4" />+ </span> */}+ {hasFreePlan && (+ <span className="ml-2 rounded-full bg-background px-2 py-0.5 text-xs text-foreground ring-1 ring-gray-800 dark:ring-gray-500">+ Datarooms+ </span>+ )}+ </h2>+ </div>+ <Switch+ checked={enabled}+ onClick={+ hasFreePlan+ ? () =>+ handleUpgradeStateChange(+ true,+ "link_sheet_agreement_section",+ "Data Rooms",+ )+ : undefined+ }+ className={hasFreePlan ? "opacity-50" : undefined}+ onCheckedChange={hasFreePlan ? undefined : handleAgreement}+ />+ </div>++ {enabled && (+ <motion.div+ className="relative mt-4 space-y-3"+ {...FADE_IN_ANIMATION_SETTINGS}+ >+ <div className="flex w-full flex-col items-start gap-6 overflow-x-visible pb-4 pt-0">+ <div className="w-full space-y-2">+ <Select+ onValueChange={handleAgreementChange}+ defaultValue={agreementId ?? ""}+ >+ <SelectTrigger className="focus:ring-offset-3 flex w-full rounded-md border-0 bg-background py-1.5 text-foreground shadow-sm ring-1 ring-inset ring-input placeholder:text-muted-foreground focus:ring-2 focus:ring-gray-400 sm:text-sm sm:leading-6">+ <SelectValue placeholder="Select an agreement" />+ </SelectTrigger>+ <SelectContent>+ {agreements &&+ agreements.map(({ id, name }) => (+ <SelectItem key={id} value={id}>+ {name}+ </SelectItem>+ ))}+ <SelectItem key="add_agreement" value="add_agreement">+ Add new agreement+ </SelectItem>+ </SelectContent>+ </Select>+ </div>+ </div>+ </motion.div>+ )}++ <AgreementSheet+ isOpen={isAgreementSheetVisible}+ setIsOpen={setIsAgreementSheetVisible}+ />+ </div>+ );+}diff --git a/components/links/link-sheet/email-protection-section.tsx b/components/links/link-sheet/email-protection-section.tsxindex db9c8447..aa64ae87 100644--- a/components/links/link-sheet/email-protection-section.tsx+++ b/components/links/link-sheet/email-protection-section.tsx@@ -26,6 +26,7 @@ export default function EmailProtectionSection({...data,emailProtected: updatedEmailProtection,emailAuthenticated: !updatedEmailProtection && false,+ enableAgreement: !updatedEmailProtection && false,});setEnabled(updatedEmailProtection);};diff --git a/components/links/link-sheet/index.tsx b/components/links/link-sheet/index.tsxindex d3ef18ae..89c870e8 100644--- a/components/links/link-sheet/index.tsx+++ b/components/links/link-sheet/index.tsx@@ -51,6 +51,8 @@ export const DEFAULT_LINK_PROPS = {enabledQuestion: false,questionText: null,questionType: null,+ enableAgreement: false,+ agreementId: null,};export type DEFAULT_LINK_TYPE = {@@ -75,6 +77,8 @@ export type DEFAULT_LINK_TYPE = {enableQuestion?: boolean; // feedback questionquestionText: string | null;questionType: string | null;+ enableAgreement: boolean; // agreement+ agreementId: string | null;};export default function LinkSheet({@@ -196,7 +200,7 @@ export default function LinkSheet({return (<Sheet open={isOpen} onOpenChange={(open: boolean) => setIsOpen(open)}>- <SheetContent className="flex w-[90%] flex-col justify-between bg-background px-4 text-foreground sm:w-[450px] md:px-5">+ <SheetContent className="flex w-[90%] flex-col justify-between bg-background px-4 text-foreground sm:w-[600px] sm:max-w-2xl md:px-5"><SheetHeader className="text-start"><SheetTitle>{currentLink ? "Edit link" : "Create a new link"}diff --git a/components/links/link-sheet/link-options.tsx b/components/links/link-sheet/link-options.tsxindex 5ba0ce29..d7914972 100644--- a/components/links/link-sheet/link-options.tsx+++ b/components/links/link-sheet/link-options.tsx@@ -21,6 +21,7 @@ import {import { usePlan } from "@/lib/swr/use-billing";+import AgreementSection from "./agreement-section";import QuestionSection from "./question-section";import ScreenshotProtectionSection from "./screenshot-protection-section";@@ -101,6 +102,11 @@ export const LinkOptions = ({hasFreePlan={isNotBusiness && isNotDatarooms}handleUpgradeStateChange={handleUpgradeStateChange}/>+ <AgreementSection+ {...{ data, setData }}+ hasFreePlan={isNotBusiness && isNotDatarooms}+ handleUpgradeStateChange={handleUpgradeStateChange}+ /></AccordionContent></AccordionItem></Accordion>diff --git a/components/links/links-table.tsx b/components/links/links-table.tsxindex 52a06628..90324f96 100644--- a/components/links/links-table.tsx+++ b/components/links/links-table.tsx@@ -97,6 +97,8 @@ export default function LinksTable({metaTitle: link.metaTitle,metaDescription: link.metaDescription,metaImage: link.metaImage,+ enableAgreement: link.enableAgreement ? link.enableAgreement : false,+ agreementId: link.agreementId,});//wait for dropdown to close before opening the link sheetsetTimeout(() => {diff --git a/lib/swr/use-agreements.ts b/lib/swr/use-agreements.tsnew file mode 100644index 00000000..8c00b915--- /dev/null+++ b/lib/swr/use-agreements.ts@@ -0,0 +1,24 @@+import { useTeam } from "@/context/team-context";+import { Agreement } from "@prisma/client";+import useSWR from "swr";++import { fetcher } from "@/lib/utils";++export function useAgreements() {+ const teamInfo = useTeam();+ const teamId = teamInfo?.currentTeam?.id;++ const { data: agreements, error } = useSWR<Agreement[]>(+ teamId && `/api/teams/${teamId}/agreements`,+ fetcher,+ {+ dedupingInterval: 60000,+ },+ );++ return {+ agreements,+ loading: !agreements && !error,+ error,+ };+}diff --git a/pages/api/links/[id]/index.ts b/pages/api/links/[id]/index.tsindex dda8ccb7..6955a4e5 100644--- a/pages/api/links/[id]/index.ts+++ b/pages/api/links/[id]/index.ts@@ -247,6 +247,12 @@ export default async function handle(}}+ if (linkData.enableAgreement && !linkData.agreementId) {+ return res.status(400).json({+ error: "No agreement selected.",+ });+ }+// Update the link in the databaseconst updatedLink = await prisma.link.update({where: { id: id },@@ -288,6 +294,8 @@ export default async function handle(},},},+ enableAgreement: linkData.enableAgreement,+ agreementId: linkData.agreementId || null,},include: {views: {diff --git a/pages/api/links/index.ts b/pages/api/links/index.tsindex 026f828a..2127aa5c 100644--- a/pages/api/links/index.ts+++ b/pages/api/links/index.ts@@ -115,6 +115,12 @@ export default async function handler(}}+ if (linkData.enableAgreement && !linkData.agreementId) {+ return res.status(400).json({+ error: "No agreement selected.",+ });+ }+// Fetch the link and its related document from the databaseconst link = await prisma.link.create({data: {@@ -150,6 +156,10 @@ export default async function handler(},},}),+ ...(linkData.enableAgreement && {+ enableAgreement: linkData.enableAgreement,+ agreementId: linkData.agreementId,+ }),},});diff --git a/pages/api/teams/[teamId]/agreements/index.ts b/pages/api/teams/[teamId]/agreements/index.tsnew file mode 100644index 00000000..40d8a9ca--- /dev/null+++ b/pages/api/teams/[teamId]/agreements/index.ts@@ -0,0 +1,107 @@+import { NextApiRequest, NextApiResponse } from "next";++import { getServerSession } from "next-auth/next";++import { addDomainToVercel, validDomainRegex } from "@/lib/domains";+import { errorhandler } from "@/lib/errorHandler";+import prisma from "@/lib/prisma";+import { getTeamWithDomain } from "@/lib/team/helper";+import { CustomUser } from "@/lib/types";+import { log } from "@/lib/utils";++import { authOptions } from "../../../auth/[...nextauth]";++export default async function handle(+ req: NextApiRequest,+ res: NextApiResponse,+) {+ if (req.method === "GET") {+ // GET /api/teams/:teamId/agreements+ const session = await getServerSession(req, res, authOptions);+ if (!session) {+ return res.status(401).end("Unauthorized");+ }++ const { teamId } = req.query as { teamId: string };+ const userId = (session.user as CustomUser).id;++ try {+ const team = await prisma.team.findUnique({+ where: {+ id: teamId,+ users: {+ some: {+ userId,+ },+ },+ },+ select: {+ agreements: true,+ },+ });++ if (!team) {+ return res.status(401).json("Unauthorized");+ }++ const agreements = team.agreements;+ return res.status(200).json(agreements);+ } catch (error) {+ errorhandler(error, res);+ }+ } else if (req.method === "POST") {+ // POST /api/teams/:teamId/agreements+ const session = await getServerSession(req, res, authOptions);+ if (!session) {+ res.status(401).end("Unauthorized");+ return;+ }++ const userId = (session.user as CustomUser).id;+ const { teamId } = req.query as { teamId: string };++ if (!teamId) {+ return res.status(401).json("Unauthorized");+ }++ try {+ const team = await prisma.team.findUnique({+ where: {+ id: teamId,+ users: {+ some: {+ userId,+ },+ },+ },+ });++ if (!team) {+ return res.status(401).json("Unauthorized");+ }++ const { name, link } = req.body as { name: string; link: string };++ const response = await prisma.agreement.create({+ data: {+ teamId,+ name,+ content: link,+ },+ });++ return res.status(201).json(response);+ } catch (error) {+ log({+ message: `Failed to add agreement. \n\n ${error} \n\n*Metadata*: \`{teamId: ${teamId}, userId: ${userId}}\``,+ type: "error",+ mention: true,+ });+ errorhandler(error, res);+ }+ } else {+ // We only allow GET and POST requests+ res.setHeader("Allow", ["GET", "POST"]);+ return res.status(405).end(`Method ${req.method} Not Allowed`);+ }+}diff --git a/prisma/migrations/20240611000000_add_agreements/migration.sql b/prisma/migrations/20240611000000_add_agreements/migration.sqlnew file mode 100644index 00000000..cb40d887--- /dev/null+++ b/prisma/migrations/20240611000000_add_agreements/migration.sql@@ -0,0 +1,54 @@+-- AlterTable+ALTER TABLE "Link" ADD COLUMN "agreementId" TEXT,+ADD COLUMN "enableAgreement" BOOLEAN DEFAULT false;++-- AlterTable+ALTER TABLE "View" ADD COLUMN "viewerName" TEXT;++-- CreateTable+CREATE TABLE "Agreement" (+ "id" TEXT NOT NULL,+ "name" TEXT NOT NULL,+ "content" TEXT NOT NULL,+ "teamId" TEXT NOT NULL,+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,+ "updatedAt" TIMESTAMP(3) NOT NULL,++ CONSTRAINT "Agreement_pkey" PRIMARY KEY ("id")+);++-- CreateTable+CREATE TABLE "AgreementResponse" (+ "id" TEXT NOT NULL,+ "agreementId" TEXT NOT NULL,+ "viewId" TEXT NOT NULL,+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,+ "updatedAt" TIMESTAMP(3) NOT NULL,++ CONSTRAINT "AgreementResponse_pkey" PRIMARY KEY ("id")+);++-- CreateIndex+CREATE INDEX "Agreement_teamId_idx" ON "Agreement"("teamId");++-- CreateIndex+CREATE UNIQUE INDEX "AgreementResponse_viewId_key" ON "AgreementResponse"("viewId");++-- CreateIndex+CREATE INDEX "AgreementResponse_agreementId_idx" ON "AgreementResponse"("agreementId");++-- CreateIndex+CREATE INDEX "AgreementResponse_viewId_idx" ON "AgreementResponse"("viewId");++-- AddForeignKey+ALTER TABLE "Link" ADD CONSTRAINT "Link_agreementId_fkey" FOREIGN KEY ("agreementId") REFERENCES "Agreement"("id") ON DELETE SET NULL ON UPDATE CASCADE;++-- AddForeignKey+ALTER TABLE "Agreement" ADD CONSTRAINT "Agreement_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;++-- AddForeignKey+ALTER TABLE "AgreementResponse" ADD CONSTRAINT "AgreementResponse_agreementId_fkey" FOREIGN KEY ("agreementId") REFERENCES "Agreement"("id") ON DELETE CASCADE ON UPDATE CASCADE;++-- AddForeignKey+ALTER TABLE "AgreementResponse" ADD CONSTRAINT "AgreementResponse_viewId_fkey" FOREIGN KEY ("viewId") REFERENCES "View"("id") ON DELETE CASCADE ON UPDATE CASCADE;+diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex 9b9da0ee..553c33c6 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -68,6 +68,7 @@ model Team {sentEmails SentEmail[]brand Brand?datarooms Dataroom[]+ agreements Agreement[]plan String @default("free")stripeId String? @unique // Stripe customer ID@@ -196,34 +197,37 @@ enum LinkType {}model Link {- id String @id @default(cuid())- document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade)+ id String @id @default(cuid())+ document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade)documentId String? // This can be nullable, representing links without documents- dataroom Dataroom? @relation(fields: [dataroomId], references: [id], onDelete: Cascade)+ dataroom Dataroom? @relation(fields: [dataroomId], references: [id], onDelete: Cascade)dataroomId String? // This can be nullable, representing links without datarooms- linkType LinkType @default(DOCUMENT_LINK)- url String? @unique+ linkType LinkType @default(DOCUMENT_LINK)+ url String? @uniquename String? // Link nameslug String? // Link slug for pretty URLsexpiresAt DateTime? // Optional expiration datepassword String? // Optional password for link protectionallowList String[] // Array of emails and domains allowed to view the documentdenyList String[] // Array of emails and domains denied to view the document- emailProtected Boolean @default(true) // Optional email protection- emailAuthenticated Boolean @default(false) // Optional email authentication flag- allowDownload Boolean? @default(false) // Optional give user a option to allow to download the document- isArchived Boolean @default(false) // Indicates if the link is archived+ emailProtected Boolean @default(true) // Optional email protection+ emailAuthenticated Boolean @default(false) // Optional email authentication flag+ allowDownload Boolean? @default(false) // Optional give user a option to allow to download the document+ isArchived Boolean @default(false) // Indicates if the link is archivedviews View[]- domain Domain? @relation(fields: [domainId], references: [id], onDelete: SetNull)+ domain Domain? @relation(fields: [domainId], references: [id], onDelete: SetNull)domainId String? // This can be nullable, representing links without custom domainsdomainSlug String? // This will store the domain's slug even if the domain is deleted- createdAt DateTime @default(now())- updatedAt DateTime @updatedAt- enableNotification Boolean? @default(true) // Optional give user a option to pause/resume the notifications- enableFeedback Boolean? @default(true) // Optional give user a option to enable the reactions toolbar- enableQuestion Boolean? @default(false) // Optional give user a option to enable the question feedback- enableScreenshotProtection Boolean? @default(false) // Optional give user a option to enable the screenshot protection+ createdAt DateTime @default(now())+ updatedAt DateTime @updatedAt+ enableNotification Boolean? @default(true) // Optional give user a option to pause/resume the notifications+ enableFeedback Boolean? @default(true) // Optional give user a option to enable the reactions toolbar+ enableQuestion Boolean? @default(false) // Optional give user a option to enable the question feedback+ enableScreenshotProtection Boolean? @default(false) // Optional give user a option to enable the screenshot protectionfeedback Feedback?+ enableAgreement Boolean? @default(false) // Optional give user a option to enable the terms and conditions+ agreement Agreement? @relation(fields: [agreementId], references: [id], onDelete: SetNull)+ agreementId String? // This can be nullable, representing links without agreements// custom metatagsmetaTitle String? // This will be the meta title of the link@@ -253,23 +257,25 @@ model Domain {}model View {- id String @id @default(cuid())- link Link @relation(fields: [linkId], references: [id])- linkId String- document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade)- documentId String?- dataroom Dataroom? @relation(fields: [dataroomId], references: [id], onDelete: Cascade)- dataroomId String?- dataroomViewId String? // This is the view ID from the dataroom- viewerEmail String? // Email of the viewer if known- verified Boolean @default(false) // Whether the viewer email has been verified- viewedAt DateTime @default(now())- downloadedAt DateTime? // This is the time the document was downloaded- reactions Reaction[]- viewType ViewType @default(DOCUMENT_VIEW)- viewerId String? // This is the viewer ID from the dataroom- viewer Viewer? @relation(fields: [viewerId], references: [id], onDelete: Cascade)- feedbackResponse FeedbackResponse?+ id String @id @default(cuid())+ link Link @relation(fields: [linkId], references: [id])+ linkId String+ document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade)+ documentId String?+ dataroom Dataroom? @relation(fields: [dataroomId], references: [id], onDelete: Cascade)+ dataroomId String?+ dataroomViewId String? // This is the view ID from the dataroom+ viewerEmail String? // Email of the viewer if known+ viewerName String? // Name of the viewer if known+ verified Boolean @default(false) // Whether the viewer email has been verified+ viewedAt DateTime @default(now())+ downloadedAt DateTime? // This is the time the document was downloaded+ reactions Reaction[]+ viewType ViewType @default(DOCUMENT_VIEW)+ viewerId String? // This is the viewer ID from the dataroom+ viewer Viewer? @relation(fields: [viewerId], references: [id], onDelete: Cascade)+ feedbackResponse FeedbackResponse?+ agreementResponse AgreementResponse?@@index([linkId])@@index([documentId])@@ -469,3 +475,34 @@ model FeedbackResponse {@@index([feedbackId])@@index([viewId])}++model Agreement {+ id String @id @default(cuid())+ name String // Easily identifiable name for the agreement+ content String // This will store the agreement content++ links Link[]+ responses AgreementResponse[]++ teamId String+ team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)++ createdAt DateTime @default(now())+ updatedAt DateTime @updatedAt++ @@index([teamId])+}++model AgreementResponse {+ id String @id @default(cuid())+ agreementId String+ agreement Agreement @relation(fields: [agreementId], references: [id], onDelete: Cascade)+ viewId String @unique+ view View @relation(fields: [viewId], references: [id], onDelete: Cascade)++ createdAt DateTime @default(now())+ updatedAt DateTime @updatedAt++ @@index([agreementId])+ @@index([viewId])+}