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.

reopenBountySubmission

Steven Tey24a633e96990
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-row-menu.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-row-menu.tsx
new file mode 100644
index 0000000000..494b5715e4
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-row-menu.tsx
@@ -0,0 +1,135 @@
+import { reopenBountySubmissionAction } from "@/lib/actions/partners/reopen-bounty-submission";
+import { mutatePrefix } from "@/lib/swr/mutate";
+import useWorkspace from "@/lib/swr/use-workspace";
+import { BountySubmissionProps } from "@/lib/types";
+import { useConfirmModal } from "@/ui/modals/confirm-modal";
+import { Button, Icon, Popover, useRouterStuff } from "@dub/ui";
+import { ArrowsOppositeDirectionX, Dots, Eye } from "@dub/ui/icons";
+import { cn } from "@dub/utils";
+import { Row } from "@tanstack/react-table";
+import { Command } from "cmdk";
+import { useParams } from "next/navigation";
+import { useState } from "react";
+import { toast } from "sonner";
+
+export function BountySubmissionRowMenu({
+ row,
+}: {
+ row: Row<BountySubmissionProps>;
+}) {
+ const { bountyId } = useParams<{ bountyId: string }>();
+ const [isOpen, setIsOpen] = useState(false);
+ const { queryParams } = useRouterStuff();
+ const { id: workspaceId } = useWorkspace();
+
+ const submission = row.original.submission;
+
+ // Only show menu if there's a submission
+ if (!submission) {
+ return null;
+ }
+
+ const { setShowConfirmModal, confirmModal } = useConfirmModal({
+ title: "Reopen submission",
+ description: (
+ <>
+ Are you sure you want to reopen this bounty submission? This will reset
+ the submission back to draft status.
+ </>
+ ),
+ confirmText: "Reopen",
+ onConfirm: async () => {
+ try {
+ await reopenBountySubmissionAction({
+ workspaceId: workspaceId!,
+ submissionId: submission.id,
+ });
+ await mutatePrefix(`/api/bounties/${bountyId}/submissions`);
+ toast.success("Bounty submission reopened successfully");
+ } catch (error) {
+ toast.error(
+ error instanceof Error
+ ? error.message
+ : "Failed to reopen bounty submission",
+ );
+ }
+ },
+ });
+
+ return (
+ <>
+ {confirmModal}
+ <Popover
+ openPopover={isOpen}
+ setOpenPopover={setIsOpen}
+ content={
+ <Command tabIndex={0} loop className="pointer-events-auto">
+ <Command.List className="flex w-screen flex-col gap-1 text-sm focus-visible:outline-none sm:w-auto sm:min-w-[180px]">
+ <Command.Group className="p-1.5">
+ <MenuItem
+ icon={Eye}
+ label="Review submission"
+ onSelect={() => {
+ queryParams({
+ set: {
+ submissionId: submission.id,
+ },
+ scroll: false,
+ });
+ setIsOpen(false);
+ }}
+ />
+
+ {submission.status === "submitted" && (
+ <MenuItem
+ icon={ArrowsOppositeDirectionX}
+ label="Reopen submission"
+ onSelect={() => {
+ setShowConfirmModal(true);
+ setIsOpen(false);
+ }}
+ />
+ )}
+ </Command.Group>
+ </Command.List>
+ </Command>
+ }
+ align="end"
+ >
+ <Button
+ type="button"
+ className="h-8 whitespace-nowrap px-2"
+ variant="outline"
+ icon={<Dots className="h-4 w-4 shrink-0" />}
+ />
+ </Popover>
+ </>
+ );
+}
+
+function MenuItem({
+ icon: IconComp,
+ label,
+ onSelect,
+ disabled,
+}: {
+ icon: Icon;
+ label: string;
+ onSelect: () => void;
+ disabled?: boolean;
+}) {
+ return (
+ <Command.Item
+ className={cn(
+ "flex cursor-pointer select-none items-center gap-2 whitespace-nowrap rounded-md p-2 text-sm text-neutral-600",
+ "data-[selected=true]:bg-neutral-100",
+ disabled && "cursor-not-allowed opacity-50",
+ )}
+ onSelect={onSelect}
+ disabled={disabled}
+ >
+ <IconComp className="size-4 shrink-0 text-neutral-500" />
+ {label}
+ </Command.Item>
+ );
+}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx
index 2a9c726933..7af5306da7 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx
@@ -33,6 +33,7 @@ import { useParams } from "next/navigation";
import { useEffect, useMemo, useState } from "react";
import useSWR from "swr";
import { BountySubmissionDetailsSheet } from "./bounty-submission-details-sheet";
+import { BountySubmissionRowMenu } from "./bounty-submission-row-menu";
import { BOUNTY_SUBMISSION_STATUS_BADGES } from "./bounty-submission-status-badges";
import { useBountySubmissionFilters } from "./use-bounty-submission-filters";
@@ -265,6 +266,16 @@ export function BountySubmissionsTable() {
},
]
: []),
+
+ // Menu
+ {
+ id: "menu",
+ enableHiding: false,
+ minSize: 43,
+ size: 43,
+ maxSize: 43,
+ cell: ({ row }) => <BountySubmissionRowMenu row={row} />,
+ },
],
[
groups,
@@ -280,6 +291,7 @@ export function BountySubmissionsTable() {
const { table, ...tableProps } = useTable({
data: submissions || [],
columns,
+ columnPinning: { right: ["menu"] },
onRowClick: (row) => {
if (!row.original.submission) {
return;
diff --git a/apps/web/lib/actions/partners/reopen-bounty-submission.ts b/apps/web/lib/actions/partners/reopen-bounty-submission.ts
new file mode 100644
index 0000000000..2cfebcf069
--- /dev/null
+++ b/apps/web/lib/actions/partners/reopen-bounty-submission.ts
@@ -0,0 +1,77 @@
+"use server";
+
+import { recordAuditLog } from "@/lib/api/audit-logs/record-audit-log";
+import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
+import { BountySubmissionSchema } from "@/lib/zod/schemas/bounties";
+// Email notification can be added later if needed
+import { prisma } from "@dub/prisma";
+import { waitUntil } from "@vercel/functions";
+import { z } from "zod";
+import { authActionClient } from "../safe-action";
+
+const schema = z.object({
+ workspaceId: z.string(),
+ submissionId: z.string(),
+});
+
+// Reopen a bounty submission that was previously submitted
+export const reopenBountySubmissionAction = authActionClient
+ .schema(schema)
+ .action(async ({ parsedInput, ctx }) => {
+ const { workspace, user } = ctx;
+ const { submissionId } = parsedInput;
+
+ const programId = getDefaultProgramIdOrThrow(workspace);
+
+ const { program, bounty, partner, ...bountySubmission } =
+ await prisma.bountySubmission.findUniqueOrThrow({
+ where: {
+ id: submissionId,
+ },
+ include: {
+ program: true,
+ bounty: true,
+ partner: true,
+ commission: true,
+ },
+ });
+
+ if (bountySubmission.programId !== programId) {
+ throw new Error("Bounty submission does not belong to this program.");
+ }
+
+ if (bountySubmission.status !== "submitted") {
+ throw new Error("Bounty submission is not submitted yet.");
+ }
+
+ await prisma.bountySubmission.update({
+ where: {
+ id: submissionId,
+ },
+ data: {
+ status: "draft",
+ },
+ });
+
+ waitUntil(
+ Promise.allSettled([
+ recordAuditLog({
+ workspaceId: workspace.id,
+ programId: program.id,
+ action: "bounty_submission.reopened",
+ description: `Bounty submission reopened for ${partner.id}`,
+ actor: user,
+ targets: [
+ {
+ type: "bounty_submission",
+ id: submissionId,
+ metadata: BountySubmissionSchema.parse(bountySubmission),
+ },
+ ],
+ }),
+
+ // Email notification can be added later if needed
+ Promise.resolve(),
+ ]),
+ );
+ });
diff --git a/apps/web/lib/api/audit-logs/schemas.ts b/apps/web/lib/api/audit-logs/schemas.ts
index 609b02782b..8ba00cda59 100644
--- a/apps/web/lib/api/audit-logs/schemas.ts
+++ b/apps/web/lib/api/audit-logs/schemas.ts
@@ -85,6 +85,7 @@ const actionSchema = z.enum([
"bounty.deleted",
"bounty_submission.approved",
"bounty_submission.rejected",
+ "bounty_submission.reopened",
]);
export const auditLogTarget = z.union([