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.

fix PartnerBountyCard UX

Steven Tey618a37c3426f
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 5870906d0d..a33125aae8 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
@@ -29,15 +29,17 @@ export function PartnerBountyCard({ bounty }: { bounty: PartnerBountyProps }) {
const expiredBounty =
bounty.endsAt && new Date(bounty.endsAt) < new Date() ? true : false;
+ const submittedBounty =
+ bounty.submission &&
+ (bounty.submission.status !== "draft" ||
+ bounty.submissionRequirements?.socialMetrics);
+
const handleCardClick = () => {
if (expiredBounty) {
return;
}
- const shouldOpenSheet =
- bounty.submission && bounty.submission.status !== "draft";
-
- if (shouldOpenSheet) {
+ if (submittedBounty) {
setPartnerBountySubmissionDetailsSheetOpen(true);
} else {
setShowClaimBountyModal(true);
@@ -66,12 +68,14 @@ export function PartnerBountyCard({ bounty }: { bounty: PartnerBountyProps }) {
<button
type="button"
onClick={handleCardClick}
- disabled={expiredBounty}
+ disabled={expiredBounty || bounty.type === "performance"}
className={cn(
"border-border-subtle group relative flex w-full cursor-pointer flex-col gap-2.5 overflow-hidden rounded-xl border bg-white p-3 text-left",
expiredBounty
? "cursor-not-allowed"
- : "hover:border-border-default transition-all hover:shadow-lg",
+ : bounty.type === "performance"
+ ? "cursor-default"
+ : "hover:border-border-default transition-all hover:shadow-lg",
)}
>
<div className="relative flex h-[124px] items-center justify-center rounded-lg bg-neutral-100 py-3">
@@ -186,7 +190,8 @@ function renderSubmissionStatus({
switch (submission.status) {
case "draft":
- return bounty.type === "performance" ? (
+ return bounty.type === "performance" ||
+ bounty.submissionRequirements?.socialMetrics ? (
<BountyPerformance bounty={bounty} />
) : (
<div
diff --git a/apps/web/lib/actions/partners/create-bounty-submission.ts b/apps/web/lib/actions/partners/create-bounty-submission.ts
index a1a02026db..11af1708f4 100644
--- a/apps/web/lib/actions/partners/create-bounty-submission.ts
+++ b/apps/web/lib/actions/partners/create-bounty-submission.ts
@@ -62,13 +62,15 @@ export const createBountySubmissionAction = authPartnerActionClient
throw new Error("This bounty is not for this program.");
}
+ const bountyInfo = resolveBountyDetails(bounty);
let submission: BountySubmission | null = null;
- // Validate the partner has not already created a submission for this bounty
if (bounty.submissions.length > 0) {
submission = bounty.submissions[0];
- if (submission.status !== "draft") {
+ // if there's an existing submission, only throw an error
+ // if submission is not a draft and is not for a social metrics bounty
+ if (submission.status !== "draft" && !bountyInfo?.hasSocialMetrics) {
throw new Error(
`You already have a ${submission.status} submission for this bounty.`,
);
@@ -118,8 +120,6 @@ export const createBountySubmissionAction = authPartnerActionClient
);
}
- const bountyInfo = resolveBountyDetails(bounty);
-
if (bountyInfo?.hasSocialMetrics && isDraft) {
throw new Error(
"Draft submissions are not allowed for social metrics bounties.",
diff --git a/apps/web/ui/partners/bounties/bounty-performance.tsx b/apps/web/ui/partners/bounties/bounty-performance.tsx
index e22b88ab7e..66e254ed2f 100644
--- a/apps/web/ui/partners/bounties/bounty-performance.tsx
+++ b/apps/web/ui/partners/bounties/bounty-performance.tsx
@@ -3,40 +3,79 @@ import { PERFORMANCE_BOUNTY_SCOPE_ATTRIBUTES } from "@/lib/bounty/api/performanc
import { PartnerBountyProps } from "@/lib/types";
import { cn, currencyFormatter, nFormatter } from "@dub/utils";
-export function BountyPerformance({ bounty }: { bounty: PartnerBountyProps }) {
+type PerformanceDisplay = {
+ value: number;
+ target: number;
+ formattedValue: string;
+ formattedTarget: string;
+ metricLabel: string;
+};
+
+function getPerformanceDisplay(
+ bounty: PartnerBountyProps,
+): PerformanceDisplay | null {
const performanceCondition = bounty.performanceCondition;
+ const socialMetrics = bounty.submissionRequirements?.socialMetrics;
- if (!performanceCondition) {
- return null;
+ if (performanceCondition) {
+ const attribute = performanceCondition.attribute;
+ const target = performanceCondition.value;
+ const value = bounty.submission?.performanceCount ?? 0;
+ const isCurrency = isCurrencyAttribute(attribute);
+
+ return {
+ value,
+ target,
+ formattedValue:
+ value === undefined
+ ? "-"
+ : isCurrency
+ ? currencyFormatter(value, {
+ trailingZeroDisplay: "stripIfInteger",
+ })
+ : nFormatter(value, { full: true }),
+ formattedTarget: isCurrency
+ ? currencyFormatter(target, { trailingZeroDisplay: "stripIfInteger" })
+ : nFormatter(target, { full: true }),
+ metricLabel:
+ PERFORMANCE_BOUNTY_SCOPE_ATTRIBUTES[
+ performanceCondition.attribute
+ ].toLowerCase(),
+ };
}
- const attribute = performanceCondition.attribute;
- const target = performanceCondition.value;
- const value = bounty.submission?.performanceCount ?? 0;
+ if (socialMetrics?.metric && socialMetrics.minCount != null) {
+ const target = socialMetrics.minCount;
+ const value = bounty.submission?.socialMetricCount ?? 0;
+
+ return {
+ value,
+ target,
+ formattedValue: nFormatter(value, { full: true }),
+ formattedTarget: nFormatter(target, { full: true }),
+ metricLabel: socialMetrics.metric.toLowerCase(),
+ };
+ }
- const formattedValue =
- value === undefined
- ? "-"
- : isCurrencyAttribute(attribute)
- ? currencyFormatter(value, { trailingZeroDisplay: "stripIfInteger" })
- : nFormatter(value, { full: true });
+ return null;
+}
- const formattedTarget = isCurrencyAttribute(attribute)
- ? currencyFormatter(target, { trailingZeroDisplay: "stripIfInteger" })
- : nFormatter(target, { full: true });
+export function BountyPerformance({ bounty }: { bounty: PartnerBountyProps }) {
+ const display = getPerformanceDisplay(bounty);
- const metricLabel =
- PERFORMANCE_BOUNTY_SCOPE_ATTRIBUTES[
- performanceCondition.attribute
- ].toLowerCase();
+ if (!display) {
+ return null;
+ }
+ const { value, target, formattedValue, formattedTarget, metricLabel } =
+ display;
const expiredBounty =
bounty.endsAt && new Date(bounty.endsAt) < new Date() ? true : false;
return (
<div className="flex flex-col gap-2">
<div className="h-1.5 w-full overflow-hidden rounded-full bg-neutral-200">
- {value && (
+ {value > 0 && target > 0 && (
<div
style={{
width: Math.min(Math.max(value / target, 0), 1) * 100 + "%",
@@ -56,7 +95,8 @@ export function BountyPerformance({ bounty }: { bounty: PartnerBountyProps }) {
<strong className="text-content-emphasis font-semibold">
{formattedTarget}
</strong>{" "}
- {metricLabel} generated
+ {metricLabel}
+ {bounty.type === "performance" ? " generated" : ""}
</span>
</div>
);
diff --git a/apps/web/ui/partners/bounties/partner-bounty-submission-details-sheet.tsx b/apps/web/ui/partners/bounties/partner-bounty-submission-details-sheet.tsx
index b23951fac5..31b701ed38 100644
--- a/apps/web/ui/partners/bounties/partner-bounty-submission-details-sheet.tsx
+++ b/apps/web/ui/partners/bounties/partner-bounty-submission-details-sheet.tsx
@@ -20,6 +20,7 @@ import {
AccordionItem,
AccordionTrigger,
Button,
+ CopyButton,
Sheet,
StatusBadge,
} from "@dub/ui";
@@ -28,6 +29,7 @@ import { formatDate, getPrettyUrl } from "@dub/utils";
import Linkify from "linkify-react";
import { useParams } from "next/navigation";
import { Dispatch, SetStateAction, useState } from "react";
+import { toast } from "sonner";
interface PartnerBountySubmissionDetailsSheetProps {
bounty: PartnerBountyProps;
@@ -91,13 +93,15 @@ function PartnerBountySubmissionDetailsSheetContent({
: "No end date"}
</div>
<BountyRewardDescription bounty={bounty} className="font-medium" />
- <StatusBadge
- variant={statusBadge.variant}
- icon={statusBadge.icon}
- className="w-fit rounded-lg py-1.5"
- >
- {statusLabelWithDate}
- </StatusBadge>
+ {statusDate && (
+ <StatusBadge
+ variant={statusBadge.variant}
+ icon={statusBadge.icon}
+ className="w-fit rounded-lg py-1.5"
+ >
+ {statusLabelWithDate}
+ </StatusBadge>
+ )}
</div>
{/* Details accordion (only when there is content; open by default to match design) */}
@@ -148,21 +152,6 @@ function PartnerBountySubmissionDetailsSheetContent({
</div>
)}
- {/* Submission section */}
- {bounty?.type === "submission" && hasSocialContent && (
- <div className="p-5">
- <h2 className="text-base font-semibold text-neutral-900">
- Submission
- </h2>
- <div className="mt-3">
- <BountySocialContentPreview
- bounty={bounty}
- submission={submission}
- />
- </div>
- </div>
- )}
-
{bounty?.type === "submission" &&
bountyInfo?.hasSocialMetrics &&
bounty && (
@@ -175,6 +164,100 @@ function PartnerBountySubmissionDetailsSheetContent({
</div>
)}
+ {/* Submission section */}
+ {bounty?.type === "submission" && (
+ <div className="p-5">
+ <h2 className="text-base font-semibold text-neutral-900">
+ Submission
+ </h2>
+ <div className="mt-3 flex flex-col gap-4">
+ {hasSocialContent && (
+ <BountySocialContentPreview
+ bounty={bounty}
+ submission={submission}
+ />
+ )}
+
+ {Boolean(submission.files?.length) && (
+ <div>
+ <h2 className="text-content-emphasis text-sm font-medium">
+ Files
+ </h2>
+ <div className="mt-2 flex flex-wrap gap-4">
+ {submission.files!.map((file, idx) => (
+ <a
+ key={idx}
+ className="border-border-subtle hover:border-border-default group relative flex size-14 items-center justify-center rounded-md border bg-white"
+ target="_blank"
+ href={file.url}
+ rel="noopener noreferrer"
+ >
+ <div className="relative size-full overflow-hidden rounded-md">
+ <img src={file.url} alt="object-cover" />
+ </div>
+ <span className="sr-only">
+ {file.fileName || `File ${idx + 1}`}
+ </span>
+ </a>
+ ))}
+ </div>
+ </div>
+ )}
+
+ {Boolean(submission.urls?.length) && !hasSocialContent && (
+ <div>
+ <h2 className="text-content-emphasis text-sm font-medium">
+ URLs
+ </h2>
+ <div className="mt-2 flex flex-col gap-2">
+ {submission.urls?.map((url, idx) => (
+ <div
+ className="relative"
+ key={`${submission.id}-${idx}-${url}`}
+ >
+ <div className="border-border-subtle block w-full rounded-lg border px-3 py-2 pl-10 pr-12">
+ <a
+ href={url}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="block cursor-alias truncate text-sm font-normal text-neutral-800 decoration-dotted underline-offset-2 hover:underline"
+ >
+ {url}
+ </a>
+ </div>
+ <div className="absolute inset-y-0 left-0 flex items-center pl-2.5">
+ <div className="flex size-6 items-center justify-center rounded-full bg-neutral-100 text-xs font-medium text-neutral-600">
+ {idx + 1}
+ </div>
+ </div>
+ <div className="absolute inset-y-0 right-0 flex items-center pr-2.5">
+ <CopyButton
+ value={url}
+ onCopy={() => {
+ toast.success("URL copied to clipboard!");
+ }}
+ />
+ </div>
+ </div>
+ ))}
+ </div>
+ </div>
+ )}
+
+ {submission.description && (
+ <div>
+ <h2 className="text-content-emphasis text-sm font-medium">
+ How did you complete this bounty?
+ </h2>
+ <span className="mt-2 whitespace-pre-wrap text-sm font-normal text-neutral-600">
+ {submission.description}
+ </span>
+ </div>
+ )}
+ </div>
+ </div>
+ )}
+
{submission.status === "approved" && (
<div className="mt-auto p-5 pt-2">
<ButtonLink
@@ -209,17 +292,15 @@ export function usePartnerBountySubmissionDetailsSheet(
bounty: PartnerBountyProps | null,
) {
const [isOpen, setIsOpen] = useState(false);
- const canOpen = bounty?.submission && bounty.submission.status !== "draft";
return {
- partnerBountySubmissionDetailsSheet:
- canOpen && bounty ? (
- <PartnerBountySubmissionDetailsSheet
- bounty={bounty}
- isOpen={isOpen}
- setIsOpen={setIsOpen}
- />
- ) : null,
+ partnerBountySubmissionDetailsSheet: bounty ? (
+ <PartnerBountySubmissionDetailsSheet
+ bounty={bounty}
+ isOpen={isOpen}
+ setIsOpen={setIsOpen}
+ />
+ ) : null,
setPartnerBountySubmissionDetailsSheetOpen: setIsOpen,
};
}