Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add one month check in trigger
Marc Seitz5b58efc731b0
diff --git a/components/emails/upgrade-one-month-checkin.tsx b/components/emails/upgrade-one-month-checkin.tsxindex 103b8ee8..d74eda83 100644--- a/components/emails/upgrade-one-month-checkin.tsx+++ b/components/emails/upgrade-one-month-checkin.tsx@@ -1,37 +1,39 @@import React from "react";-import { Body, Head, Html, Preview, Tailwind, Text } from "@react-email/components";+import {+ Body,+ Head,+ Html,+ Preview,+ Tailwind,+ Text,+} from "@react-email/components";interface UpgradeCheckinEmailProps {name: string | null | undefined;- planName?: string;}-const UpgradeCheckinEmail = ({ name, planName = "Pro" }: UpgradeCheckinEmailProps) => {+const UpgradeCheckinEmail = ({ name }: UpgradeCheckinEmailProps) => {return (<Html><Head /><Preview>Check-in from Marc</Preview><Tailwind><Body className="font-sans text-sm">- <Text>Hi {name},</Text>+ <Text>Hi{name && ` ${name}`},</Text><Text>- It is Marc here. How has your experience been so far? Are you getting the value you- expected from the advanced features?- </Text>-- <Text>- Any feedback - what's working well, and what could- we improve?+ It is Marc here. How has your experience been so far? Are you+ getting the value you expected from the advanced features?</Text>+<Text>-- Marc+ Any feedback - what's working well and what could we improve?</Text>+ <Text>Marc</Text></Body></Tailwind></Html>);};-export default UpgradeCheckinEmail;\ No newline at end of file+export default UpgradeCheckinEmail;diff --git a/ee/stripe/webhooks/checkout-session-completed.ts b/ee/stripe/webhooks/checkout-session-completed.tsindex a125a9ab..a6ee6ea8 100644--- a/ee/stripe/webhooks/checkout-session-completed.ts+++ b/ee/stripe/webhooks/checkout-session-completed.ts@@ -121,4 +121,16 @@ export async function checkoutSessionCompleted(}),);+ waitUntil(+ sendUpgradeOneMonthCheckinEmailTask.trigger(+ {+ to: team.users[0].user.email as string,+ name: team.users[0].user.name as string,+ teamId,+ },+ {+ delay: "40d",+ },+ ),+ );}diff --git a/lib/emails/send-upgrade-month-checkin.ts b/lib/emails/send-upgrade-month-checkin.tsindex 784d67a3..b920a778 100644--- a/lib/emails/send-upgrade-month-checkin.ts+++ b/lib/emails/send-upgrade-month-checkin.ts@@ -1,29 +1,28 @@-import UpgradeCheckinEmail from "@/components/emails/upgrade-checkin";-import { sendEmail } from "@/lib/resend";+import UpgradeOneMonthCheckinEmail from "@/components/emails/upgrade-one-month-checkin";+import { CreateUserEmailProps } from "../types";-export const sendUpgradeCheckinEmail = async (params: CreateUserEmailProps & { planName?: string }) => {+export const sendUpgradeOneMonthCheckinEmail = async (+ params: CreateUserEmailProps,+) => {const { name, email } = params.user;- const { planName = "Pro" } = params;-- // Schedule the email to be sent 1.5 months from now (45 days)- const oneAndHalfMonthsFromNow = new Date(Date.now() + 1000 * 60 * 60 * 24 * 45).toISOString();-+// Get the first name from the full nameconst firstName = name ? name.split(" ")[0] : null;-- const emailTemplate = UpgradeCheckinEmail({ name: firstName, planName });++ const emailTemplate = UpgradeOneMonthCheckinEmail({+ name: firstName,+ });try {await sendEmail({to: email as string,- subject: "Check-in from Marc",+ subject: "Check-in from Papermark",react: emailTemplate,test: process.env.NODE_ENV === "development",- scheduledAt: oneAndHalfMonthsFromNow,});} catch (e) {console.error(e);}-};\ No newline at end of file+};diff --git a/lib/trigger/send-scheduled-email.ts b/lib/trigger/send-scheduled-email.tsindex 10f4d70a..9ffdee70 100644--- a/lib/trigger/send-scheduled-email.ts+++ b/lib/trigger/send-scheduled-email.ts@@ -1,11 +1,11 @@import { logger, task } from "@trigger.dev/sdk/v3";import { sendDataroomInfoEmail } from "@/lib/emails/send-dataroom-info";+import { sendDataroomTrial24hReminderEmail } from "@/lib/emails/send-dataroom-trial-24h";+import { sendDataroomTrialEndEmail } from "@/lib/emails/send-dataroom-trial-end";+import { sendUpgradeOneMonthCheckinEmail } from "@/lib/emails/send-upgrade-month-checkin";import prisma from "@/lib/prisma";-import { sendDataroomTrial24hReminderEmail } from "../emails/send-dataroom-trial-24h";-import { sendDataroomTrialEndEmail } from "../emails/send-dataroom-trial-end";-export const sendDataroomTrialInfoEmailTask = task({id: "send-dataroom-trial-info-email",retry: { maxAttempts: 3 },@@ -110,3 +110,41 @@ export const sendDataroomTrialExpiredEmailTask = task({return;},});++export const sendUpgradeOneMonthCheckinEmailTask = task({+ id: "send-upgrade-one-month-checkin-email",+ retry: { maxAttempts: 3 },+ run: async (payload: { to: string; name: string; teamId: string }) => {+ try {+ const team = await prisma.team.findUnique({+ where: { id: payload.teamId },+ select: {+ plan: true,+ },+ });++ if (!team) {+ logger.error("Team not found", { teamId: payload.teamId });+ return;+ }++ if (+ !["pro", "business", "datarooms", "datarooms-plus"].includes(team.plan)+ ) {+ logger.info("Team not on paid plan - no further action", {+ teamId: payload.teamId,+ plan: team.plan,+ });+ return;+ }++ await sendUpgradeOneMonthCheckinEmail({+ user: { email: payload.to, name: payload.name },+ });+ logger.info("Email sent", { to: payload.to });+ } catch (error) {+ logger.error("Error sending upgrade one month checkin email", { error });+ return;+ }+ },+});