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 draft status for bounty submissions

Kiran K0b46ea11559f
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/partner-bounty-card.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/partner-bounty-card.tsx
index c4dfc21dd3..eddc5a4ef5 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/partner-bounty-card.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/partner-bounty-card.tsx
@@ -54,43 +54,11 @@ export function PartnerBountyCard({ bounty }: { bounty: PartnerBountyProps }) {
</div>
<div className="flex grow flex-col justify-end">
- {submission ? (
- submission.status === "pending" ? (
- <StatusBadge variant="pending" icon={null}>
- Submitted{" "}
- {submission.createdAt &&
- formatDate(submission.createdAt, { month: "short" })}
- </StatusBadge>
- ) : submission.status === "rejected" ? (
- <StatusBadge variant="error" icon={null}>
- Rejected
- </StatusBadge>
- ) : (
- <StatusBadge variant="success">
- {bounty.type === "performance" ? (
- <>
- Completed{" "}
- {formatDate(submission.createdAt, { month: "short" })}
- </>
- ) : (
- <>
- Confirmed{" "}
- {submission.reviewedAt &&
- formatDate(submission.reviewedAt, { month: "short" })}
- </>
- )}
- </StatusBadge>
- )
- ) : bounty.type === "performance" ? (
- <BountyPerformance bounty={bounty} />
- ) : (
- <div
- className="group-hover:ring-border-subtle flex h-7 w-fit items-center rounded-lg bg-black px-2.5 text-sm text-white transition-all group-hover:ring-2"
- onClick={() => setShowClaimBountyModal(true)}
- >
- Claim bounty
- </div>
- )}
+ {renderSubmissionStatus({
+ bounty,
+ submission,
+ setShowClaimBountyModal,
+ })}
</div>
</button>
</>
@@ -115,3 +83,72 @@ export const PartnerBountyCardSkeleton = () => {
</div>
);
};
+
+function renderSubmissionStatus({
+ bounty,
+ submission,
+ setShowClaimBountyModal,
+}: {
+ bounty: PartnerBountyProps;
+ submission: PartnerBountyProps["submission"];
+ setShowClaimBountyModal: (show: boolean) => void;
+}) {
+ if (!submission) {
+ return bounty.type === "performance" ? (
+ <BountyPerformance bounty={bounty} />
+ ) : (
+ <div
+ className="group-hover:ring-border-subtle flex h-7 w-fit items-center rounded-lg bg-black px-2.5 text-sm text-white transition-all group-hover:ring-2"
+ onClick={() => setShowClaimBountyModal(true)}
+ >
+ Claim bounty
+ </div>
+ );
+ }
+
+ switch (submission.status) {
+ case "draft":
+ return (
+ <div
+ className="group-hover:ring-border-subtle flex h-7 w-fit items-center rounded-lg bg-black px-2.5 text-sm text-white transition-all group-hover:ring-2"
+ onClick={() => setShowClaimBountyModal(true)}
+ >
+ Continue submission
+ </div>
+ );
+
+ case "pending":
+ return (
+ <StatusBadge variant="pending" icon={null}>
+ Submitted{" "}
+ {submission.createdAt &&
+ formatDate(submission.createdAt, { month: "short" })}
+ </StatusBadge>
+ );
+
+ case "rejected":
+ return (
+ <StatusBadge variant="error" icon={null}>
+ Rejected
+ </StatusBadge>
+ );
+
+ case "approved":
+ default:
+ return (
+ <StatusBadge variant="success">
+ {bounty.type === "performance" ? (
+ <>
+ Completed {formatDate(submission.createdAt, { month: "short" })}
+ </>
+ ) : (
+ <>
+ Confirmed{" "}
+ {submission.reviewedAt &&
+ formatDate(submission.reviewedAt, { month: "short" })}
+ </>
+ )}
+ </StatusBadge>
+ );
+ }
+}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx
index 4d2a988fad..caeb6e7956 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx
@@ -326,11 +326,16 @@ function BountySubmissionDetailsSheetContent({
variant="danger"
text="Reject"
disabledTooltip={
- submission.status === "rejected"
- ? "Bounty submission already rejected."
- : undefined
+ submission.status === "draft"
+ ? "Bounty submission is in progress."
+ : submission.status === "rejected"
+ ? "Bounty submission already rejected."
+ : undefined
+ }
+ disabled={
+ isApprovingBountySubmission ||
+ submission.status === "draft"
}
- disabled={isApprovingBountySubmission}
onClick={() => setShowRejectModal(true)}
/>
@@ -340,7 +345,12 @@ function BountySubmissionDetailsSheetContent({
text="Approve"
loading={isApprovingBountySubmission}
onClick={() => setShowApproveBountySubmissionModal(true)}
- disabled={!isValidForm}
+ disabledTooltip={
+ submission.status === "draft"
+ ? "Bounty submission is in progress."
+ : undefined
+ }
+ disabled={!isValidForm || submission.status === "draft"}
/>
</div>
</div>
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-status-badges.ts b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-status-badges.ts
index ca59e05a53..7df461583f 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-status-badges.ts
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-status-badges.ts
@@ -1,6 +1,12 @@
import { CircleCheck, CircleHalfDottedCheck, CircleXmark } from "@dub/ui/icons";
export const BOUNTY_SUBMISSION_STATUS_BADGES = {
+ draft: {
+ label: "In progress",
+ variant: "new",
+ icon: CircleHalfDottedCheck,
+ iconClassName: "text-blue-600",
+ },
pending: {
label: "Pending",
variant: "pending",
diff --git a/apps/web/lib/actions/partners/create-bounty-submission.ts b/apps/web/lib/actions/partners/create-bounty-submission.ts
index 9a42a05df1..08487605d2 100644
--- a/apps/web/lib/actions/partners/create-bounty-submission.ts
+++ b/apps/web/lib/actions/partners/create-bounty-submission.ts
@@ -15,7 +15,7 @@ import { VARIANT_TO_FROM_MAP } from "@dub/email/resend/constants";
import BountyPendingReview from "@dub/email/templates/bounty-pending-review";
import BountySubmitted from "@dub/email/templates/bounty-submitted";
import { prisma } from "@dub/prisma";
-import { Role } from "@prisma/client";
+import { BountySubmission, Role } from "@prisma/client";
import { waitUntil } from "@vercel/functions";
import { z } from "zod";
import { authPartnerActionClient } from "../safe-action";
@@ -29,13 +29,18 @@ const schema = z.object({
.default([]),
urls: z.array(z.string().url()).max(MAX_SUBMISSION_URLS).default([]),
description: z.string().trim().max(1000).optional(),
+ isDraft: z
+ .boolean()
+ .default(false)
+ .describe("Whether to create a draft submission or a final submission."),
});
export const createBountySubmissionAction = authPartnerActionClient
.schema(schema)
.action(async ({ ctx, parsedInput }) => {
const { partner } = ctx;
- const { programId, bountyId, files, urls, description } = parsedInput;
+ const { programId, bountyId, files, urls, description, isDraft } =
+ parsedInput;
const [programEnrollment, bounty] = await Promise.all([
getProgramEnrollmentOrThrow({
@@ -68,9 +73,17 @@ export const createBountySubmissionAction = authPartnerActionClient
throw new Error("This bounty is not for this program.");
}
+ let submission: BountySubmission | null = null;
+
// Validate the partner has not already created a submission for this bounty
if (bounty.submissions.length > 0) {
- throw new Error("You have already created a submission for this bounty.");
+ submission = bounty.submissions[0];
+
+ if (submission.status !== "draft") {
+ throw new Error(
+ `You already have a ${submission.status} submission for this bounty.`,
+ );
+ }
}
if (bounty.groups.length > 0) {
@@ -110,29 +123,52 @@ export const createBountySubmissionAction = authPartnerActionClient
const requireImage = submissionRequirements.includes("image");
const requireUrl = submissionRequirements.includes("url");
- if (requireImage && files.length === 0) {
- throw new Error("You must submit an image.");
- }
+ if (!isDraft) {
+ if (requireImage && files.length === 0) {
+ throw new Error("You must submit an image.");
+ }
- if (requireUrl && urls.length === 0) {
- throw new Error("You must submit a URL.");
+ if (requireUrl && urls.length === 0) {
+ throw new Error("You must submit a URL.");
+ }
}
- // Create the submission
- const submission = await prisma.bountySubmission.create({
- data: {
- id: createId({ prefix: "bnty_sub_" }),
- programId: bounty.programId,
- bountyId: bounty.id,
- partnerId: partner.id,
- description,
- ...(requireImage && { files }),
- ...(requireUrl && { urls }),
- },
- });
+ // If there is an existing submission, update it
+ if (submission) {
+ submission = await prisma.bountySubmission.update({
+ where: {
+ id: submission.id,
+ },
+ data: {
+ description,
+ ...(requireImage && { files }),
+ ...(requireUrl && { urls }),
+ status: isDraft ? "draft" : "pending",
+ },
+ });
+ }
+ // If there is no existing submission, create a new one
+ else {
+ submission = await prisma.bountySubmission.create({
+ data: {
+ id: createId({ prefix: "bnty_sub_" }),
+ programId: bounty.programId,
+ bountyId: bounty.id,
+ partnerId: partner.id,
+ description,
+ ...(requireImage && { files }),
+ ...(requireUrl && { urls }),
+ ...(isDraft && { status: "draft" }),
+ },
+ });
+ }
waitUntil(
(async () => {
+ if (submission.status === "draft") {
+ return;
+ }
+
// Send email to the program owners
const { users, program, ...workspace } = await getWorkspaceUsers({
programId,
diff --git a/apps/web/lib/actions/partners/upload-bounty-submission-file.ts b/apps/web/lib/actions/partners/upload-bounty-submission-file.ts
index d1c15c6e0f..a6e69340f5 100644
--- a/apps/web/lib/actions/partners/upload-bounty-submission-file.ts
+++ b/apps/web/lib/actions/partners/upload-bounty-submission-file.ts
@@ -66,7 +66,13 @@ export const uploadBountySubmissionFileAction = authPartnerActionClient
// Validate the partner has not already created a submission for this bounty
if (bounty.submissions.length > 0) {
- throw new Error("You have already created a submission for this bounty.");
+ const submission = bounty.submissions[0];
+
+ if (submission.status !== "draft") {
+ throw new Error(
+ "You have already created a submission for this bounty.",
+ );
+ }
}
if (bounty.groups.length > 0) {
diff --git a/apps/web/ui/partners/bounties/claim-bounty-modal.tsx b/apps/web/ui/partners/bounties/claim-bounty-modal.tsx
index 246d8b6b34..bd87df9a9a 100644
--- a/apps/web/ui/partners/bounties/claim-bounty-modal.tsx
+++ b/apps/web/ui/partners/bounties/claim-bounty-modal.tsx
@@ -62,11 +62,33 @@ function ClaimBountyModalContent({
const { handleKeyDown } = useEnterSubmit();
const [success, setSuccess] = useState(false);
- const [isFormOpen, setIsFormOpen] = useState(false);
+ const [isFormOpen, setIsFormOpen] = useState(submission?.status === "draft");
+
+ // Initialize form state with existing draft submission data
+ const [description, setDescription] = useState(submission?.description || "");
+
+ const [files, setFiles] = useState<FileInput[]>(() => {
+ if (submission?.files && submission.files.length > 0) {
+ return submission.files.map((file) => ({
+ id: uuid(),
+ url: file.url,
+ uploading: false,
+ }));
+ }
+
+ return [];
+ });
+
+ const [urls, setUrls] = useState<Url[]>(() => {
+ if (submission?.urls && submission.urls.length > 0) {
+ return submission.urls.map((url) => ({
+ id: uuid(),
+ url: url,
+ }));
+ }
- const [description, setDescription] = useState("");
- const [files, setFiles] = useState<FileInput[]>([]);
- const [urls, setUrls] = useState<Url[]>([{ id: uuid(), url: "" }]);
+ return [{ id: uuid(), url: "" }];
+ });
const { executeAsync: uploadFile } = useAction(
uploadBountySubmissionFileAction,
@@ -124,30 +146,64 @@ function ClaimBountyModalContent({
e.preventDefault();
if (!programEnrollment) return;
+ // Determine which button was clicked
+ const submitter = (e.nativeEvent as SubmitEvent)
+ .submitter as HTMLButtonElement;
+ const isDraft = submitter?.name === "draft";
+
+ const finalFiles = files
+ .filter(({ file, url }) => file && url)
+ .map(({ file, url }) => ({
+ url: url!,
+ fileName: file?.name || "File",
+ size: file?.size || 0,
+ }));
+
+ const finalUrls = urls.map(({ url }) => url).filter(Boolean);
+
try {
+ // Check the submission requirements are met for non-draft submissions
+ if (!isDraft) {
+ if (imageRequired && finalFiles.length === 0) {
+ throw new Error("You must upload at least one image.");
+ }
+
+ if (urlRequired && finalUrls.length === 0) {
+ throw new Error("You must provide at least one URL.");
+ }
+ }
+
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),
+ files: finalFiles,
+ urls: finalUrls,
description,
+ ...(isDraft && { isDraft }),
});
- if (!result?.data?.success)
- throw new Error("Failed to create submission");
+ if (!result?.data?.success) {
+ throw new Error(
+ isDraft
+ ? "Failed to save progress."
+ : "Failed to create submission.",
+ );
+ }
- mutatePrefix(
- `/api/partner-profile/programs/${programEnrollment.program.slug}/bounties`,
+ toast.success(
+ isDraft ? "Bounty progress saved." : "Bounty submitted.",
);
+
setSuccess(true);
- } catch (e) {
- toast.error("Failed to create submission. Please try again.");
+ await mutatePrefix(
+ `/api/partner-profile/programs/${programEnrollment.program.slug}/bounties`,
+ );
+ } catch (error) {
+ toast.error(
+ error instanceof Error
+ ? error.message
+ : "Failed to create submission. Please try again.",
+ );
}
}}
className="scrollbar-hide max-h-[calc(100dvh-50px)] overflow-y-auto"
@@ -471,49 +527,48 @@ function ClaimBountyModalContent({
</motion.div>
{/* Action buttons */}
- {bounty.type !== "performance" && !submission && (
- <div className="border-border-subtle border-t p-5">
- <div
- className={cn(
- "flex items-center transition-all",
- isFormOpen ? "gap-4" : "gap-0",
- )}
- >
- <div
- className={cn(
- "shrink-0 overflow-hidden transition-[width]",
- isFormOpen ? "w-[calc(50%-1rem)]" : "w-0",
- )}
- >
+ {bounty.type !== "performance" &&
+ (!submission || submission.status === "draft") && (
+ <div className="border-border-subtle border-t p-5">
+ {isFormOpen ? (
+ <div className="flex items-center justify-between">
+ <Button
+ variant="outline"
+ text="Cancel"
+ className="w-fit rounded-lg"
+ onClick={() => setIsFormOpen(false)}
+ />
+ <div className="flex gap-2">
+ <Button
+ variant="secondary"
+ text="Save progress"
+ className="rounded-lg"
+ type="submit"
+ name="draft"
+ loading={isPending}
+ disabled={fileUploading}
+ />
+ <Button
+ variant="primary"
+ text="Submit"
+ className="rounded-lg"
+ type="submit"
+ name="submit"
+ loading={isPending}
+ disabled={fileUploading}
+ />
+ </div>
+ </div>
+ ) : (
<Button
- variant="secondary"
- text="Cancel"
- className="rounded-lg"
- onClick={() => setIsFormOpen(false)}
+ variant="primary"
+ text={submission ? "Continue submission" : "Claim bounty"}
+ className="w-full rounded-lg"
+ onClick={() => setIsFormOpen(true)}
/>
- </div>
- <Button
- variant="primary"
- text={isFormOpen ? "Submit proof" : "Claim bounty"}
- className="grow rounded-lg"
- onClick={
- isFormOpen
- ? undefined
- : // Delay open to prevent also submitting the form
- () => setTimeout(() => setIsFormOpen(true), 100)
- }
- loading={isPending}
- disabled={
- isFormOpen &&
- ((imageRequired && !files.length) ||
- (urlRequired &&
- !urls.filter(({ url }) => url).length) ||
- fileUploading)
- }
- />
+ )}
</div>
- </div>
- )}
+ )}
</>
)}
</AnimatedSizeContainer>
diff --git a/packages/prisma/schema/bounty.prisma b/packages/prisma/schema/bounty.prisma
index 14dfed7a31..73ddad3eeb 100644
--- a/packages/prisma/schema/bounty.prisma
+++ b/packages/prisma/schema/bounty.prisma
@@ -4,6 +4,7 @@ enum BountyType {
}
enum BountySubmissionStatus {
+ draft
pending
approved
rejected