Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: automate dataroom trial email
Marc Seitzd47a3f016443
diff --git a/components/emails/dataroom-trial-welcome.tsx b/components/emails/dataroom-trial-welcome.tsxnew file mode 100644index 00000000..992a40e9--- /dev/null+++ b/components/emails/dataroom-trial-welcome.tsx@@ -0,0 +1,27 @@+import React from "react";++import { Body, Head, Html, Tailwind, Text } from "@react-email/components";++interface WelcomeEmailProps {+ name: string | null | undefined;+}++const DataroomTrialWelcomeEmail = ({ name }: WelcomeEmailProps) => {+ return (+ <Html>+ <Head />+ <Tailwind>+ <Body className="font-sans text-sm">+ <Text>Hi {name},</Text>+ <Text>+ I am Marc, founder of Papermark. Thanks for creating a trial. Do you+ need any help with Data Rooms setup?+ </Text>+ <Text>Marc</Text>+ </Body>+ </Tailwind>+ </Html>+ );+};++export default DataroomTrialWelcomeEmail;diff --git a/lib/emails/send-dataroom-trial.ts b/lib/emails/send-dataroom-trial.tsnew file mode 100644index 00000000..3e1fa069--- /dev/null+++ b/lib/emails/send-dataroom-trial.ts@@ -0,0 +1,29 @@+import DataroomTrialWelcome from "@/components/emails/dataroom-trial-welcome";++import { sendEmail } from "@/lib/resend";++export const sendDataroomTrialWelcome = async ({+ fullName,+ to,+}: {+ fullName: string;+ to: string;+}) => {+ // Schedule the email to be sent 6 minutes from now+ const sixMinuteFromNow = new Date(Date.now() + 1000 * 60 * 6).toISOString();++ // get the first name from the full name+ const name = fullName.split(" ")[0];++ try {+ await sendEmail({+ to: to,+ subject: `For ${name}`,+ react: DataroomTrialWelcome({ name }),+ test: process.env.NODE_ENV === "development",+ scheduledAt: sixMinuteFromNow,+ });+ } catch (e) {+ console.error(e);+ }+};diff --git a/lib/resend.ts b/lib/resend.tsindex bb8be1ce..8bc364fe 100644--- a/lib/resend.ts+++ b/lib/resend.ts@@ -16,6 +16,7 @@ export const sendEmail = async ({system,test,cc,+ scheduledAt,}: {to: string;subject: string;@@ -24,6 +25,7 @@ export const sendEmail = async ({system?: boolean;test?: boolean;cc?: string | string[];+ scheduledAt?: string;}) => {if (!resend) {// Throw an error if resend is not initialized@@ -36,12 +38,15 @@ export const sendEmail = async ({? "Marc from Papermark <[email protected]>": system? "Papermark <[email protected]>"- : "Marc from Papermark <[email protected]>",+ : !!scheduledAt+ ? "Marc Seitz <[email protected]>"+ : "Marc from Papermark <[email protected]>",to: test ? "[email protected]" : to,cc: cc,replyTo: marketing ? "[email protected]" : undefined,subject,react,+ scheduledAt,headers: {"X-Entity-Ref-ID": nanoid(),},diff --git a/pages/api/teams/[teamId]/datarooms/trial.ts b/pages/api/teams/[teamId]/datarooms/trial.tsindex bb5793e1..c0c4a674 100644--- a/pages/api/teams/[teamId]/datarooms/trial.ts+++ b/pages/api/teams/[teamId]/datarooms/trial.ts@@ -1,8 +1,10 @@import { NextApiRequest, NextApiResponse } from "next";import { authOptions } from "@/pages/api/auth/[...nextauth]";+import { waitUntil } from "@vercel/functions";import { getServerSession } from "next-auth/next";+import { sendDataroomTrialWelcome } from "@/lib/emails/send-dataroom-trial";import { newId } from "@/lib/id-helper";import prisma from "@/lib/prisma";import { CustomUser } from "@/lib/types";@@ -21,6 +23,7 @@ export default async function handle(}const userId = (session.user as CustomUser).id;+ const email = (session.user as CustomUser).email;const { teamId } = req.query as { teamId: string };const { name, fullName, companyName, industry, companySize, phoneNumber } =@@ -65,7 +68,7 @@ export default async function handle(}await log({- message: `Dataroom Trial: ${teamId} \n\nEmail: ${(session.user as CustomUser).email} \nName: ${fullName} \nCompany Name: ${companyName} \nIndustry: ${industry} \nCompany Size: ${companySize} \nPhone Number: ${phoneNumber}`,+ message: `Dataroom Trial: ${teamId} \n\nEmail: ${email} \nName: ${fullName} \nCompany Name: ${companyName} \nIndustry: ${industry} \nCompany Size: ${companySize} \nPhone Number: ${phoneNumber}`,type: "trial",mention: true,});@@ -92,6 +95,8 @@ export default async function handle(_count: { documents: 0 },};+ waitUntil(sendDataroomTrialWelcome({ fullName, to: email! }));+res.status(201).json(dataroomWithCount);} catch (error) {console.error("Request error", error);