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.

Allow relative-start bounties with a fixed end date and fix related form/API handling.

Kiran Kbcbf746f06cc
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/bounties/[bountyId]/social-content-stats/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/bounties/[bountyId]/social-content-stats/route.ts
index 013741d7bc..931b4efdd2 100644
--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/bounties/[bountyId]/social-content-stats/route.ts
+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/bounties/[bountyId]/social-content-stats/route.ts
@@ -31,44 +31,35 @@ export const GET = withPartnerProfile(
});
}
- const [programEnrollment, bounty] = await Promise.all([
- getProgramEnrollmentOrThrow({
- partnerId: partner.id,
- programId,
- include: {
- program: {
- select: {
- id: true,
- defaultGroupId: true,
- },
+ const programEnrollment = await getProgramEnrollmentOrThrow({
+ partnerId: partner.id,
+ programId,
+ include: {
+ program: {
+ select: {
+ id: true,
+ defaultGroupId: true,
},
},
- }),
+ },
+ });
- getBountyOrThrow({
- bountyId,
- programId,
- include: {
- groups: {
- select: {
- groupId: true,
- },
+ const bounty = await getBountyOrThrow({
+ bountyId,
+ programId: programEnrollment.programId,
+ include: {
+ groups: {
+ select: {
+ groupId: true,
},
- submissions: {
- where: {
- partnerId: partner.id,
- },
+ },
+ submissions: {
+ where: {
+ partnerId: partner.id,
},
},
- }),
- ]);
-
- if (bounty.submissions.length > 0) {
- throw new DubApiError({
- code: "bad_request",
- message: "You have already submitted a social content for this bounty.",
- });
- }
+ },
+ });
const bountyInfo = resolveBountyDetails(bounty);
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty/add-edit-bounty-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty/add-edit-bounty-sheet.tsx
index cd807e7b15..91ee6dc52c 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty/add-edit-bounty-sheet.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty/add-edit-bounty-sheet.tsx
@@ -77,7 +77,6 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {
form,
openAccordions,
setOpenAccordions,
- hasEndDate,
startsAt,
endsAt,
startMode,
@@ -281,7 +280,7 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {
<div>
<Tooltip
content={
- !hasEndDate
+ !endsAt
? "Set an end date to use submission window."
: allowedSubmissions > 1
? "Decrease allowed submissions to 1 to use submission window."
@@ -291,7 +290,7 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {
<div
className={cn(
"flex items-center gap-4 transition-opacity",
- (!hasEndDate || allowedSubmissions > 1) &&
+ (!endsAt || allowedSubmissions > 1) &&
"opacity-30",
)}
>
@@ -301,7 +300,7 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {
trackDimensions="w-8 h-4"
thumbDimensions="w-3 h-3"
thumbTranslate="translate-x-4"
- disabled={!hasEndDate || allowedSubmissions > 1}
+ disabled={!endsAt || allowedSubmissions > 1}
/>
<Label>Submission window</Label>
</div>
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty/use-add-edit-bounty-form.ts b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty/use-add-edit-bounty-form.ts
index e34639ab5b..9d02709f69 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty/use-add-edit-bounty-form.ts
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty/use-add-edit-bounty-form.ts
@@ -695,7 +695,12 @@ export function useAddEditBountyForm({
})
: name || "New bounty",
startsAt: startMode === "relative" ? null : startsAt || new Date(),
- endsAt: startMode === "relative" ? null : effectiveEndsAt,
+ endsAt:
+ startMode === "relative"
+ ? endsAfterDays != null
+ ? null
+ : endsAt ?? null
+ : effectiveEndsAt,
startMode: startMode ?? "absolute",
endsAfterDays: endsAfterDays ?? null,
rewardAmount: rewardAmount ? rewardAmount * 100 : null,
diff --git a/apps/web/lib/bounty/api/bounty-availability.ts b/apps/web/lib/bounty/api/bounty-availability.ts
index f1516d2d44..af8f22b7fe 100644
--- a/apps/web/lib/bounty/api/bounty-availability.ts
+++ b/apps/web/lib/bounty/api/bounty-availability.ts
@@ -112,13 +112,14 @@ export function getEffectiveBountyPeriod({
};
}
-function isPartnerEligibleForBounty({
+export function isPartnerEligibleForBounty({
program,
bounty,
programEnrollment,
}: PartnerBountyEligibilityInput): boolean {
// Archived bounties are not visible
if (bounty.archivedAt) {
+ console.log(`Bounty ${bounty.id} is archived.`);
return false;
}
diff --git a/apps/web/lib/bounty/bounty-period.ts b/apps/web/lib/bounty/bounty-period.ts
index a3116f04a4..3c4b794676 100644
--- a/apps/web/lib/bounty/bounty-period.ts
+++ b/apps/web/lib/bounty/bounty-period.ts
@@ -119,6 +119,8 @@ export function getProgramBountyMeta({
const durationLabel =
ENDS_AFTER_DAYS_LABELS[endsAfterDays] ?? `${endsAfterDays} days`;
dateRangeLabel = `${durationLabel} after joining`;
+ } else if (endsAt) {
+ dateRangeLabel = `when a new partner joins → ${formatDate(endsAt, { month: "short" })}`;
} else {
dateRangeLabel = "when a new partner joins";
}
diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.ts
index 00b2762e6f..fc2a8e8b73 100644
--- a/apps/web/lib/zod/schemas/bounties.ts
+++ b/apps/web/lib/zod/schemas/bounties.ts
@@ -127,7 +127,7 @@ export const createBountySchema = z.object({
performanceCondition: bountyPerformanceConditionSchema.nullish(),
performanceScope: z.enum(BountyPerformanceScope).nullish(),
sendNotificationEmails: z.boolean().optional(),
- startMode: z.enum(BountyStartMode),
+ startMode: z.enum(BountyStartMode).default("absolute"),
endsAfterDays: z.number().int().positive().nullish(),
});