The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
update bounty
Kiran Kcf767d6c9ba2
diff --git a/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts b/apps/web/app/(ee)/api/bounties/[bountyId]/route.tsindex 0bd4140609..262dd6ec15 100644--- a/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts+++ b/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts@@ -56,29 +56,47 @@ export const PATCH = withWorkspace(async ({ workspace, params, req }) => {}): [];- await prisma.bounty.update({- where: {- id: bounty.id,- },- data: {- name,- description,- startsAt: startsAt!, // Can remove the ! when we're on a newer TS version (currently 5.4.4)- endsAt,- rewardAmount,- submissionRequirements: submissionRequirements ?? Prisma.JsonNull,- groups: {- deleteMany: {},- create: groups.map((group) => ({- groupId: group.id,- })),+ const updatedBounty = await prisma.$transaction(async (tx) => {+ const updatedBounty = await tx.bounty.update({+ where: {+ id: bounty.id,},- },- });+ data: {+ name,+ description,+ startsAt,+ endsAt,+ rewardAmount,+ ...(bounty.type === "submission" && {+ submissionRequirements: submissionRequirements ?? Prisma.JsonNull,+ }),+ groups: {+ deleteMany: {},+ create: groups.map((group) => ({+ groupId: group.id,+ })),+ },+ },+ });++ if (updatedBounty.workflowId && performanceCondition) {+ await tx.workflow.update({+ where: {+ id: updatedBounty.workflowId,+ },+ data: {+ triggerConditions: [performanceCondition],+ },+ });+ }- // TODO: [bounties] Persist performance logic to workflow+ return {+ ...updatedBounty,+ performanceCondition,+ };+ });- return NextResponse.json(BountySchema.parse(bounty));+ return NextResponse.json(BountySchema.parse(updatedBounty));});// DELETE /api/bounties/[bountyId] - delete a bountydiff --git a/apps/web/app/(ee)/api/bounties/route.ts b/apps/web/app/(ee)/api/bounties/route.tsindex 672e8e18d3..999e8dd8e4 100644--- a/apps/web/app/(ee)/api/bounties/route.ts+++ b/apps/web/app/(ee)/api/bounties/route.ts@@ -45,7 +45,7 @@ export const POST = withWorkspace(async ({ workspace, req }) => {endsAt,submissionRequirements,groupIds,- performanceCondition: condition,+ performanceCondition,} = createBountySchema.parse(await parseRequestBody(req));const groups = groupIds?.length@@ -64,7 +64,7 @@ export const POST = withWorkspace(async ({ workspace, req }) => {const bountyId = createId({ prefix: "bnty_" });// Create a workflow if there is a performance condition- if (condition) {+ if (performanceCondition && type === "performance") {const action: WorkflowAction = {type: WORKFLOW_ACTION_TYPES.AwardBounty,data: {@@ -76,8 +76,9 @@ export const POST = withWorkspace(async ({ workspace, req }) => {data: {id: createId({ prefix: "wf_" }),programId,- trigger: WORKFLOW_ATTRIBUTE_TRIGGER_MAP[condition.attribute],- triggerConditions: [condition],+ trigger:+ WORKFLOW_ATTRIBUTE_TRIGGER_MAP[performanceCondition.attribute],+ triggerConditions: [performanceCondition],actions: [action],},});@@ -95,9 +96,10 @@ export const POST = withWorkspace(async ({ workspace, req }) => {startsAt: startsAt!, // Can remove the ! when we're on a newer TS version (currently 5.4.4)endsAt,rewardAmount,- ...(submissionRequirements && {- submissionRequirements,- }),+ ...(submissionRequirements &&+ type === "submission" && {+ submissionRequirements,+ }),...(groups?.length && {groups: {createMany: {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 f4619f2641..bdff025df2 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@@ -74,9 +74,16 @@ const ACCORDION_ITEMS = [function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {const { id: workspaceId } = useWorkspace();- const [hasEndDate, setHasEndDate] = useState(false);- const [requireImage, setRequireImage] = useState(false);- const [requireUrl, setRequireUrl] = useState(false);+ const [hasEndDate, setHasEndDate] = useState(!!bounty?.endsAt);++ const [requireImage, setRequireImage] = useState(+ bounty?.submissionRequirements?.includes("image") || false,+ );++ const [requireUrl, setRequireUrl] = useState(+ bounty?.submissionRequirements?.includes("url") || false,+ );+const [openAccordions, setOpenAccordions] = useState(ACCORDION_ITEMS);const { makeRequest, isSubmitting } = useApiMutation<BountyProps>();@@ -92,7 +99,7 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {type: bounty?.type || "performance",submissionRequirements: bounty?.submissionRequirements || null,groupIds: bounty?.groups?.map(({ id }) => id) || null,- performanceCondition: {+ performanceCondition: bounty?.performanceCondition || {operator: "gte",},},