Skip to content

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

add viewId prop to view page

Marc Seitz07cd3cf2cd55
diff --git a/pages/api/views.ts b/pages/api/views.ts
index f7573f6b..8758ef74 100644
--- a/pages/api/views.ts
+++ b/pages/api/views.ts
@@ -15,7 +15,7 @@ export default async function handle(
const { linkId, email, documentId } = req.body;
try {
- await prisma.view.create({
+ const newView = await prisma.view.create({
data: {
linkId: linkId,
viewerEmail: email,
@@ -23,7 +23,7 @@ export default async function handle(
},
});
- res.status(200).json({ message: "View recorded" });
+ res.status(200).json({ message: "View recorded", viewId: newView.id });
} catch (error) {
log(`Failed to record view for ${linkId}. Error: \n\n ${error}`)
res.status(500).json({ message: (error as Error).message });
diff --git a/pages/view/[linkId].tsx b/pages/view/[linkId].tsx
index d8418052..6678d2fd 100644
--- a/pages/view/[linkId].tsx
+++ b/pages/view/[linkId].tsx
@@ -1,14 +1,16 @@
import React, { useState } from "react";
import EmailForm from "@/components/EmailForm";
-import { getExtension } from "@/lib/utils";
+import { classNames, getExtension } from "@/lib/utils";
import { useLink } from "@/lib/swr/use-link";
import ErrorPage from "next/error";
import PDFViewer from "@/components/PDFViewer";
+import { set } from "date-fns";
export default function DocumentView() {
const { link, error } = useLink();
const [email, setEmail] = useState("");
const [submitted, setSubmitted] = useState(false);
+ const [viewId, setViewId] = useState<string>("");
if (error && error.status === 404) {
return <ErrorPage statusCode={404} />;
@@ -31,6 +33,8 @@ export default function DocumentView() {
});
if (response.ok) {
+ const { viewId } = await response.json();
+ setViewId(viewId);
setSubmitted(true);
} else {
// Handle error
@@ -76,7 +80,7 @@ export default function DocumentView() {
}
return (
<div className="bg-gray-950">
- <PDFViewer file={document.file} />
+ <PDFViewer file={document.file} viewId={viewId} linkId={link.id} documentId={document.id} />
</div>
);
}