Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: identify internal visitors
Marc Seitza9d490484fa4
diff --git a/components/visitors/visitors-table.tsx b/components/visitors/visitors-table.tsxindex f7bffba6..ee8b96d8 100644--- a/components/visitors/visitors-table.tsx+++ b/components/visitors/visitors-table.tsx@@ -20,6 +20,7 @@ import ChevronDown from "@/components/shared/icons/chevron-down";import VisitorChart from "./visitor-chart";import { VisitorAvatar } from "./visitor-avatar";import BadgeCheck from "../shared/icons/badge-check";+import { BadgeInfoIcon } from "lucide-react";export default function VisitorsTable({ numPages }: { numPages: number }) {const { views } = useDocumentVisits();@@ -68,6 +69,9 @@ export default function VisitorsTable({ numPages }: { numPages: number }) {{view.verified && (<BadgeCheck className="h-4 w-4 text-emerald-500" />)}+ {view.internal && (+ <BadgeInfoIcon className="h-4 w-4 text-blue-500" />+ )}</>) : ("Anonymous"diff --git a/lib/swr/use-document.ts b/lib/swr/use-document.tsindex d092ca82..64ed8bb7 100644--- a/lib/swr/use-document.ts+++ b/lib/swr/use-document.ts@@ -61,6 +61,7 @@ export function useDocumentLinks() {}interface ViewWithDuration extends View {+ internal: boolean;duration: {data: { pageNumber: string; sum_duration: number }[];};diff --git a/pages/api/teams/[teamId]/documents/[id]/views/index.ts b/pages/api/teams/[teamId]/documents/[id]/views/index.tsindex ee41446e..4c751421 100644--- a/pages/api/teams/[teamId]/documents/[id]/views/index.ts+++ b/pages/api/teams/[teamId]/documents/[id]/views/index.ts@@ -6,6 +6,7 @@ import { authOptions } from "@/pages/api/auth/[...nextauth]";import { CustomUser } from "@/lib/types";import { getTeamWithUsersAndDocument } from "@/lib/team/helper";import { errorhandler } from "@/lib/errorHandler";+import prisma from "@/lib/prisma";export default async function handle(req: NextApiRequest,@@ -57,6 +58,19 @@ export default async function handle(},});+ const users = await prisma.user.findMany({+ where: {+ teams: {+ some: {+ teamId: teamId,+ },+ },+ },+ select: {+ email: true,+ },+ });+// get the numPages from documentconst numPages =document?.versions?.[0]?.numPages || document?.numPages || 0;@@ -91,6 +105,7 @@ export default async function handle(return {...view,+ internal: users.some((user) => user.email === view.viewerEmail), // set internal to true if view.viewerEmail is in the users listduration: durations[index],totalDuration: summedDurations[index],completionRate: completionRate.toFixed(),@@ -99,7 +114,10 @@ export default async function handle(return res.status(200).json(viewsWithDuration);} catch (error) {- log({message: `Failed to get views for document: _${docId}_. \n\n ${error} \n\n*Metadata*: \`{teamId: ${teamId}, userId: ${userId}}\``, type: "error"});+ log({+ message: `Failed to get views for document: _${docId}_. \n\n ${error} \n\n*Metadata*: \`{teamId: ${teamId}, userId: ${userId}}\``,+ type: "error",+ });errorhandler(error, res);}} else {