Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

send feedback email when subscription deleted

Steven Teyc17f826f2ccf
diff --git a/apps/web/app/api/callback/stripe/route.ts b/apps/web/app/api/callback/stripe/route.ts
index e04de96ee2..aafaf2b8fd 100644
--- a/apps/web/app/api/callback/stripe/route.ts
+++ b/apps/web/app/api/callback/stripe/route.ts
@@ -4,7 +4,7 @@ import { stripe } from "@/lib/stripe";
import { getPlanFromPriceId, isUpgrade } from "@/lib/stripe/utils";
import { redis } from "@/lib/upstash";
import { log } from "@dub/utils";
-import { sendEmail } from "emails";
+import { resend, sendEmail } from "emails";
import UpgradeEmail from "emails/upgrade-email";
import { NextResponse } from "next/server";
import Stripe from "stripe";
@@ -196,6 +196,15 @@ export const POST = async (req: Request) => {
select: {
slug: true,
domains: true,
+ users: {
+ select: {
+ user: {
+ select: {
+ email: true,
+ },
+ },
+ },
+ },
},
});
@@ -210,6 +219,9 @@ export const POST = async (req: Request) => {
return NextResponse.json({ received: true });
}
+ const projectUsers = project.users.map(
+ ({ user }) => user.email as string,
+ );
const projectDomains = project.domains.map((domain) => domain.slug);
const pipeline = redis.pipeline();
@@ -218,7 +230,7 @@ export const POST = async (req: Request) => {
pipeline.del(`root:${domain}`);
});
- await Promise.all([
+ await Promise.allSettled([
prisma.project.update({
where: {
stripeId,
@@ -237,6 +249,12 @@ export const POST = async (req: Request) => {
type: "cron",
mention: true,
}),
+ resend.emails.send({
+ from: "Steven from Dub.co <[email protected]>",
+ to: projectUsers,
+ subject: "Feedback on your Dub.co experience?",
+ text: "Hey!\n\nI noticed you recently cancelled your Dub.co subscription – we're sorry to see you go!\n\nI'd love to hear your feedback on your experience with Dub – what could we have done better?\n\nThanks!\n\nSteven Tey\nFounder, Dub.co",
+ }),
]);
}
} catch (error) {
diff --git a/apps/web/emails/index.ts b/apps/web/emails/index.ts
index dbeffdc2b7..7fe95fc58e 100644
--- a/apps/web/emails/index.ts
+++ b/apps/web/emails/index.ts
@@ -2,9 +2,7 @@ import { nanoid } from "@dub/utils";
import { JSXElementConstructor, ReactElement } from "react";
import { Resend } from "resend";
-export const resend = process.env.RESEND_API_KEY
- ? new Resend(process.env.RESEND_API_KEY)
- : null;
+export const resend = new Resend(process.env.RESEND_API_KEY);
export const sendEmail = async ({
email,
@@ -19,7 +17,7 @@ export const sendEmail = async ({
marketing?: boolean;
test?: boolean;
}) => {
- if (!resend) {
+ if (!process.env.RESEND_API_KEY) {
console.log(
"Resend is not configured. You need to add a RESEND_API_KEY in your .env file for emails to work.",
);