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.

Delete bounties

Tim Wilsonddd434ec68a9
diff --git a/apps/web/app/(ee)/api/bounties/route.ts b/apps/web/app/(ee)/api/bounties/route.ts
index b94c369299..e1af716ab8 100644
--- a/apps/web/app/(ee)/api/bounties/route.ts
+++ b/apps/web/app/(ee)/api/bounties/route.ts
@@ -11,6 +11,7 @@ import {
getBountiesQuerySchema,
} from "@/lib/zod/schemas/bounties";
import { prisma } from "@dub/prisma";
+import { Prisma } from "@prisma/client";
import { NextResponse } from "next/server";
import { z } from "zod";
@@ -32,8 +33,15 @@ export const POST = withWorkspace(async ({ workspace, req }) => {
const programId = getDefaultProgramIdOrThrow(workspace);
// TODO: [bounties] Persist performance logic to workflow and groupIds to bountyGroup
- const { name, description, type, rewardAmount, startsAt, endsAt } =
- createBountySchema.parse(await parseRequestBody(req));
+ const {
+ name,
+ description,
+ type,
+ rewardAmount,
+ startsAt,
+ endsAt,
+ submissionRequirements,
+ } = createBountySchema.parse(await parseRequestBody(req));
const workflow = await createWorkflow({
program: {
@@ -57,6 +65,7 @@ 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 ?? Prisma.JsonNull,
},
});
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.tsx
index 5b5a899ba5..d84f6d48ac 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
@@ -1,19 +1,55 @@
+import { mutatePrefix } from "@/lib/swr/mutate";
+import useWorkspace from "@/lib/swr/use-workspace";
import { BountyExtendedProps } from "@/lib/types";
+import { useConfirmModal } from "@/ui/modals/confirm-modal";
import { ProgramOverviewCard } from "@/ui/partners/overview/program-overview-card";
import { Button, MenuItem, Popover, useRouterStuff } from "@dub/ui";
-import { CalendarDays, Dots, PenWriting, Users } from "@dub/ui/icons";
+import { CalendarDays, Dots, PenWriting, Trash, Users } from "@dub/ui/icons";
import { formatDate } from "@dub/utils";
import { Command } from "cmdk";
import Link from "next/link";
import { useState } from "react";
+import { toast } from "sonner";
export function BountyCard({ bounty }: { bounty: BountyExtendedProps }) {
+ const { id: workspaceId } = useWorkspace();
const { queryParams } = useRouterStuff();
const [isMenuOpen, setIsMenuOpen] = useState(false);
+ const { confirmModal: deleteModal, setShowConfirmModal: setShowDeleteModal } =
+ useConfirmModal({
+ title: "Delete bounty",
+ description: "Are you sure you want to delete this bounty?",
+ onConfirm: async () => {
+ toast.promise(
+ async () => {
+ const response = await fetch(
+ `/api/bounties/${bounty.id}?workspaceId=${workspaceId}`,
+ {
+ method: "DELETE",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ },
+ );
+
+ if (!response.ok) throw new Error("Failed to delete bounty");
+
+ mutatePrefix("/api/bounties");
+ },
+ {
+ loading: "Deleting bounty...",
+ success: "Bounty deleted successfully!",
+ error: (err) => err,
+ },
+ );
+ },
+ });
+
return (
<ProgramOverviewCard className="relative cursor-pointer border-neutral-200 p-5 transition-all hover:border-neutral-300 hover:shadow-lg">
+ {deleteModal}
<Link
href={`/program/bounties/${bounty.id}`}
className="flex flex-col gap-5"
@@ -83,6 +119,17 @@ export function BountyCard({ bounty }: { bounty: BountyExtendedProps }) {
>
Edit bounty
</MenuItem>
+ <MenuItem
+ as={Command.Item}
+ icon={Trash}
+ variant="danger"
+ onSelect={() => {
+ setIsMenuOpen(false);
+ setShowDeleteModal(true);
+ }}
+ >
+ Delete bounty
+ </MenuItem>
</Command.List>
</Command>
}