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.

made domains cron handle multiple emails

Steven Tey7a06f160d478
diff --git a/emails/domain-deleted.tsx b/emails/domain-deleted.tsx
index 8ceee4f281..6fbce7faef 100644
--- a/emails/domain-deleted.tsx
+++ b/emails/domain-deleted.tsx
@@ -15,12 +15,12 @@ import {
import { DUB_LOGO } from "../lib/constants";
export default function DomainDeleted({
- email = "[email protected]",
domain = "dub.sh",
+ projectName = "Dub",
projectSlug = "dub",
}: {
- email: string;
domain: string;
+ projectName: string;
projectSlug: string;
}) {
return (
@@ -72,11 +72,11 @@ export default function DomainDeleted({
</Text>
<Hr className="mx-0 my-6 w-full border border-gray-200" />
<Text className="text-[12px] leading-6 text-gray-500">
- This email was intended for{" "}
- <span className="text-black">{email}</span>. If you were not
- expecting this email, you can ignore this email. If you are
- concerned about your account's safety, please reply to this email
- to get in touch with us.
+ This email was intended for members of the{" "}
+ <span className="text-black">{projectName}</span> project on
+ Dub.If you were not expecting this email, you can ignore this
+ email. If you are concerned about your account's safety, please
+ reply to this email to get in touch with us.
</Text>
</Container>
</Body>
diff --git a/emails/invalid-domain.tsx b/emails/invalid-domain.tsx
index 1d54852f81..abe547b8dc 100644
--- a/emails/invalid-domain.tsx
+++ b/emails/invalid-domain.tsx
@@ -15,13 +15,13 @@ import {
import { DUB_LOGO } from "../lib/constants";
export default function InvalidDomain({
- email = "[email protected]",
domain = "dub.sh",
+ projectName = "Dub",
projectSlug = "dub",
invalidDays = 14,
}: {
- email: string;
domain: string;
+ projectName: string;
projectSlug: string;
invalidDays: number;
}): JSX.Element {
@@ -85,11 +85,11 @@ export default function InvalidDomain({
</Text>
<Hr className="mx-0 my-6 w-full border border-gray-200" />
<Text className="text-[12px] leading-6 text-gray-500">
- This email was intended for{" "}
- <span className="text-black">{email}</span>. If you were not
- expecting this email, you can ignore this email. If you are
- concerned about your account's safety, please reply to this email
- to get in touch with us.
+ This email was intended for members of the{" "}
+ <span className="text-black">{projectName}</span> project on Dub.
+ If you were not expecting this email, you can ignore this email.
+ If you are concerned about your account's safety, please reply to
+ this email to get in touch with us.
</Text>
</Container>
</Body>
diff --git a/lib/cron/domains.tsx b/lib/cron/domains.tsx
index 3b09e715c2..a3d5de76d0 100644
--- a/lib/cron/domains.tsx
+++ b/lib/cron/domains.tsx
@@ -45,13 +45,11 @@ export const handleDomainUpdates = async ({
},
},
select: {
+ name: true,
slug: true,
sentEmails: true,
usage: true,
users: {
- where: {
- role: "owner",
- },
select: {
user: {
select: {
@@ -59,6 +57,7 @@ export const handleDomainUpdates = async ({
},
},
},
+ take: 50,
},
_count: {
select: {
@@ -75,9 +74,10 @@ export const handleDomainUpdates = async ({
});
return;
}
+ const projectName = project.name;
const projectSlug = project.slug;
const sentEmails = project.sentEmails.map((email) => email.type);
- const ownerEmail = project.users[0].user.email as string;
+ const emails = project.users.map((user) => user.user.email) as string[];
// if domain is invalid for more than 30 days, check if we can delete it
if (invalidDays >= 30) {
@@ -126,11 +126,11 @@ export const handleDomainUpdates = async ({
limiter.schedule(() =>
sendEmail({
subject: `Your domain ${domain} has been deleted`,
- email: ownerEmail,
+ email: emails,
react: DomainDeleted({
- email: ownerEmail,
- projectSlug,
domain,
+ projectName,
+ projectSlug,
}),
}),
),
@@ -142,15 +142,15 @@ export const handleDomainUpdates = async ({
"secondDomainInvalidEmail",
);
if (!sentSecondDomainInvalidEmail) {
- sendDomainInvalidEmail({
+ return sendDomainInvalidEmail({
+ projectName,
projectSlug,
domain,
invalidDays,
- ownerEmail,
+ emails,
type: "second",
});
}
- return;
}
if (invalidDays >= 14) {
@@ -158,30 +158,32 @@ export const handleDomainUpdates = async ({
"firstDomainInvalidEmail",
);
if (!sentFirstDomainInvalidEmail) {
- sendDomainInvalidEmail({
+ return sendDomainInvalidEmail({
+ projectName,
projectSlug,
domain,
invalidDays,
- ownerEmail,
+ emails,
type: "first",
});
}
- return;
}
return;
};
const sendDomainInvalidEmail = async ({
+ projectName,
projectSlug,
domain,
invalidDays,
- ownerEmail,
+ emails,
type,
}: {
+ projectName: string;
projectSlug: string;
domain: string;
invalidDays: number;
- ownerEmail: string;
+ emails: string[];
type: "first" | "second";
}) => {
return await Promise.allSettled([
@@ -192,10 +194,10 @@ const sendDomainInvalidEmail = async ({
limiter.schedule(() =>
sendEmail({
subject: `Your domain ${domain} needs to be configured`,
- email: ownerEmail,
+ email: emails,
react: InvalidDomain({
- email: ownerEmail,
domain,
+ projectName,
projectSlug,
invalidDays,
}),