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.

add NewBountySubmission to executeCompleteBountyWorkflow

Steven Tey40eddea35673
diff --git a/apps/web/lib/api/workflows/execute-award-bounty-workflow.ts b/apps/web/lib/api/workflows/execute-complete-bounty-workflow.ts
similarity index 78%
rename from apps/web/lib/api/workflows/execute-award-bounty-workflow.ts
rename to apps/web/lib/api/workflows/execute-complete-bounty-workflow.ts
index 301e773228..2298f42c64 100644
--- a/apps/web/lib/api/workflows/execute-award-bounty-workflow.ts
+++ b/apps/web/lib/api/workflows/execute-complete-bounty-workflow.ts
@@ -1,14 +1,16 @@
import { WorkflowConditionAttribute, WorkflowContext } from "@/lib/types";
import { WORKFLOW_ACTION_TYPES } from "@/lib/zod/schemas/workflows";
-import { sendEmail } from "@dub/email";
+import { sendBatchEmail, sendEmail } from "@dub/email";
import BountyCompleted from "@dub/email/templates/bounty-completed";
+import NewBountySubmission from "@dub/email/templates/bounty-new-submission";
import { prisma } from "@dub/prisma";
-import { Workflow } from "@dub/prisma/client";
+import { Role, Workflow } from "@dub/prisma/client";
import { createId } from "../create-id";
+import { getWorkspaceUsers } from "../get-workspace-users";
import { evaluateWorkflowCondition } from "./execute-workflows";
import { parseWorkflowConfig } from "./parse-workflow-config";
-export const executeAwardBountyWorkflow = async ({
+export const executeCompleteBountyWorkflow = async ({
workflow,
context,
}: {
@@ -191,5 +193,41 @@ export const executeAwardBountyWorkflow = async ({
},
}),
});
+
+ // Send email to the program owners
+ // TODO: combine with what we're doing on createBountySubmissionAction maybe?
+ const { users, program, ...workspace } = await getWorkspaceUsers({
+ programId: bounty.programId,
+ role: Role.owner,
+ notificationPreference: "newBountySubmitted",
+ });
+
+ if (users.length > 0) {
+ await sendBatchEmail(
+ users.map((user) => ({
+ variant: "notifications",
+ to: user.email,
+ subject: "New bounty submission",
+ react: NewBountySubmission({
+ email: user.email,
+ workspace: {
+ slug: workspace.slug,
+ },
+ bounty: {
+ id: bounty.id,
+ name: bounty.name,
+ },
+ partner: {
+ name: partner.name,
+ image: partner.image,
+ email: partner.email!,
+ },
+ submission: {
+ id: bountySubmission.id,
+ },
+ }),
+ })),
+ );
+ }
}
};
diff --git a/apps/web/lib/api/workflows/execute-workflows.ts b/apps/web/lib/api/workflows/execute-workflows.ts
index a4293c21a5..c0055215af 100644
--- a/apps/web/lib/api/workflows/execute-workflows.ts
+++ b/apps/web/lib/api/workflows/execute-workflows.ts
@@ -9,7 +9,7 @@ import {
} from "@/lib/zod/schemas/workflows";
import { prisma } from "@dub/prisma";
import { WorkflowTrigger } from "@dub/prisma/client";
-import { executeAwardBountyWorkflow } from "./execute-award-bounty-workflow";
+import { executeCompleteBountyWorkflow } from "./execute-complete-bounty-workflow";
import { executeSendCampaignWorkflow } from "./execute-send-campaign-workflow";
import { parseWorkflowConfig } from "./parse-workflow-config";
@@ -74,7 +74,7 @@ export async function executeWorkflows({
switch (action.type) {
case WORKFLOW_ACTION_TYPES.AwardBounty:
- await executeAwardBountyWorkflow({
+ await executeCompleteBountyWorkflow({
workflow,
context: workflowContext,
});