Skip to content

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

feat: add personal upgrade welcome email

Marc Seitz7490abf5172b
diff --git a/components/emails/upgrade-personal-welcome.tsx b/components/emails/upgrade-personal-welcome.tsx
index d437e7cf..55940057 100644
--- a/components/emails/upgrade-personal-welcome.tsx
+++ b/components/emails/upgrade-personal-welcome.tsx
@@ -1,36 +1,42 @@
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 UpgradeCongratsEmailProps {
+interface UpgradePersonalEmailProps {
name: string | null | undefined;
planName?: string;
}
-const UpgradeCongratsEmail = ({ name, planName = "Pro" }: UpgradeCongratsEmailProps) => {
+const UpgradePersonalEmail = ({
+ name,
+ planName = "Pro",
+}: UpgradePersonalEmailProps) => {
return (
<Html>
<Head />
- <Preview>Welcome to {planName}, {name}!</Preview>
+ <Preview>Welcome to {planName}</Preview>
<Tailwind>
<Body className="font-sans text-sm">
- <Text>Hi {name},</Text>
+ <Text>Hi{name && ` ${name}`},</Text>
<Text>
- I'm Iuliia, co-founder of Papermark. Thanks for upgrading! I'm thrilled
- to have you on our {planName} plan.
+ I'm Iuliia, co-founder of Papermark. Thanks for upgrading! I'm
+ thrilled to have you on our {planName} plan.
</Text>
<Text>
- You now have access to advanced features. Any questions so far??
- </Text>
-
- <Text>
-
- Iuliia
+ You now have access to advanced features. Any questions so far??
</Text>
+ <Text>Iuliia</Text>
</Body>
</Tailwind>
</Html>
);
};
-export default UpgradeCongratsEmail;
\ No newline at end of file
+export default UpgradePersonalEmail;
diff --git a/ee/stripe/webhooks/checkout-session-completed.ts b/ee/stripe/webhooks/checkout-session-completed.ts
index a6ee6ea8..5bd83982 100644
--- a/ee/stripe/webhooks/checkout-session-completed.ts
+++ b/ee/stripe/webhooks/checkout-session-completed.ts
@@ -8,6 +8,7 @@ import { stripeInstance } from "@/ee/stripe";
import { waitUntil } from "@vercel/functions";
import Stripe from "stripe";
+import { sendUpgradePersonalEmail } from "@/lib/emails/send-upgrade-personal-welcome";
import { sendUpgradePlanEmail } from "@/lib/emails/send-upgrade-plan";
import prisma from "@/lib/prisma";
import { sendUpgradeOneMonthCheckinEmailTask } from "@/lib/trigger/send-scheduled-email";
@@ -121,6 +122,17 @@ export async function checkoutSessionCompleted(
}),
);
+ // send personal welcome email
+ waitUntil(
+ sendUpgradePersonalEmail({
+ user: {
+ email: team.users[0].user.email as string,
+ name: team.users[0].user.name as string,
+ },
+ planSlug: plan.slug,
+ }),
+ );
+
waitUntil(
sendUpgradeOneMonthCheckinEmailTask.trigger(
{
diff --git a/lib/emails/send-upgrade-personal-welcome.ts b/lib/emails/send-upgrade-personal-welcome.ts
index 9a861714..880b7e48 100644
--- a/lib/emails/send-upgrade-personal-welcome.ts
+++ b/lib/emails/send-upgrade-personal-welcome.ts
@@ -1,23 +1,34 @@
-import UpgradeCongratsEmail from "@/components/emails/upgrade-personal-welcome";
-
import { sendEmail } from "@/lib/resend";
+import UpgradePersonalEmail from "@/components/emails/upgrade-personal-welcome";
+
import { CreateUserEmailProps } from "../types";
-export const sendUpgradeCongratsEmail = async (params: CreateUserEmailProps & { planName?: string }) => {
+const PLAN_TYPE_MAP = {
+ pro: "Pro",
+ business: "Business",
+ datarooms: "Data Rooms",
+ "datarooms-plus": "Data Rooms Plus",
+};
+
+export const sendUpgradePersonalEmail = async (
+ params: CreateUserEmailProps & { planSlug?: string },
+) => {
const { name, email } = params.user;
- const { planName = "Pro" } = params;
-
+ const { planSlug = "pro" } = params;
+
// 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 firstName = name ? name.split(" ")[0] : null;
-
- const emailTemplate = UpgradeCongratsEmail({ name: firstName, planName });
+ const planName = PLAN_TYPE_MAP[planSlug as keyof typeof PLAN_TYPE_MAP];
+
+ const emailTemplate = UpgradePersonalEmail({ name: firstName, planName });
try {
await sendEmail({
to: email as string,
+ from: "Iuliia Shnai <[email protected]>",
subject: `Your Papermark account is ready`,
react: emailTemplate,
test: process.env.NODE_ENV === "development",
@@ -26,4 +37,4 @@ export const sendUpgradeCongratsEmail = async (params: CreateUserEmailProps & {
} catch (e) {
console.error(e);
}
-};
\ No newline at end of file
+};