Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add location data into notification email
Marc Seitz3ff72d8a8c64
diff --git a/components/emails/viewed-dataroom.tsx b/components/emails/viewed-dataroom.tsxindex 28c02cec..64287b4b 100644--- a/components/emails/viewed-dataroom.tsx+++ b/components/emails/viewed-dataroom.tsx@@ -16,11 +16,15 @@ import {export default function ViewedDataroom({dataroomId = "123",dataroomName = "Example Dataroom",+ linkName = "Dataroom",viewerEmail,+ locationString,}: {dataroomId: string;dataroomName: string;+ linkName: string;viewerEmail: string | null;+ locationString?: string;}) {return (<Html>@@ -42,7 +46,13 @@ export default function ViewedDataroom({<span className="font-semibold">{viewerEmail ? `${viewerEmail}` : `someone`}</span>- .+ {locationString ? (+ <span>+ {" "}+ in <span className="font-semibold">{locationString}</span>+ </span>+ ) : null}{" "}+ from the link <span className="font-semibold">{linkName}</span>.</Text><Text className="text-sm leading-6 text-black">You can get the detailed engagement analytics like time-spent perdiff --git a/components/emails/viewed-document.tsx b/components/emails/viewed-document.tsxindex 052df330..0a30f722 100644--- a/components/emails/viewed-document.tsx+++ b/components/emails/viewed-document.tsx@@ -18,11 +18,13 @@ export default function ViewedDocument({documentName = "Pitchdeck",linkName = "Pitchdeck",viewerEmail,+ locationString,}: {documentId: string;documentName: string;linkName: string;viewerEmail: string | null;+ locationString?: string;}) {return (<Html>@@ -43,7 +45,13 @@ export default function ViewedDocument({viewed by{" "}<span className="font-semibold">{viewerEmail ? `${viewerEmail}` : `someone`}- </span>{" "}+ </span>+ {locationString ? (+ <span>+ {" "}+ in <span className="font-semibold">{locationString}</span>+ </span>+ ) : null}{" "}from the link <span className="font-semibold">{linkName}</span>.</Text><Text className="text-sm leading-6 text-black">diff --git a/lib/api/notification-helper.ts b/lib/api/notification-helper.tsindex 1e74c865..1adc028b 100644--- a/lib/api/notification-helper.ts+++ b/lib/api/notification-helper.ts@@ -1,13 +1,24 @@import { log } from "@/lib/utils";-export default async function sendNotification({ viewId }: { viewId: string }) {+export default async function sendNotification({+ viewId,+ locationData,+}: {+ viewId: string;+ locationData: {+ continent: string | null;+ country: string;+ region: string;+ city: string;+ };+}) {return await fetch(`${process.env.NEXTAUTH_URL}/api/jobs/send-notification`, {method: "POST",headers: {"Content-Type": "application/json",Authorization: `Bearer ${process.env.INTERNAL_API_KEY}`,},- body: JSON.stringify({ viewId: viewId }),+ body: JSON.stringify({ viewId: viewId, locationData }),}).then(() => {}).catch((error) => {diff --git a/lib/emails/send-viewed-dataroom.ts b/lib/emails/send-viewed-dataroom.tsindex 7392d456..08ca513a 100644--- a/lib/emails/send-viewed-dataroom.ts+++ b/lib/emails/send-viewed-dataroom.ts@@ -7,18 +7,24 @@ export const sendViewedDataroomEmail = async ({dataroomId,dataroomName,viewerEmail,+ linkName,teamMembers,+ locationString,}: {ownerEmail: string | null;dataroomId: string;dataroomName: string;viewerEmail: string | null;+ linkName: string;teamMembers?: string[];+ locationString?: string;}) => {const emailTemplate = ViewedDataroomEmail({dataroomId,dataroomName,viewerEmail,+ linkName,+ locationString,});try {if (!ownerEmail) {diff --git a/lib/emails/send-viewed-document.ts b/lib/emails/send-viewed-document.tsindex 01c8dfc1..e0a3bce8 100644--- a/lib/emails/send-viewed-document.ts+++ b/lib/emails/send-viewed-document.ts@@ -9,6 +9,7 @@ export const sendViewedDocumentEmail = async ({linkName,viewerEmail,teamMembers,+ locationString,}: {ownerEmail: string | null;documentId: string;@@ -16,12 +17,14 @@ export const sendViewedDocumentEmail = async ({linkName: string;viewerEmail: string | null;teamMembers?: string[];+ locationString?: string;}) => {const emailTemplate = ViewedDocumentEmail({documentId,documentName,linkName,viewerEmail,+ locationString,});try {if (!ownerEmail) {diff --git a/lib/tracking/record-link-view.ts b/lib/tracking/record-link-view.tsindex dbda263f..0db40b57 100644--- a/lib/tracking/record-link-view.ts+++ b/lib/tracking/record-link-view.ts@@ -104,6 +104,8 @@ export async function recordLinkView({// record link view in TinybirdrecordLinkViewTB(clickData),+ // send email notification+ enableNotification ? sendNotification({ viewId, locationData }) : null,// send webhook eventsendLinkViewWebhook({diff --git a/pages/api/jobs/send-notification.ts b/pages/api/jobs/send-notification.tsindex a00aba7c..60a65b6f 100644--- a/pages/api/jobs/send-notification.ts+++ b/pages/api/jobs/send-notification.ts@@ -29,8 +29,14 @@ export default async function handle(return;}- const { viewId } = req.body as {+ const { viewId, locationData } = req.body as {viewId: string;+ locationData: {+ continent: string | null;+ country: string;+ region: string;+ city: string;+ };};let view: {@@ -48,6 +54,9 @@ export default async function handle(id: string;name: string;} | null;+ team: {+ plan: string | null;+ } | null;} | null;try {@@ -79,6 +88,11 @@ export default async function handle(name: true,},},+ team: {+ select: {+ plan: true,+ },+ },},});@@ -117,6 +131,16 @@ export default async function handle(},});+ const includeLocation =+ !view.team?.plan?.includes("free") &&+ !view.team?.plan?.includes("starter") &&+ !view.team?.plan?.includes("pro");++ const locationString =+ locationData.country === "US"+ ? `${locationData.city}, ${locationData.region}, ${locationData.country}`+ : `${locationData.city}, ${locationData.country}`;+// POST /api/jobs/send-notificationtry {const adminEmail = users.find((user) => user.role === "ADMIN")?.user.email;@@ -132,6 +156,7 @@ export default async function handle(teamMembers: users.map((user) => user.user.email!).filter((email) => email !== adminEmail),+ locationString: includeLocation ? locationString : undefined,});} else {// send email to dataroom owner that dataroom@@ -140,9 +165,11 @@ export default async function handle(dataroomId: view.dataroom!.id,dataroomName: view.dataroom!.name,viewerEmail: view.viewerEmail,+ linkName: view.link!.name || `Link #${view.linkId.slice(-5)}`,teamMembers: users.map((user) => user.user.email!).filter((email) => email !== adminEmail),+ locationString: includeLocation ? locationString : undefined,});}