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 domain renewal email to workspace owners

Kiran K0d3871a06806
diff --git a/apps/web/app/(ee)/api/stripe/webhook/charge-succeeded.ts b/apps/web/app/(ee)/api/stripe/webhook/charge-succeeded.ts
index 0dfe9949fc..fe16e165b7 100644
--- a/apps/web/app/(ee)/api/stripe/webhook/charge-succeeded.ts
+++ b/apps/web/app/(ee)/api/stripe/webhook/charge-succeeded.ts
@@ -1,8 +1,11 @@
import { qstash } from "@/lib/cron";
import { setRenewOption } from "@/lib/dynadot/set-renew-option";
+import { resend } from "@dub/email/resend";
+import { VARIANT_TO_FROM_MAP } from "@dub/email/resend/constants";
+import DomainRenewed from "@dub/email/templates/domain-renewed";
import { prisma } from "@dub/prisma";
import { Invoice } from "@dub/prisma/client";
-import { APP_DOMAIN_WITH_NGROK } from "@dub/utils";
+import { APP_DOMAIN_WITH_NGROK, pluralize } from "@dub/utils";
import { addDays } from "date-fns";
import Stripe from "stripe";
@@ -100,6 +103,8 @@ async function processRenewalInvoice({ invoice }: { invoice: Invoice }) {
return;
}
+ const newExpiresAt = addDays(new Date(), 365);
+
await prisma.registeredDomain.updateMany({
where: {
id: {
@@ -107,7 +112,7 @@ async function processRenewalInvoice({ invoice }: { invoice: Invoice }) {
},
},
data: {
- expiresAt: addDays(new Date(), 365),
+ expiresAt: newExpiresAt,
autoRenewalDisabledAt: null,
},
});
@@ -121,6 +126,42 @@ async function processRenewalInvoice({ invoice }: { invoice: Invoice }) {
),
);
- // TODO:
- // Send email to the user
+ const workspace = await prisma.project.findUniqueOrThrow({
+ where: {
+ id: invoice.workspaceId,
+ },
+ include: {
+ users: {
+ where: {
+ role: "owner",
+ },
+ select: {
+ user: true,
+ },
+ },
+ },
+ });
+
+ const workspaceOwners = workspace.users.filter(({ user }) => user.email);
+
+ if (workspaceOwners.length === 0) {
+ console.log("No users found to send domain renewal failed email.");
+ return;
+ }
+
+ await resend?.batch.send(
+ workspaceOwners.map(({ user }) => ({
+ from: VARIANT_TO_FROM_MAP.notifications,
+ to: user.email!,
+ subject: `Your ${pluralize("domain", domains.length)} have been renewed`,
+ react: DomainRenewed({
+ email: user.email!,
+ workspace: {
+ slug: workspace.slug,
+ },
+ domains: domains.map(({ slug }) => ({ slug })),
+ expiresAt: newExpiresAt,
+ }),
+ })),
+ );
}
diff --git a/packages/email/src/templates/domain-renewed.tsx b/packages/email/src/templates/domain-renewed.tsx
index ad6b3db5d7..9d5573ccc4 100644
--- a/packages/email/src/templates/domain-renewed.tsx
+++ b/packages/email/src/templates/domain-renewed.tsx
@@ -1,6 +1,7 @@
-import { DUB_WORDMARK, formatDate } from "@dub/utils";
+import { DUB_WORDMARK, formatDate, pluralize } from "@dub/utils";
import {
Body,
+ Column,
Container,
Head,
Heading,
@@ -8,6 +9,7 @@ import {
Img,
Link,
Preview,
+ Row,
Section,
Tailwind,
Text,
@@ -16,21 +18,32 @@ import { Footer } from "../components/footer";
export default function DomainRenewed({
email = "[email protected]",
- domain = {
- slug: "getacme.link",
- expiresAt: new Date("2026-07-29"),
+ workspace = {
+ slug: "acme",
},
+ domains = [
+ {
+ slug: "getacme.link",
+ },
+ {
+ slug: "example.link",
+ },
+ ],
+ expiresAt = new Date(),
}: {
email: string;
- domain: {
+ workspace: {
slug: string;
- expiresAt: Date;
};
+ domains: {
+ slug: string;
+ }[];
+ expiresAt: Date;
}) {
return (
<Html>
<Head />
- <Preview>Domain renewed</Preview>
+ <Preview>Domain{domains.length > 1 ? "s" : ""} renewed</Preview>
<Tailwind>
<Body className="mx-auto my-auto bg-white font-sans">
<Container className="mx-auto my-10 max-w-[600px] px-5 py-5">
@@ -39,25 +52,57 @@ export default function DomainRenewed({
</Section>
<Heading className="mx-0 mb-5 mt-10 p-0 text-lg font-semibold text-neutral-800">
- Domain renewed
+ Domain{domains.length > 1 ? "s" : ""} renewed
</Heading>
<Text className="text-sm leading-6 text-neutral-600">
- The domain{" "}
- <Link
- href={domain.slug}
- className="font-semibold text-black underline"
- >
- {domain.slug}
- </Link>{" "}
- has been renewed for 1 year and has been processed. This
- registration expires on{" "}
+ The following {pluralize("domain", domains.length)} have been
+ successfully renewed for 1 year:
+ </Text>
+
+ <Section>
+ {domains.map((domain, index) => (
+ <div key={index}>
+ <Row>
+ <Column align="left" className="text-sm font-medium">
+ <Link
+ href={domain.slug}
+ className="font-semibold text-black underline"
+ >
+ {domain.slug}
+ </Link>
+ </Column>
+ </Row>
+
+ {index !== domains.length - 1 && (
+ <div className="my-2 w-full" />
+ )}
+ </div>
+ ))}
+ </Section>
+
+ <Text className="text-sm leading-6 text-neutral-600">
+ These domains are now active until{" "}
<span className="font-semibold text-black">
- {formatDate(domain.expiresAt)}
+ {formatDate(expiresAt)}
</span>
.
</Text>
+ <Text className="text-sm leading-6 text-neutral-600">
+ No further action is needed. Auto-renewal can be turned off from
+ domain settings page.
+ </Text>
+
+ <Section className="my-10">
+ <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}/settings/domains`}
+ >
+ Manage your domains
+ </Link>
+ </Section>
+
<Footer email={email} />
</Container>
</Body>