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.

Add bounty details and submission actions

Kiran K876270d7beb6
diff --git a/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts b/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts
index 93053cf2c6..3b9ea711fa 100644
--- a/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts
+++ b/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts
@@ -4,6 +4,19 @@ import { withWorkspace } from "@/lib/auth";
import { BountySchema } from "@/lib/zod/schemas/bounties";
import { NextResponse } from "next/server";
+// GET /api/bounties/[bountyId] - get a bounty
+export const GET = withWorkspace(async ({ workspace, params }) => {
+ const { bountyId } = params;
+ const programId = getDefaultProgramIdOrThrow(workspace);
+
+ const bounty = await getBountyOrThrow({
+ bountyId,
+ programId,
+ });
+
+ return NextResponse.json(BountySchema.parse(bounty));
+});
+
// PATCH /api/bounties/[bountyId] - update a bounty
export const PATCH = withWorkspace(async ({ workspace, params }) => {
const { bountyId } = params;
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-details.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-details.tsx
new file mode 100644
index 0000000000..1d0f0e69d8
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-details.tsx
@@ -0,0 +1,50 @@
+"use client";
+
+import useBounty from "@/lib/swr/use-bounty";
+import { formatDate } from "@dub/utils";
+import { CalendarDays, Trophy, Users } from "lucide-react";
+import { useParams } from "next/navigation";
+
+export function BountyDetails() {
+ const { bountyId } = useParams<{ bountyId: string }>();
+ const { bounty } = useBounty({ bountyId });
+
+ const total = 100;
+ const completed = 50;
+
+ return (
+ <div className="flex items-center gap-6">
+ <div className="flex h-[90px] w-[90px] shrink-0 items-center justify-center rounded-lg bg-neutral-100 p-5">
+ <Trophy className="size-12" />
+ </div>
+
+ {bounty && (
+ <div className="flex flex-1 flex-col gap-1.5">
+ <h3 className="text-base font-semibold leading-6 text-neutral-900">
+ {bounty.name}
+ </h3>
+
+ <div className="flex items-center space-x-2">
+ <CalendarDays className="size-4" />
+ <span className="text-sm font-medium text-neutral-500">
+ {formatDate(bounty.startsAt, { month: "short" })}
+ {" → "}
+ {bounty.endsAt
+ ? formatDate(bounty.endsAt, { month: "short" })
+ : "No end date"}
+ </span>
+ </div>
+
+ <div className="flex items-center space-x-2">
+ <Users className="size-4" />
+ <div className="text-sm text-neutral-500">
+ <span className="font-medium text-neutral-700">{completed}</span>{" "}
+ of <span className="font-medium text-neutral-700">{total}</span>{" "}
+ partners completed
+ </div>
+ </div>
+ </div>
+ )}
+ </div>
+ );
+}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions.tsx
new file mode 100644
index 0000000000..79afc7116a
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions.tsx
@@ -0,0 +1,11 @@
+"use client";
+
+import useBounty from "@/lib/swr/use-bounty";
+import { useParams } from "next/navigation";
+
+export function BountySubmissions() {
+ const { bountyId } = useParams<{ bountyId: string }>();
+ const { bounty } = useBounty({ bountyId });
+
+ return <div></div>;
+}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/page.tsx
index b3ce4db7f7..49db3e082f 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/page.tsx
@@ -2,6 +2,8 @@ import { PageContent } from "@/ui/layout/page-content";
import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";
import { ChevronRight } from "@dub/ui";
import { Trophy } from "lucide-react";
+import { BountyDetails } from "./bounty-details";
+import { BountySubmissions } from "./bounty-submissions";
export default function Page() {
return (
@@ -21,7 +23,10 @@ export default function Page() {
}
>
<PageWidthWrapper>
- <></>
+ <div>
+ <BountyDetails />
+ <BountySubmissions />
+ </div>
</PageWidthWrapper>
</PageContent>
);
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 594066cd86..ce1f15d41a 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
@@ -24,9 +24,9 @@ export function BountyCard({ bounty }: { bounty: BountyProps }) {
{name}
</h3>
- <div className="flex items-center space-x-2 text-sm text-neutral-500">
+ <div className="flex items-center space-x-2">
<CalendarDays className="size-4" />
- <span>
+ <span className="text-sm text-neutral-500">
{formatDate(startsAt, { month: "short" })}
{endsAt && (
<>
@@ -37,11 +37,12 @@ export function BountyCard({ bounty }: { bounty: BountyProps }) {
</span>
</div>
- <div className="flex items-center space-x-2 text-sm text-neutral-700">
+ <div className="flex items-center space-x-2">
<Users className="size-4" />
- <div>
- <span className="font-medium">{completed}</span> of{" "}
- <span className="font-medium">{total}</span> partners completed
+ <div className="text-sm text-neutral-500">
+ <span className="font-medium text-neutral-700">{completed}</span>{" "}
+ of <span className="font-medium text-neutral-700">{total}</span>{" "}
+ partners completed
</div>
</div>
</div>
diff --git a/apps/web/lib/actions/partners/approve-bounty-submission.ts b/apps/web/lib/actions/partners/approve-bounty-submission.ts
new file mode 100644
index 0000000000..c31edb3cae
--- /dev/null
+++ b/apps/web/lib/actions/partners/approve-bounty-submission.ts
@@ -0,0 +1,48 @@
+"use server";
+
+import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
+import { prisma } from "@dub/prisma";
+import { z } from "zod";
+import { authActionClient } from "../safe-action";
+
+const schema = z.object({
+ workspaceId: z.string(),
+ submissionId: z.string(),
+});
+
+export const approveBountySubmissionAction = authActionClient
+ .schema(schema)
+ .action(async ({ parsedInput, ctx }) => {
+ const { workspace, user } = ctx;
+ const { submissionId } = parsedInput;
+
+ const programId = getDefaultProgramIdOrThrow(workspace);
+
+ const bountySubmission = await prisma.bountySubmission.findUniqueOrThrow({
+ where: {
+ id: submissionId,
+ },
+ });
+
+ if (bountySubmission.programId !== programId) {
+ throw new Error("Bounty submission does not belong to this program.");
+ }
+
+ if (bountySubmission.status === "approved") {
+ throw new Error("Bounty submission already approved.");
+ }
+
+ await prisma.bountySubmission.update({
+ where: {
+ id: submissionId,
+ },
+ data: {
+ status: "approved",
+ reviewedAt: new Date(),
+ userId: user.id,
+ },
+ });
+
+ // TODO:
+ // Record audit log
+ });
diff --git a/apps/web/lib/actions/partners/reject-bounty-submission.ts b/apps/web/lib/actions/partners/reject-bounty-submission.ts
new file mode 100644
index 0000000000..5b3ca8785e
--- /dev/null
+++ b/apps/web/lib/actions/partners/reject-bounty-submission.ts
@@ -0,0 +1,52 @@
+"use server";
+
+import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
+import { prisma } from "@dub/prisma";
+import { z } from "zod";
+import { authActionClient } from "../safe-action";
+
+const schema = z.object({
+ workspaceId: z.string(),
+ submissionId: z.string(),
+ rejectionReason: z.string(), // TODO: Add a list of reasons as enum
+ rejectionNote: z.string().max(500).optional(),
+});
+
+export const rejectBountySubmissionAction = authActionClient
+ .schema(schema)
+ .action(async ({ parsedInput, ctx }) => {
+ const { workspace, user } = ctx;
+ const { submissionId, rejectionReason, rejectionNote } = parsedInput;
+
+ const programId = getDefaultProgramIdOrThrow(workspace);
+
+ const bountySubmission = await prisma.bountySubmission.findUniqueOrThrow({
+ where: {
+ id: submissionId,
+ },
+ });
+
+ if (bountySubmission.programId !== programId) {
+ throw new Error("Bounty submission does not belong to this program.");
+ }
+
+ if (bountySubmission.status === "rejected") {
+ throw new Error("Bounty submission already rejected.");
+ }
+
+ await prisma.bountySubmission.update({
+ where: {
+ id: submissionId,
+ },
+ data: {
+ status: "rejected",
+ reviewedAt: new Date(),
+ userId: user.id,
+ rejectionReason,
+ rejectionNote,
+ },
+ });
+
+ // TODO:
+ // Record audit log
+ });
diff --git a/apps/web/lib/swr/use-bounty.ts b/apps/web/lib/swr/use-bounty.ts
new file mode 100644
index 0000000000..2df02c9aca
--- /dev/null
+++ b/apps/web/lib/swr/use-bounty.ts
@@ -0,0 +1,25 @@
+import { fetcher } from "@dub/utils";
+import useSWR from "swr";
+import { BountyProps } from "../types";
+import useWorkspace from "./use-workspace";
+
+export default function useBounty({ bountyId }: { bountyId: string }) {
+ const { id: workspaceId } = useWorkspace();
+
+ const {
+ data: bounty,
+ error,
+ isLoading,
+ } = useSWR<BountyProps>(
+ workspaceId && bountyId
+ ? `/api/bounties/${bountyId}?workspaceId=${workspaceId}`
+ : undefined,
+ fetcher,
+ );
+
+ return {
+ bounty,
+ isLoading,
+ error,
+ };
+}