Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: track dataroom view and document view separately
Marc Seitzae379b379caa
diff --git a/components/view/DataroomViewer.tsx b/components/view/DataroomViewer.tsxindex a58edb0c..f59f1bca 100644--- a/components/view/DataroomViewer.tsx+++ b/components/view/DataroomViewer.tsx@@ -18,7 +18,7 @@ import {} from "../ui/breadcrumb";import Link from "next/link";-type DRDocument = {+type DataroomDocument = {dataroomDocumentId: string;folderId: string | null;id: string;@@ -42,7 +42,9 @@ export default function DataroomViewer({viewId: string;dataroomViewId: string;dataroom: any;- setViewType: React.Dispatch<React.SetStateAction<"DOCUMENT" | "DATAROOM">>;+ setViewType: React.Dispatch<+ React.SetStateAction<"DOCUMENT_VIEW" | "DATAROOM_VIEW">+ >;setDocumentData: React.Dispatch<React.SetStateAction<{id: string;@@ -55,7 +57,7 @@ export default function DataroomViewer({}) {const [folderId, setFolderId] = useState<string | null>(null);const { documents, folders } = dataroom as {- documents: DRDocument[];+ documents: DataroomDocument[];folders: DataroomFolder[];};console.log("documents, ", documents);@@ -104,7 +106,7 @@ export default function DataroomViewer({{documents? documents.filter((doc) => doc.folderId === folderId)- .map((document: DRDocument) => {+ .map((document: DataroomDocument) => {return (<DocumentCardkey={document.id}diff --git a/components/view/dataroom/dataroom-view.tsx b/components/view/dataroom/dataroom-view.tsxindex ba0cb761..0de277e2 100644--- a/components/view/dataroom/dataroom-view.tsx+++ b/components/view/dataroom/dataroom-view.tsx@@ -66,7 +66,9 @@ export default function DataroomView({documentVersionNumber: number;} | null>(null);- const [viewType, setViewType] = useState<"DOCUMENT" | "DATAROOM">("DATAROOM");+ const [viewType, setViewType] = useState<"DOCUMENT_VIEW" | "DATAROOM_VIEW">(+ "DATAROOM_VIEW",+ );const handleSubmission = async (): Promise<void> => {setIsLoading(true);@@ -117,7 +119,7 @@ export default function DataroomView({setViewData((prev) => ({viewId,dataroomViewId:- viewType === "DATAROOM" ? viewId : prev.dataroomViewId,+ viewType === "DATAROOM_VIEW" ? viewId : prev.dataroomViewId,file,pages,}));diff --git a/components/view/dataroom/document-card.tsx b/components/view/dataroom/document-card.tsxindex f5548de0..399d19f8 100644--- a/components/view/dataroom/document-card.tsx+++ b/components/view/dataroom/document-card.tsx@@ -38,7 +38,7 @@ type DRDocument = {type DocumentsCardProps = {document: DRDocument;- setViewType: (type: "DOCUMENT" | "DATAROOM") => void;+ setViewType: (type: "DOCUMENT_VIEW" | "DATAROOM_VIEW") => void;setDocumentData: (data: {id: string;name: string;@@ -75,7 +75,7 @@ export default function DocumentCard({<Linkhref="#"onClick={() => {- setViewType("DOCUMENT");+ setViewType("DOCUMENT_VIEW");setDocumentData({id: document.id,name: document.name,diff --git a/pages/api/teams/[teamId]/datarooms/[id]/links.ts b/pages/api/teams/[teamId]/datarooms/[id]/links.tsindex 8ff0f713..1f40596f 100644--- a/pages/api/teams/[teamId]/datarooms/[id]/links.ts+++ b/pages/api/teams/[teamId]/datarooms/[id]/links.ts@@ -52,12 +52,15 @@ export default async function handle(},include: {views: {+ where: {+ viewType: "DATAROOM_VIEW",+ },orderBy: {viewedAt: "desc",},},_count: {- select: { views: true },+ select: { views: { where: { viewType: "DATAROOM_VIEW" } } },},},});diff --git a/pages/api/views-dataroom.ts b/pages/api/views-dataroom.tsindex 43696503..70024a5f 100644--- a/pages/api/views-dataroom.ts+++ b/pages/api/views-dataroom.ts@@ -44,7 +44,7 @@ export default async function handle(verifiedEmail: string | null;linkType: string;dataroomViewId?: string;- viewType: string;+ viewType: "DATAROOM_VIEW" | "DOCUMENT_VIEW";};const { email, password } = data as { email: string; password: string };@@ -191,7 +191,7 @@ export default async function handle(isEmailVerified = true;}- if (viewType === "DATAROOM") {+ if (viewType === "DATAROOM_VIEW") {try {console.time("create-view");const newDataroomView = await prisma.view.create({@@ -200,6 +200,7 @@ export default async function handle(viewerEmail: email,verified: isEmailVerified,dataroomId: dataroomId,+ viewType: "DATAROOM_VIEW",},select: { id: true },});@@ -232,6 +233,8 @@ export default async function handle(documentId: documentId,verified: isEmailVerified,dataroomViewId: dataroomViewId,+ dataroomId: dataroomId,+ viewType: "DOCUMENT_VIEW",},select: { id: true },});diff --git a/prisma/migrations/20240330062000_add_viewtype/migration.sql b/prisma/migrations/20240330062000_add_viewtype/migration.sqlnew file mode 100644index 00000000..3424d86e--- /dev/null+++ b/prisma/migrations/20240330062000_add_viewtype/migration.sql@@ -0,0 +1,12 @@+-- CreateEnum+CREATE TYPE "ViewType" AS ENUM ('DOCUMENT_VIEW', 'DATAROOM_VIEW');++-- AlterTable+ALTER TABLE "View" ADD COLUMN "viewType" "ViewType" NOT NULL DEFAULT 'DOCUMENT_VIEW';++-- CreateIndex+CREATE INDEX "View_dataroomId_idx" ON "View"("dataroomId");++-- CreateIndex+CREATE INDEX "View_dataroomViewId_idx" ON "View"("dataroomViewId");+diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex 7ee45144..3c6136da 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -259,9 +259,17 @@ model View {viewedAt DateTime @default(now())downloadedAt DateTime? // This is the time the document was downloadedreactions Reaction[]+ viewType ViewType @default(DOCUMENT_VIEW)@@index([linkId])@@index([documentId])+ @@index([dataroomId])+ @@index([dataroomViewId])+}++enum ViewType {+ DOCUMENT_VIEW+ DATAROOM_VIEW}model Reaction {