The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Edit bounties
Tim Wilsonc43e77394722
diff --git a/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts b/apps/web/app/(ee)/api/bounties/[bountyId]/route.tsindex 68dbeef0b7..fdb69ed161 100644--- a/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts+++ b/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts@@ -1,7 +1,14 @@import { getBountyOrThrow } from "@/lib/api/bounties/get-bounty-or-throw";import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";+import { parseRequestBody } from "@/lib/api/utils";import { withWorkspace } from "@/lib/auth";-import { BountySchema, BountySchemaExtended } from "@/lib/zod/schemas/bounties";+import {+ BountySchema,+ BountySchemaExtended,+ updateBountySchema,+} from "@/lib/zod/schemas/bounties";+import { prisma } from "@dub/prisma";+import { Prisma } from "@prisma/client";import { NextResponse } from "next/server";// GET /api/bounties/[bountyId] - get a bounty@@ -18,15 +25,32 @@ export const GET = withWorkspace(async ({ workspace, params }) => {});// PATCH /api/bounties/[bountyId] - update a bounty-export const PATCH = withWorkspace(async ({ workspace, params }) => {+export const PATCH = withWorkspace(async ({ workspace, params, req }) => {const { bountyId } = params;const programId = getDefaultProgramIdOrThrow(workspace);+ // TODO: [bounties] Persist performance logic to workflow and groupIds to bountyGroup+ const { performanceLogic, groupIds, ...data } = updateBountySchema.parse(+ await parseRequestBody(req),+ );+const bounty = await getBountyOrThrow({bountyId,programId,});+ await prisma.bounty.update({+ where: {+ id: bounty.id,+ },+ data: {+ ...data,+ submissionRequirements: data.submissionRequirements ?? Prisma.JsonNull,+ startsAt: new Date(data.startsAt!),+ endsAt: data.endsAt ? new Date(data.endsAt) : null,+ },+ });+return NextResponse.json(BountySchema.parse(bounty));});@@ -40,5 +64,11 @@ export const DELETE = withWorkspace(async ({ workspace, params }) => {programId,});+ await prisma.bounty.delete({+ where: {+ id: bounty.id,+ },+ });+return NextResponse.json({ id: bounty.id });});diff --git a/apps/web/app/(ee)/api/bounties/route.ts b/apps/web/app/(ee)/api/bounties/route.tsindex d2ae22426e..b94c369299 100644--- a/apps/web/app/(ee)/api/bounties/route.ts+++ b/apps/web/app/(ee)/api/bounties/route.ts@@ -31,6 +31,7 @@ export const GET = withWorkspace(async ({ workspace, searchParams }) => {export const POST = withWorkspace(async ({ workspace, req }) => {const programId = getDefaultProgramIdOrThrow(workspace);+ // TODO: [bounties] Persist performance logic to workflow and groupIds to bountyGroupconst { name, description, type, rewardAmount, startsAt, endsAt } =createBountySchema.parse(await parseRequestBody(req));diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsxindex c87f0d5beb..3f89684c31 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx@@ -84,9 +84,17 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {const form = useForm<FormData>({defaultValues: {- // TODO: Edit existing values (and handle currency / 100)-- type: "performance",+ name: bounty?.name || undefined,+ description: bounty?.description || undefined,+ startsAt: bounty?.startsAt || undefined,+ endsAt: bounty?.endsAt || undefined,+ rewardAmount: bounty?.rewardAmount+ ? bounty.rewardAmount / 100+ : undefined,+ type: bounty?.type || "performance",+ submissionRequirements: bounty?.submissionRequirements || null,++ // TODO: [bounties] Get existing performance logic from bounty/workflowperformanceLogic: {activity: undefined,operator: "gte",@@ -155,13 +163,13 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {// Handle form submissionconst onSubmit = async (data: FormData) => {- if (!workspaceId) {- return;- }+ if (!workspaceId) return;data.rewardAmount = data.rewardAmount * 100;if (data.type === "performance") {+ data.submissionRequirements = null;+let performanceLogic: BountyPerformanceLogic | null = null;if (data.performanceLogic) {try {@@ -193,15 +201,15 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {data.performanceLogic = performanceLogic;}- }+ } else data.performanceLogic = null;- await makeRequest("/api/bounties", {- method: "POST",+ await makeRequest(bounty ? `/api/bounties/${bounty.id}` : "/api/bounties", {+ method: bounty ? "PATCH" : "POST",body: data,onSuccess: () => {mutatePrefix("/api/bounties");setIsOpen(false);- toast.success("Bounty created successfully!");+ toast.success(`Bounty ${bounty ? "updated" : "created"} successfully!`);},onError: (message) => {toast.error(message);@@ -214,7 +222,7 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {<div className="sticky top-0 z-10 border-b border-neutral-200 bg-white"><div className="flex h-16 items-center justify-between px-6 py-4"><Sheet.Title className="text-lg font-semibold">- Create bounty+ {bounty ? "Update" : "Create"} bounty</Sheet.Title><Sheet.Close asChild><Button@@ -516,7 +524,7 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {<Buttontype="submit"variant="primary"- text="Create bounty"+ text={bounty ? "Update bounty" : "Create bounty"}className="w-fit"loading={isSubmitting}disabled={shouldDisableSubmit}diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-card.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-card.tsxindex d32f872970..5b5a899ba5 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-card.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-card.tsx@@ -8,7 +8,7 @@ import Link from "next/link";import { useState } from "react";export function BountyCard({ bounty }: { bounty: BountyExtendedProps }) {- const { queryParams, searchParams } = useRouterStuff();+ const { queryParams } = useRouterStuff();const [isMenuOpen, setIsMenuOpen] = useState(false);diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-list.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-list.tsxindex 88fa31ad79..2179522a65 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-list.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-list.tsx@@ -26,7 +26,6 @@ export function BountyList() {// Open/close edit bounty sheetuseEffect(() => {const bountyId = searchParams.get("bountyId");- console.log("bountyId", bountyId);setBountySheetState(bountyId ? { open: true, bountyId } : { open: false, bountyId: null },);diff --git a/apps/web/lib/api/bounties/get-bounties.ts b/apps/web/lib/api/bounties/get-bounties.tsindex 598c60e033..030255953a 100644--- a/apps/web/lib/api/bounties/get-bounties.ts+++ b/apps/web/lib/api/bounties/get-bounties.ts@@ -30,6 +30,7 @@ export async function getBounties(filters: BountyFilters) {b.startsAt,b.endsAt,b.rewardAmount,+ b.submissionRequirements,${includeExpandedFields? Prisma.sql`diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.tsindex 99314a4330..51eaf74b51 100644--- a/apps/web/lib/zod/schemas/bounties.ts+++ b/apps/web/lib/zod/schemas/bounties.ts@@ -33,6 +33,11 @@ export const bountyPerformanceLogicSchema = z.object({value: z.number().min(0, "Logic value must be at least 0"),});+const bountySubmissionRequirementsSchema = z+ .array(z.enum(SUBMISSION_REQUIREMENTS))+ .min(0)+ .max(2);+export const createBountySchema = z.object({name: z.string()@@ -48,15 +53,13 @@ export const createBountySchema = z.object({startsAt: parseDateSchema,endsAt: parseDateSchema.nullish(),rewardAmount: z.number().min(1, "Reward amount must be greater than 1"),- submissionRequirements: z- .array(z.enum(SUBMISSION_REQUIREMENTS))- .min(0)- .max(2)- .nullish(),+ submissionRequirements: bountySubmissionRequirementsSchema.nullish(),performanceLogic: bountyPerformanceLogicSchema.nullish(),groupIds: z.array(z.string()).nullable(),});+export const updateBountySchema = createBountySchema;+export const BountySchema = z.object({id: z.string(),name: z.string().nullable(),@@ -65,6 +68,7 @@ export const BountySchema = z.object({startsAt: z.date(),endsAt: z.date().nullable(),rewardAmount: z.number(),+ submissionRequirements: bountySubmissionRequirementsSchema.nullish(),});export const BountySchemaExtended = BountySchema.extend({diff --git a/packages/prisma/schema/bounty.prisma b/packages/prisma/schema/bounty.prismaindex 9838d20d22..a12fb5a763 100644--- a/packages/prisma/schema/bounty.prisma+++ b/packages/prisma/schema/bounty.prisma@@ -16,7 +16,7 @@ enum BountySubmissionStatus {model Bounty {id String @id @default(cuid())programId String- workflowId String?+ workflowId String? @uniquename String?description String? @db.Texttype BountyType@@ -30,6 +30,7 @@ model Bounty {program Program @relation(fields: [programId], references: [id], onDelete: Cascade)submissions BountySubmission[]groups BountyGroup[]+ workflow Workflow? @relation(fields: [workflowId], references: [id], onDelete: Cascade)@@index(programId)@@index(workflowId)diff --git a/packages/prisma/schema/workflow.prisma b/packages/prisma/schema/workflow.prismaindex b629c1e465..5fc4991523 100644--- a/packages/prisma/schema/workflow.prisma+++ b/packages/prisma/schema/workflow.prisma@@ -15,6 +15,7 @@ model Workflow {updatedAt DateTime @updatedAtprogram Program @relation(fields: [programId], references: [id], onDelete: Cascade)+ bounty Bounty?@@index(programId)}