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 submission

Tim Wilsonbb5f0d2fccea
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/bounty-card.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/bounty-card.tsx
index 8267d23472..bfcc575a86 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/bounty-card.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/bounty-card.tsx
@@ -44,6 +44,14 @@ export function BountyCard({ bounty }: { bounty: BountyWithSubmissionsProps }) {
<div className="flex grow flex-col justify-end">
{submission ? (
submission.status === "pending" ? (
+ <div className="flex h-7 w-fit items-center gap-1 rounded-lg bg-orange-100 px-2.5">
+ <span className="text-xs font-medium text-orange-600">
+ Submitted{" "}
+ {submission.createdAt &&
+ formatDate(submission.createdAt, { month: "short" })}
+ </span>
+ </div>
+ ) : (
<div className="flex h-7 w-fit items-center gap-1 rounded-lg bg-neutral-100 px-2.5">
<CircleCheckFill className="size-3 text-green-600" />
<span className="text-content-default text-xs font-medium">
@@ -52,14 +60,6 @@ export function BountyCard({ bounty }: { bounty: BountyWithSubmissionsProps }) {
formatDate(submission.reviewedAt, { month: "short" })}
</span>
</div>
- ) : (
- <div className="flex h-7 w-fit items-center gap-1 rounded-lg bg-orange-100 px-2.5">
- <span className="text-xs font-medium text-orange-600">
- Submitted{" "}
- {submission.createdAt &&
- formatDate(submission.createdAt, { month: "short" })}
- </span>
- </div>
)
) : (
<Button
diff --git a/apps/web/lib/actions/partners/create-bounty-submission.ts b/apps/web/lib/actions/partners/create-bounty-submission.ts
new file mode 100644
index 0000000000..8121145630
--- /dev/null
+++ b/apps/web/lib/actions/partners/create-bounty-submission.ts
@@ -0,0 +1,47 @@
+"use server";
+
+import { getBountyOrThrow } from "@/lib/api/bounties/get-bounty-or-throw";
+import { getProgramEnrollmentOrThrow } from "@/lib/api/programs/get-program-enrollment-or-throw";
+import { BountySubmissionFileSchema } from "@/lib/zod/schemas/bounties";
+import { prisma } from "@dub/prisma";
+import { z } from "zod";
+import { authPartnerActionClient } from "../safe-action";
+
+const schema = z.object({
+ programId: z.string(),
+ bountyId: z.string(),
+ files: z.array(BountySubmissionFileSchema),
+ urls: z.array(z.string().url()),
+ description: z.string().optional(),
+});
+
+export const createBountySubmissionAction = authPartnerActionClient
+ .schema(schema)
+ .action(async ({ ctx, parsedInput }) => {
+ const { partner } = ctx;
+ const { programId, bountyId, files, urls, description } = parsedInput;
+
+ await Promise.all([
+ getProgramEnrollmentOrThrow({
+ partnerId: partner.id,
+ programId,
+ }),
+ await getBountyOrThrow({
+ bountyId,
+ programId,
+ }),
+ ]);
+
+ await prisma.bountySubmission.create({
+ data: {
+ programId,
+ bountyId,
+ partnerId: partner.id,
+ files,
+ urls,
+ description,
+ },
+ });
+
+ return { success: true };
+ });
diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.ts
index d000ee3be8..5274dddb22 100644
--- a/apps/web/lib/zod/schemas/bounties.ts
+++ b/apps/web/lib/zod/schemas/bounties.ts
@@ -58,9 +58,8 @@ export const BountySchemaExtended = BountySchema.extend({
});
export const BountySubmissionFileSchema = z.object({
+ url: z.string(),
fileName: z.string(),
- storagePath: z.string(),
- mimeType: z.string(),
size: z.number(),
});
diff --git a/apps/web/ui/partners/bounties/claim-bounty-modal.tsx b/apps/web/ui/partners/bounties/claim-bounty-modal.tsx
index 8a05755637..4dcbaaeecb 100644
--- a/apps/web/ui/partners/bounties/claim-bounty-modal.tsx
+++ b/apps/web/ui/partners/bounties/claim-bounty-modal.tsx
@@ -1,4 +1,6 @@
+import { createBountySubmissionAction } from "@/lib/actions/partners/create-bounty-submission";
import { uploadBountySubmissionFileAction } from "@/lib/actions/partners/upload-bounty-submission-file";
+import { mutatePrefix } from "@/lib/swr/mutate";
import useProgramEnrollment from "@/lib/swr/use-program-enrollment";
import { BountyProps } from "@/lib/types";
import { X } from "@/ui/shared/icons";
@@ -95,14 +97,45 @@ function ClaimBountyModalContent({
);
};
+ const { executeAsync: createSubmission, isPending } = useAction(
+ createBountySubmissionAction,
+ );
+
const imageRequired = bounty.submissionRequirements?.includes("image");
const urlRequired = bounty.submissionRequirements?.includes("url");
return (
<form
- onSubmit={(e) => {
+ onSubmit={async (e) => {
e.preventDefault();
- toast.info("WIP");
+ if (!programEnrollment) return;
+
+ try {
+ const result = await createSubmission({
+ programId: programEnrollment.programId,
+ bountyId: bounty.id,
+ files: files
+ .filter(({ file, url }) => file && url)
+ .map(({ file, url }) => ({
+ url: url!,
+ fileName: file?.name || "File",
+ size: file?.size || 0,
+ })),
+ urls: urls.map(({ url }) => url).filter(Boolean),
+ description,
+ });
+
+ if (!result?.data?.success)
+ throw new Error("Failed to create submission");
+
+ mutatePrefix(
+ `/api/partner-profile/programs/${programEnrollment.program.slug}/bounties`,
+ );
+ toast.success("Submission created successfully!");
+ setShowModal(false);
+ } catch (e) {
+ toast.error("Failed to create submission. Please try again.");
+ }
}}
className="scrollbar-hide max-h-[calc(100dvh-50px)] overflow-y-auto"
>
@@ -310,6 +343,7 @@ function ClaimBountyModalContent({
text={isFormOpen ? "Submit proof" : "Claim bounty"}
className="grow rounded-lg"
onClick={isFormOpen ? undefined : () => setIsFormOpen(true)}
+ loading={isPending}
disabled={
isFormOpen &&
((imageRequired && !files.length) ||