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.

Refactor bounty submissions and details logic

Kiran Kf0161bf31a0a
diff --git a/apps/web/app/(ee)/api/bounties/[bountyId]/submissions/route.ts b/apps/web/app/(ee)/api/bounties/[bountyId]/submissions/route.ts
index 685b08f57b..fb36c2ff90 100644
--- a/apps/web/app/(ee)/api/bounties/[bountyId]/submissions/route.ts
+++ b/apps/web/app/(ee)/api/bounties/[bountyId]/submissions/route.ts
@@ -4,6 +4,7 @@ import { withWorkspace } from "@/lib/auth";
import { BountySubmissionSchema } from "@/lib/zod/schemas/bounties";
import { prisma } from "@dub/prisma";
import { NextResponse } from "next/server";
+import { z } from "zod";
// TODO:
// Add filter, pagination
@@ -29,5 +30,5 @@ export const GET = withWorkspace(async ({ workspace, params }) => {
},
});
- return NextResponse.json(BountySubmissionSchema.parse(submissions));
+ return NextResponse.json(z.array(BountySubmissionSchema).parse(submissions));
});
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
index 1d0f0e69d8..23a41f3014 100644
--- 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
@@ -9,7 +9,6 @@ export function BountyDetails() {
const { bountyId } = useParams<{ bountyId: string }>();
const { bounty } = useBounty({ bountyId });
- const total = 100;
const completed = 50;
return (
@@ -39,7 +38,10 @@ export function BountyDetails() {
<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>{" "}
+ of{" "}
+ <span className="font-medium text-neutral-700">
+ {bounty.submissionsCount}
+ </span>{" "}
partners completed
</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
deleted file mode 100644
index 79afc7116a..0000000000
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions.tsx
+++ /dev/null
@@ -1,11 +0,0 @@
-"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 49db3e082f..fd67611150 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
@@ -3,7 +3,7 @@ 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";
+import { BountySubmissionsTable } from "./bounty-submissions-table";
export default function Page() {
return (
@@ -25,7 +25,7 @@ export default function Page() {
<PageWidthWrapper>
<div>
<BountyDetails />
- <BountySubmissions />
+ <BountySubmissionsTable />
</div>
</PageWidthWrapper>
</PageContent>
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.tsx
index 31289b4225..2e2b08908a 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
@@ -28,7 +28,6 @@ import { z } from "zod";
type BountySheetProps = {
setIsOpen: Dispatch<SetStateAction<boolean>>;
- partnerId?: string;
};
type FormData = z.infer<typeof createBountySchema>;
@@ -456,6 +455,6 @@ export function useBountySheet(
BountySheet: (
<BountySheet setIsOpen={setIsOpen} isOpen={isOpen} {...props} />
),
- setIsOpen,
+ setShowCreateBountySheet: setIsOpen,
};
}
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.tsx
index 8e12be8966..7f28dd4878 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
@@ -3,9 +3,11 @@
import useWorkspace from "@/lib/swr/use-workspace";
import { BountyProps } from "@/lib/types";
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
+import { Button } from "@dub/ui";
import { fetcher } from "@dub/utils";
import { Trophy } from "lucide-react";
import useSWR from "swr";
+import { useBountySheet } from "./add-edit-bounty-sheet";
import { BountyCard, BountyCardSkeleton } from "./bounty-card";
// TODO:
@@ -14,6 +16,10 @@ import { BountyCard, BountyCardSkeleton } from "./bounty-card";
export function BountyList() {
const { id: workspaceId, defaultProgramId } = useWorkspace();
+ const { BountySheet, setShowCreateBountySheet } = useBountySheet({
+ nested: false,
+ });
+
const {
data: bounties,
isLoading,
@@ -43,15 +49,25 @@ export function BountyList() {
))}
</div>
) : (
- <AnimatedEmptyState
- title="No bounties found"
- description="No bounties have been created for this program yet."
- cardContent={() => (
- <>
- <Trophy className="size-4 text-neutral-700" />
- <div className="h-2.5 w-24 min-w-0 rounded-sm bg-neutral-200" />
- </>
- )}
- />
+ <>
+ {BountySheet}
+ <AnimatedEmptyState
+ title="No bounties found"
+ description="No bounties have been created for this program yet."
+ cardContent={() => (
+ <>
+ <Trophy className="size-4 text-neutral-700" />
+ <div className="h-2.5 w-24 min-w-0 rounded-sm bg-neutral-200" />
+ </>
+ )}
+ addButton={
+ <Button
+ text="Create bounty"
+ variant="primary"
+ onClick={() => setShowCreateBountySheet(true)}
+ />
+ }
+ />
+ </>
);
}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/create-bounty-button.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/create-bounty-button.tsx
index c644456d49..ee5bff5c37 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/create-bounty-button.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/create-bounty-button.tsx
@@ -4,7 +4,7 @@ import { Button, useKeyboardShortcut } from "@dub/ui";
import { useBountySheet } from "./add-edit-bounty-sheet";
export function CreateBountyButton() {
- const { BountySheet, setIsOpen: setShowCreateBountySheet } = useBountySheet({
+ const { BountySheet, setShowCreateBountySheet } = useBountySheet({
nested: false,
partnerId: "",
});
diff --git a/apps/web/lib/api/bounty/get-bounty-or-throw.ts b/apps/web/lib/api/bounty/get-bounty-or-throw.ts
index 9d8bedc6a1..2eaa88fcb7 100644
--- a/apps/web/lib/api/bounty/get-bounty-or-throw.ts
+++ b/apps/web/lib/api/bounty/get-bounty-or-throw.ts
@@ -12,6 +12,13 @@ export const getBountyOrThrow = async ({
where: {
id: bountyId,
},
+ include: {
+ _count: {
+ select: {
+ submissions: true,
+ },
+ },
+ },
});
if (!bounty) {
@@ -28,5 +35,8 @@ export const getBountyOrThrow = async ({
});
}
- return bounty;
+ return {
+ ...bounty,
+ submissionsCount: bounty._count.submissions,
+ };
};
diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.ts
index 567e4c84e3..62bf510b07 100644
--- a/apps/web/lib/zod/schemas/bounties.ts
+++ b/apps/web/lib/zod/schemas/bounties.ts
@@ -44,6 +44,7 @@ export const BountySchema = z.object({
export const BountySubmissionSchema = z.object({
id: z.string(),
description: z.string().nullable(),
+ evidenceUrl: z.string(),
status: z.nativeEnum(BountySubmissionStatus),
createdAt: z.date(),
updatedAt: z.date(),
@@ -66,7 +67,6 @@ export const BountySubmissionSchema = z.object({
user: UserSchema.pick({
id: true,
name: true,
- email: true,
image: true,
}).nullable(),
});
diff --git a/apps/web/scripts/bounty.ts b/apps/web/scripts/bounty.ts
index 46e991acc8..e053ad5d18 100644
--- a/apps/web/scripts/bounty.ts
+++ b/apps/web/scripts/bounty.ts
@@ -2,20 +2,42 @@ import { createId } from "@/lib/api/create-id";
import { prisma } from "@dub/prisma";
import "dotenv-flow/config";
+// TODO:
+// Remove this
async function main() {
- const bounty = await prisma.bounty.create({
- data: {
- id: createId({ prefix: "bounty_" }),
- programId: "prog_1K21SX1XVES0B7PJCCSQ099ZF",
- name: "Very long name for a bounty that will be truncated after certain length",
- type: "submission",
- startsAt: new Date(),
- // endsAt: new Date(),
- rewardAmount: 1000,
+ // const bounty = await prisma.bounty.create({
+ // data: {
+ // id: createId({ prefix: "bounty_" }),
+ // programId: "prog_1K21SX1XVES0B7PJCCSQ099ZF",
+ // name: "Very long name for a bounty that will be truncated after certain length",
+ // type: "submission",
+ // startsAt: new Date(),
+ // rewardAmount: 1000,
+ // },
+ // });
+
+ // console.log(bounty);
+
+ const programId = "prog_1K21SX1XVES0B7PJCCSQ099ZF";
+ const bountyId = "bounty_1K290RBGA500N6DR92TW2QVSV"
+
+ const programEnrollments = await prisma.programEnrollment.findMany({
+ where: {
+ programId,
},
});
- console.log(bounty);
+ // Create a submission for each partner
+ const submissions = programEnrollments.map((enrollment) => ({
+ programId,
+ partnerId: enrollment.partnerId,
+ bountyId,
+ evidenceUrl: ""
+ }));
+
+ await prisma.bountySubmission.createMany({
+ data: submissions,
+ });
}
main();