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.

only send integration installation emails to installer

Steven Tey553310442fe9
diff --git a/apps/web/lib/integrations/install.ts b/apps/web/lib/integrations/install.ts
index 59aa2f71aa..f5c5abefdb 100644
--- a/apps/web/lib/integrations/install.ts
+++ b/apps/web/lib/integrations/install.ts
@@ -38,60 +38,63 @@ export const installIntegration = async ({
waitUntil(
(async () => {
- const [integration, workspace] = await Promise.all([
- prisma.integration.findUniqueOrThrow({
- where: {
- id: integrationId,
- },
- select: {
- id: true,
- name: true,
- slug: true,
- },
- }),
-
- prisma.project.findUniqueOrThrow({
- where: {
- id: workspaceId,
- users: {
- some: {
- role: "owner",
+ const workspace = await prisma.project.findUniqueOrThrow({
+ where: {
+ id: workspaceId,
+ },
+ select: {
+ name: true,
+ slug: true,
+ users: {
+ select: {
+ user: {
+ select: { email: true },
},
},
+ where: {
+ userId,
+ },
},
- select: {
- name: true,
- slug: true,
- users: {
- select: {
- user: {
- select: { email: true },
+ installedIntegrations: {
+ where: {
+ integrationId,
+ },
+ select: {
+ integration: {
+ select: {
+ name: true,
+ slug: true,
},
},
},
},
- }),
- ]);
+ },
+ });
- await Promise.allSettled(
- workspace.users.map(({ user: { email } }) =>
- sendEmail({
+ const email =
+ workspace.users.length > 0 ? workspace.users[0].user.email : null;
+ const integration =
+ workspace.installedIntegrations.length > 0
+ ? workspace.installedIntegrations[0].integration
+ : null;
+
+ if (email && integration) {
+ await sendEmail({
+ email: email!,
+ subject: `The "${integration.name}" integration has been added to your workspace`,
+ react: IntegrationInstalled({
email: email!,
- subject: `The "${integration.name}" integration has been added to your workspace`,
- react: IntegrationInstalled({
- email: email!,
- workspace: {
- name: workspace.name,
- slug: workspace.slug,
- },
- integration: {
- name: integration.name,
- slug: integration.slug,
- },
- }),
+ workspace: {
+ name: workspace.name,
+ slug: workspace.slug,
+ },
+ integration: {
+ name: integration.name,
+ slug: integration.slug,
+ },
}),
- ),
- );
+ });
+ }
})(),
);