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 BountySubmitted email

Kiran K427d5386cf2f
diff --git a/apps/web/lib/actions/partners/create-bounty-submission.ts b/apps/web/lib/actions/partners/create-bounty-submission.ts
index 60e7f8457a..eaee904db3 100644
--- a/apps/web/lib/actions/partners/create-bounty-submission.ts
+++ b/apps/web/lib/actions/partners/create-bounty-submission.ts
@@ -4,9 +4,11 @@ import { getBountyOrThrow } from "@/lib/api/bounties/get-bounty-or-throw";
import { getWorkspaceUsers } from "@/lib/api/get-workspace-users";
import { getProgramEnrollmentOrThrow } from "@/lib/api/programs/get-program-enrollment-or-throw";
import { BountySubmissionFileSchema } from "@/lib/zod/schemas/bounties";
+import { sendEmail } from "@dub/email";
import { resend } from "@dub/email/resend";
import { VARIANT_TO_FROM_MAP } from "@dub/email/resend/constants";
import BountyPendingReview from "@dub/email/templates/bounty-pending-review";
+import BountySubmitted from "@dub/email/templates/bounty-submitted";
import { prisma } from "@dub/prisma";
import { Role } from "@prisma/client";
import { waitUntil } from "@vercel/functions";
@@ -27,15 +29,16 @@ export const createBountySubmissionAction = authPartnerActionClient
const { partner } = ctx;
const { programId, bountyId, files, urls, description } = parsedInput;
- const [programEnrollment, bounty] = await Promise.all([
- getProgramEnrollmentOrThrow({
- partnerId: partner.id,
+ const [bounty, _] = await Promise.all([
+ await getBountyOrThrow({
+ bountyId,
programId,
}),
- await getBountyOrThrow({
- bountyId,
+ getProgramEnrollmentOrThrow({
+ partnerId: partner.id,
programId,
+ includePartner: true,
}),
]);
@@ -61,40 +64,58 @@ export const createBountySubmissionAction = authPartnerActionClient
waitUntil(
(async () => {
- const { users, ...workspace } = await getWorkspaceUsers({
+ // Send email to the program owners
+ const { users, program, ...workspace } = await getWorkspaceUsers({
programId,
role: Role.owner,
});
- if (users.length === 0) {
- return;
+ if (users.length > 0) {
+ await resend?.batch.send(
+ users.map((user) => ({
+ from: VARIANT_TO_FROM_MAP.notifications,
+ to: user.email,
+ subject: "Pending bounty review",
+ react: BountyPendingReview({
+ 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: submission.id,
+ },
+ }),
+ })),
+ );
}
- await resend?.batch.send(
- users.map((user) => ({
- from: VARIANT_TO_FROM_MAP.notifications,
- to: user.email,
- subject: "Pending bounty review",
- react: BountyPendingReview({
- email: user.email,
- workspace: {
- slug: workspace.slug,
- },
+ // Send email to the partner
+ if (partner.email && program) {
+ await sendEmail({
+ subject: "Bounty submitted!",
+ email: partner.email,
+ react: BountySubmitted({
+ email: partner.email,
bounty: {
- id: bounty.id,
name: bounty.name,
},
- partner: {
- name: partner.name,
- image: partner.image,
- email: partner.email!,
- },
- submission: {
- id: submission.id,
+ program: {
+ name: program.name,
+ slug: program.slug,
+ supportEmail: program.supportEmail || "[email protected]",
},
}),
- })),
- );
+ });
+ }
})(),
);
diff --git a/apps/web/lib/api/get-workspace-users.ts b/apps/web/lib/api/get-workspace-users.ts
index 35b56bf6b0..ac77860aeb 100644
--- a/apps/web/lib/api/get-workspace-users.ts
+++ b/apps/web/lib/api/get-workspace-users.ts
@@ -39,6 +39,13 @@ export async function getWorkspaceUsers({
id: true,
slug: true,
name: true,
+ programs: {
+ select: {
+ name: true,
+ slug: true,
+ supportEmail: true,
+ },
+ },
users: {
where: {
role,
@@ -60,10 +67,13 @@ export async function getWorkspaceUsers({
throw new Error(`Workspace ${workspaceId} not found.`);
}
+ const program = workspace.programs.length > 0 ? workspace.programs[0] : null;
+
return {
id: workspace.id,
slug: workspace.slug,
name: workspace.name,
+ program,
users: workspace.users
.map(({ user }) => user)
.filter((user) => user.email)
diff --git a/packages/email/src/templates/bounty-submitted.tsx b/packages/email/src/templates/bounty-submitted.tsx
index 4070fb9881..113f0ecc54 100644
--- a/packages/email/src/templates/bounty-submitted.tsx
+++ b/packages/email/src/templates/bounty-submitted.tsx
@@ -16,30 +16,24 @@ import { BountyThumbnailImage } from "../components/bounty-thumbnail";
import { Footer } from "../components/footer";
export default function BountySubmitted({
- bounty = {
- id: "bounty_1K33NYERM0XZS1HK7C82C77K0",
- name: "Promote Acme at your campus and earn $500 ",
- rewardAmount: 50000,
- type: "performance",
- },
program = {
name: "Acme",
slug: "acme",
supportEmail: "[email protected]",
},
+ bounty = {
+ name: "Promote Acme at your campus and earn $500 ",
+ },
email = "[email protected]",
}: {
- bounty: {
- id: string;
- name: string;
- rewardAmount: number;
- type: "performance" | "submission";
- };
program: {
slug: string;
name: string;
supportEmail: string;
};
+ bounty: {
+ name: string;
+ };
email: string;
}) {
return (
@@ -63,7 +57,7 @@ export default function BountySubmitted({
</Text>
<Section className="flex h-[140px] items-center justify-center rounded-lg bg-neutral-100 py-1.5">
- <BountyThumbnailImage type={bounty.type} />
+ <BountyThumbnailImage type="submission" />
</Section>
<Text className="text-sm leading-5 text-neutral-600">