The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
update NewBountyAvailable email
Steven Teye9115caf378c
diff --git a/apps/web/app/(ee)/api/bounties/route.ts b/apps/web/app/(ee)/api/bounties/route.tsindex 2b5d3dd44c..8e128e496f 100644--- a/apps/web/app/(ee)/api/bounties/route.ts+++ b/apps/web/app/(ee)/api/bounties/route.ts@@ -35,108 +35,120 @@ export const GET = withWorkspace(async ({ workspace, searchParams }) => {});// POST /api/bounties - create a bounty-export const POST = withWorkspace(async ({ workspace, req }) => {- const programId = getDefaultProgramIdOrThrow(workspace);+export const POST = withWorkspace(+ async ({ workspace, req }) => {+ const programId = getDefaultProgramIdOrThrow(workspace);- const {- name,- description,- type,- rewardAmount,- startsAt,- endsAt,- submissionRequirements,- groupIds,- performanceCondition,- } = createBountySchema.parse(await parseRequestBody(req));+ const {+ name,+ description,+ type,+ rewardAmount,+ startsAt,+ endsAt,+ submissionRequirements,+ groupIds,+ performanceCondition,+ } = createBountySchema.parse(await parseRequestBody(req));- const groups = groupIds?.length- ? await prisma.partnerGroup.findMany({- where: {- programId,- id: {- in: groupIds,+ const groups = groupIds?.length+ ? await prisma.partnerGroup.findMany({+ where: {+ programId,+ id: {+ in: groupIds,+ },},- },- })- : null;+ })+ : null;- const bounty = await prisma.$transaction(async (tx) => {- let workflow: Workflow | null = null;- const bountyId = createId({ prefix: "bnty_" });+ const bounty = await prisma.$transaction(async (tx) => {+ let workflow: Workflow | null = null;+ const bountyId = createId({ prefix: "bnty_" });- // Create a workflow if there is a performance condition- if (performanceCondition && type === "performance") {- const action: WorkflowAction = {- type: WORKFLOW_ACTION_TYPES.AwardBounty,- data: {- bountyId,- },- };+ // Create a workflow if there is a performance condition+ if (performanceCondition && type === "performance") {+ const action: WorkflowAction = {+ type: WORKFLOW_ACTION_TYPES.AwardBounty,+ data: {+ bountyId,+ },+ };++ workflow = await tx.workflow.create({+ data: {+ id: createId({ prefix: "wf_" }),+ programId,+ trigger:+ WORKFLOW_ATTRIBUTE_TRIGGER_MAP[performanceCondition.attribute],+ triggerConditions: [performanceCondition],+ actions: [action],+ },+ });+ }- workflow = await tx.workflow.create({+ // Create a bounty+ const bounty = await tx.bounty.create({data: {- id: createId({ prefix: "wf_" }),+ id: bountyId,programId,- trigger:- WORKFLOW_ATTRIBUTE_TRIGGER_MAP[performanceCondition.attribute],- triggerConditions: [performanceCondition],- actions: [action],+ workflowId: workflow?.id,+ name,+ description,+ type,+ startsAt: startsAt!, // Can remove the ! when we're on a newer TS version (currently 5.4.4)+ endsAt,+ rewardAmount,+ ...(submissionRequirements &&+ type === "submission" && {+ submissionRequirements,+ }),+ ...(groups?.length && {+ groups: {+ createMany: {+ data: groups.map(({ id }) => ({+ groupId: id,+ })),+ },+ },+ }),},});- }- // Create a bounty- const bounty = await tx.bounty.create({- data: {- id: bountyId,- programId,- workflowId: workflow?.id,- name,- description,- type,- startsAt: startsAt!, // Can remove the ! when we're on a newer TS version (currently 5.4.4)- endsAt,- rewardAmount,- ...(submissionRequirements &&- type === "submission" && {- submissionRequirements,- }),- ...(groups?.length && {- groups: {- createMany: {- data: groups.map(({ id }) => ({- groupId: id,- })),- },- },- }),- },+ return {+ ...bounty,+ performanceCondition,+ };});- return {- ...bounty,- performanceCondition,- };- });-- waitUntil(- Promise.allSettled([- sendWorkspaceWebhook({- workspace,- trigger: "bounty.created",- data: BountySchema.parse(bounty),- }),+ waitUntil(+ Promise.allSettled([+ sendWorkspaceWebhook({+ workspace,+ trigger: "bounty.created",+ data: BountySchema.parse(bounty),+ }),- qstash.publishJSON({- url: `${APP_DOMAIN_WITH_NGROK}/api/cron/bounties/published`,- body: {- bountyId: bounty.id,- page: 1,- },- }),- ]),- );+ qstash.publishJSON({+ url: `${APP_DOMAIN_WITH_NGROK}/api/cron/bounties/published`,+ body: {+ bountyId: bounty.id,+ page: 1,+ },+ }),+ ]),+ );- return NextResponse.json(BountySchema.parse(bounty));-});+ return NextResponse.json(BountySchema.parse(bounty));+ },+ {+ requiredPlan: [+ "business",+ "business plus",+ "business extra",+ "business max",+ "advanced",+ "enterprise",+ ],+ },+);diff --git a/apps/web/app/(ee)/api/cron/bounties/published/route.ts b/apps/web/app/(ee)/api/cron/bounties/published/route.tsindex 8f0f4b180a..5dd2af14d8 100644--- a/apps/web/app/(ee)/api/cron/bounties/published/route.ts+++ b/apps/web/app/(ee)/api/cron/bounties/published/route.ts@@ -3,7 +3,7 @@ import { qstash } from "@/lib/cron";import { verifyQstashSignature } from "@/lib/cron/verify-qstash";import { resend } from "@dub/email/resend";import { VARIANT_TO_FROM_MAP } from "@dub/email/resend/constants";-import BountyPublished from "@dub/email/templates/new-bounty-published";+import NewBountyAvailable from "@dub/email/templates/new-bounty-available";import { prisma } from "@dub/prisma";import { APP_DOMAIN_WITH_NGROK, log } from "@dub/utils";import { z } from "zod";@@ -85,8 +85,8 @@ export async function POST(req: Request) {.map(({ partner }) => ({from: VARIANT_TO_FROM_MAP.notifications,to: partner.email!,- subject: "New bounty published",- react: BountyPublished({+ subject: `New bounty available for ${bounty.program.name}`,+ react: NewBountyAvailable({email: partner.email!,bounty: {name: bounty.name!,@@ -95,6 +95,7 @@ export async function POST(req: Request) {description: bounty.description,},program: {+ name: bounty.program.name,slug: bounty.program.slug,},}),diff --git a/packages/email/src/templates/new-bounty-published.tsx b/packages/email/src/templates/new-bounty-available.tsxsimilarity index 94%rename from packages/email/src/templates/new-bounty-published.tsxrename to packages/email/src/templates/new-bounty-available.tsxindex 9cd9923f1f..087848af5c 100644--- a/packages/email/src/templates/new-bounty-published.tsx+++ b/packages/email/src/templates/new-bounty-available.tsx@@ -15,7 +15,7 @@ import {import { BountyThumbnailImage } from "../components/bounty-thumbnail";import { Footer } from "../components/footer";-export default function NewBountyPublished({+export default function NewBountyAvailable({bounty = {name: "Promote Acme at your campus and earn $500",type: "performance",@@ -24,6 +24,7 @@ export default function NewBountyPublished({"How does it work? get a group together of at least 15 other people interested in trying out Acme. Then, during the event, take a photo of the group using Acme. When submitting, provide any links to the event or photos. Once confirmed, we'll create a one-time commission for you.",},program = {+ name: "Acme",slug: "acme",},email = "[email protected]",@@ -35,6 +36,7 @@ export default function NewBountyPublished({description: string | null;};program: {+ name: string;slug: string;};email: string;@@ -42,7 +44,7 @@ export default function NewBountyPublished({return (<Html><Head />- <Preview>New bounty available!</Preview>+ <Preview>New bounty available for {program.name}</Preview><Tailwind><Body className="mx-auto my-auto bg-white font-sans"><Container className="mx-auto my-8 max-w-[600px] px-8 py-8">@@ -51,7 +53,7 @@ export default function NewBountyPublished({</Section><Heading className="bt-5 mx-0 mt-10 p-0 text-lg font-medium text-black">- New bounty available!+ New bounty available for {program.name}</Heading><Section className="rounded-xl border border-solid border-neutral-200 bg-white">