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 discount has been deleted email

Kiran Kdfb32cce9e58
diff --git a/apps/web/app/(ee)/api/stripe/integration/webhook/coupon-deleted.ts b/apps/web/app/(ee)/api/stripe/integration/webhook/coupon-deleted.ts
index 5524d387e7..cdc649be27 100644
--- a/apps/web/app/(ee)/api/stripe/integration/webhook/coupon-deleted.ts
+++ b/apps/web/app/(ee)/api/stripe/integration/webhook/coupon-deleted.ts
@@ -1,5 +1,8 @@
import { deleteDiscount } from "@/lib/api/partners/delete-discount";
+import { sendEmail } from "@dub/email";
+import DiscountDeleted from "@dub/email/templates/discount-deleted";
import { prisma } from "@dub/prisma";
+import { waitUntil } from "@vercel/functions";
import type Stripe from "stripe";
// Handle event "coupon.deleted"
@@ -13,6 +16,7 @@ export async function couponDeleted(event: Stripe.Event) {
},
select: {
id: true,
+ slug: true,
defaultProgramId: true,
stripeConnectId: true,
},
@@ -43,6 +47,47 @@ export async function couponDeleted(event: Stripe.Event) {
});
if (deletedDiscountId) {
+ waitUntil(
+ (async () => {
+ const workspaceUsers = await prisma.projectUsers.findFirst({
+ where: {
+ projectId: workspace.id,
+ role: "owner",
+ user: {
+ email: {
+ not: null,
+ },
+ },
+ },
+ include: {
+ user: {
+ select: {
+ email: true,
+ },
+ },
+ },
+ });
+
+ if (workspaceUsers) {
+ const { user } = workspaceUsers;
+
+ sendEmail({
+ subject: `${process.env.NEXT_PUBLIC_APP_NAME}: Discount has been deleted`,
+ email: user.email!,
+ react: DiscountDeleted({
+ email: user.email!,
+ workspace: {
+ slug: workspace.slug,
+ },
+ coupon: {
+ id: coupon.id,
+ },
+ }),
+ });
+ }
+ })(),
+ );
+
return `Discount ${deletedDiscountId} deleted.`;
}
diff --git a/packages/email/src/templates/discount-deleted.tsx b/packages/email/src/templates/discount-deleted.tsx
new file mode 100644
index 0000000000..6128f1916b
--- /dev/null
+++ b/packages/email/src/templates/discount-deleted.tsx
@@ -0,0 +1,74 @@
+import { DUB_WORDMARK } from "@dub/utils";
+import {
+ Body,
+ Container,
+ Head,
+ Heading,
+ Html,
+ Img,
+ Link,
+ Preview,
+ Section,
+ Tailwind,
+ Text,
+} from "@react-email/components";
+import { Footer } from "../components/footer";
+
+export default function DiscountDeleted({
+ email = "[email protected]",
+ workspace = {
+ slug: "acme",
+ },
+ coupon = {
+ id: "jMT0WJUD",
+ },
+}: {
+ email: string;
+ workspace: {
+ slug: string;
+ };
+ coupon: {
+ id: string;
+ };
+}) {
+ return (
+ <Html>
+ <Head />
+ <Preview>Discount has been deleted</Preview>
+ <Tailwind>
+ <Body className="mx-auto my-auto bg-white font-sans">
+ <Container className="mx-auto my-10 max-w-[600px] rounded border border-solid border-neutral-200 px-10 py-5">
+ <Section className="mt-8">
+ <Img src={DUB_WORDMARK} height="32" alt="Dub" />
+ </Section>
+
+ <Heading className="mx-0 my-7 p-0 text-xl font-medium text-black">
+ Discount has been deleted
+ </Heading>
+
+ <Text className="text-sm leading-6 text-black">
+ Your discount with Stripe coupon <strong>{coupon.id}</strong> has
+ been deleted.
+ </Text>
+
+ <Text className="text-sm leading-6 text-black">
+ This action also removes the discount association from any
+ partners who were using this discount.
+ </Text>
+
+ <Section className="mb-8 mt-8">
+ <Link
+ className="rounded-lg bg-black px-6 py-3 text-center text-[12px] font-semibold text-white no-underline"
+ href={`https://app.dub.co/${workspace.slug}/program/discounts`}
+ >
+ Manage discounts
+ </Link>
+ </Section>
+
+ <Footer email={email} />
+ </Container>
+ </Body>
+ </Tailwind>
+ </Html>
+ );
+}