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 custom reward description to bounty

Kiran K13835d843738
diff --git a/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts b/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts
index cf07199284..7a767b91b1 100644
--- a/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts
+++ b/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts
@@ -57,6 +57,7 @@ export const PATCH = withWorkspace(
startsAt,
endsAt,
rewardAmount,
+ rewardDescription,
submissionRequirements,
performanceCondition,
groupIds,
@@ -96,23 +97,27 @@ export const PATCH = withWorkspace(
});
}
+ // Bounty name
+ let bountyName = name;
+
+ if (bounty.type === "performance" && performanceCondition) {
+ bountyName = generateBountyName({
+ condition: performanceCondition,
+ });
+ }
+
const data = await prisma.$transaction(async (tx) => {
const updatedBounty = await tx.bounty.update({
where: {
id: bounty.id,
},
data: {
- name:
- bounty.type === "performance" && rewardAmount
- ? generateBountyName({
- rewardAmount,
- condition: performanceCondition,
- })
- : name ?? undefined,
+ name: bountyName ?? undefined,
description,
startsAt: startsAt!, // Can remove the ! when we're on a newer TS version (currently 5.4.4)
endsAt,
rewardAmount,
+ rewardDescription,
...(bounty.type === "submission" &&
submissionRequirements !== undefined && {
submissionRequirements: submissionRequirements ?? Prisma.DbNull,
diff --git a/apps/web/app/(ee)/api/bounties/route.ts b/apps/web/app/(ee)/api/bounties/route.ts
index 3c86a1ece6..8d4aeb7d6f 100644
--- a/apps/web/app/(ee)/api/bounties/route.ts
+++ b/apps/web/app/(ee)/api/bounties/route.ts
@@ -79,6 +79,7 @@ export const POST = withWorkspace(
description,
type,
rewardAmount,
+ rewardDescription,
startsAt,
endsAt,
submissionRequirements,
@@ -98,12 +99,21 @@ export const POST = withWorkspace(
groupIds,
});
- const bountyName =
- name ??
- generateBountyName({
- rewardAmount,
+ // Bounty name
+ let bountyName = name;
+
+ if (type === "performance" && performanceCondition) {
+ bountyName = generateBountyName({
condition: performanceCondition,
});
+ }
+
+ if (!bountyName) {
+ throw new DubApiError({
+ code: "bad_request",
+ message: "Bounty name is required",
+ });
+ }
const bounty = await prisma.$transaction(async (tx) => {
let workflow: Workflow | null = null;
@@ -142,6 +152,7 @@ export const POST = withWorkspace(
startsAt: startsAt!, // Can remove the ! when we're on a newer TS version (currently 5.4.4)
endsAt,
rewardAmount,
+ rewardDescription,
...(submissionRequirements &&
type === "submission" && {
submissionRequirements,
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-info.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-info.tsx
index 101e638bc3..bf56339042 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-info.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-info.tsx
@@ -1,5 +1,6 @@
"use client";
+import { getBountyRewardDescription } from "@/lib/partners/get-bounty-reward-description";
import useBounty from "@/lib/swr/use-bounty";
import {
SubmissionsCountByStatus,
@@ -7,7 +8,7 @@ import {
} from "@/lib/swr/use-bounty-submissions-count";
import { BountyThumbnailImage } from "@/ui/partners/bounties/bounty-thumbnail-image";
import { formatDate, nFormatter, pluralize } from "@dub/utils";
-import { CalendarDays, Users } from "lucide-react";
+import { CalendarDays, Gift, Users } from "lucide-react";
import { useMemo } from "react";
import { BountyActionButton } from "../bounty-action-button";
@@ -33,8 +34,8 @@ export function BountyInfo() {
}
return (
- <div className="flex flex-col gap-3 sm:flex-row sm:items-start sm:gap-6">
- <div className="relative flex size-20 shrink-0 items-center justify-center rounded-lg bg-neutral-100 p-3">
+ <div className="flex flex-col items-center gap-3 sm:flex-row sm:items-start sm:gap-6">
+ <div className="relative flex h-[100px] w-[100px] shrink-0 items-center justify-center rounded-lg bg-neutral-100 p-3">
<BountyThumbnailImage bounty={bounty} />
</div>
@@ -54,6 +55,13 @@ export function BountyInfo() {
</span>
</div>
+ <div className="text-content-subtle flex items-center gap-2 text-sm font-medium">
+ <Gift className="size-4 shrink-0" />
+ <span className="text-ellipsis">
+ {getBountyRewardDescription(bounty)}
+ </span>
+ </div>
+
<div className="flex items-center space-x-2">
<Users className="size-4 shrink-0" />
<div className="text-sm text-neutral-500">
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 8e9d7d8c34..3e66fe3ff1 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
@@ -29,6 +29,7 @@ import {
Sheet,
SmartDateTimePicker,
Switch,
+ ToggleGroup,
useRouterStuff,
} from "@dub/ui";
import { cn } from "@dub/utils";
@@ -64,6 +65,18 @@ const BOUNTY_TYPES: CardSelectorOption[] = [
},
];
+// Only valid for submission bounties
+const REWARD_TYPES = [
+ {
+ value: "flat",
+ label: "Flat rate",
+ },
+ {
+ value: "custom",
+ label: "Custom",
+ },
+];
+
const ACCORDION_ITEMS = [
"bounty-type",
"bounty-details",
@@ -71,6 +84,8 @@ const ACCORDION_ITEMS = [
"groups",
];
+type RewardType = "flat" | "custom";
+
function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {
const { id: workspaceId } = useWorkspace();
const { program } = useProgram();
@@ -84,6 +99,10 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {
bounty?.submissionRequirements?.includes("url") || false,
);
+ const [rewardType, setRewardType] = useState<RewardType>(
+ bounty ? (bounty.rewardAmount ? "flat" : "custom") : "flat",
+ );
+
const [openAccordions, setOpenAccordions] = useState(ACCORDION_ITEMS);
const { makeRequest, isSubmitting } = useApiMutation<BountyProps>();
@@ -96,6 +115,7 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {
rewardAmount: bounty?.rewardAmount
? bounty.rewardAmount / 100
: undefined,
+ rewardDescription: bounty?.rewardDescription || undefined,
type: bounty?.type || "performance",
submissionRequirements: bounty?.submissionRequirements || null,
groupIds: bounty?.groups?.map(({ id }) => id) || null,
@@ -125,6 +145,7 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {
startsAt,
endsAt,
rewardAmount,
+ rewardDescription,
type,
name,
description,
@@ -133,11 +154,11 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {
"startsAt",
"endsAt",
"rewardAmount",
+ "rewardDescription",
"type",
"name",
"description",
"performanceCondition",
- "groupIds",
]);
// Make sure endsAt is null if hasEndDate is false
@@ -179,7 +200,7 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {
// Decide if the submit button should be disabled
const shouldDisableSubmit = useMemo(() => {
- if (!startsAt || !rewardAmount) {
+ if (!startsAt) {
return true;
}
@@ -187,17 +208,32 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {
return true;
}
- if (type === "submission" && !name?.trim()) {
- return true;
+ if (type === "submission") {
+ if (!name?.trim()) {
+ return true;
+ }
+
+ if (rewardType === "flat" && !rewardAmount) {
+ return true;
+ }
+
+ if (rewardType === "custom" && !rewardDescription) {
+ return true;
+ }
}
- if (
- type === "performance" &&
- ["attribute", "operator", "value"].some(
- (key) => performanceCondition?.[key] === undefined,
- )
- ) {
- return true;
+ if (type === "performance") {
+ if (
+ ["attribute", "operator", "value"].some(
+ (key) => performanceCondition?.[key] === undefined,
+ )
+ ) {
+ return true;
+ }
+
+ if (!rewardAmount) {
+ return true;
+ }
}
return false;
@@ -205,6 +241,7 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {
startsAt,
endsAt,
rewardAmount,
+ rewardDescription,
type,
name,
performanceCondition?.attribute,
@@ -214,10 +251,11 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {
// Handle actual form submission (called after confirmation)
const performSubmit = async () => {
- const data = form.getValues();
if (!workspaceId) return;
- data.rewardAmount = data.rewardAmount * 100;
+ const data = form.getValues();
+
+ data.rewardAmount = data.rewardAmount ? data.rewardAmount * 100 : null;
// Parse performance logic
if (data.type === "performance") {
@@ -233,17 +271,25 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {
}
let { data: condition } = result;
- const isCurrency = isCurrencyAttribute(condition.attribute);
// Format the value to be in cents if it's a currency attribute
condition = {
...condition,
- value: isCurrency ? condition.value * 100 : condition.value,
+ value: isCurrencyAttribute(condition.attribute)
+ ? condition.value * 100
+ : condition.value,
};
data.performanceCondition = condition;
+ data.rewardDescription = null;
} else if (type === "submission") {
data.performanceCondition = null;
+
+ if (rewardType === "custom") {
+ data.rewardAmount = null;
+ } else if (rewardType === "flat") {
+ data.rewardDescription = null;
+ }
}
await makeRequest(bounty ? `/api/bounties/${bounty.id}` : "/api/bounties", {
@@ -388,73 +434,119 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {
)}
</AnimatedSizeContainer>
- <div>
- <label
- htmlFor="rewardAmount"
- className="text-sm font-medium text-neutral-800"
- >
- Reward
- </label>
- <div className="mt-2">
- <Controller
- name="rewardAmount"
- control={control}
- rules={{
- required: true,
- min: 0,
- }}
- render={({ field }) => (
- <AmountInput
- {...field}
- id="rewardAmount"
- amountType="flat"
- placeholder="200"
- error={errors.rewardAmount?.message}
- value={
- field.value == null || isNaN(field.value)
- ? ""
- : field.value
- }
- onChange={(e) => {
- const val = e.target.value;
-
- field.onChange(
- val === "" ? null : parseFloat(val),
- );
- }}
+ {type === "submission" && (
+ <>
+ <div>
+ <label
+ htmlFor="name"
+ className="text-sm font-medium text-neutral-800"
+ >
+ Name
+ </label>
+ <div className="mt-2">
+ <input
+ id="name"
+ type="text"
+ maxLength={100}
+ className={cn(
+ "block w-full rounded-md border-neutral-300 px-3 py-2 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",
+ errors.name &&
+ "border-red-600 focus:border-red-500 focus:ring-red-600",
+ )}
+ placeholder={`Create a YouTube video about${program?.name ? ` ${program.name}` : ""}...`}
+ {...register("name", {
+ setValueAs: (value) =>
+ value === "" ? null : value,
+ })}
/>
- )}
+ <div className="mt-1 text-left">
+ <span className="text-xs text-neutral-400">
+ {name?.length || 0}/100
+ </span>
+ </div>
+ </div>
+ </div>
+
+ <ToggleGroup
+ className="mt-2 flex w-full items-center gap-1 rounded-md border border-neutral-200 bg-neutral-100 p-1"
+ optionClassName="h-8 flex items-center justify-center rounded-md flex-1 text-sm"
+ indicatorClassName="bg-white border-none rounded-md"
+ options={REWARD_TYPES}
+ selected={rewardType}
+ selectAction={(id: RewardType) => setRewardType(id)}
/>
+ </>
+ )}
+
+ {(rewardType === "flat" || type === "performance") && (
+ <div>
+ <label
+ htmlFor="rewardAmount"
+ className="text-sm font-medium text-neutral-800"
+ >
+ Reward
+ </label>
+ <div className="mt-2">
+ <Controller
+ name="rewardAmount"
+ control={control}
+ rules={{
+ required: true,
+ min: 0,
+ }}
+ render={({ field }) => (
+ <AmountInput
+ {...field}
+ id="rewardAmount"
+ amountType="flat"
+ placeholder="200"
+ error={errors.rewardAmount?.message}
+ value={
+ field.value == null || isNaN(field.value)
+ ? ""
+ : field.value
+ }
+ onChange={(e) => {
+ const val = e.target.value;
+
+ field.onChange(
+ val === "" ? null : parseFloat(val),
+ );
+ }}
+ />
+ )}
+ />
+ </div>
</div>
- </div>
+ )}
- {type === "submission" && (
+ {rewardType === "custom" && type === "submission" && (
<div>
<label
- htmlFor="name"
+ htmlFor="rewardDescription"
className="text-sm font-medium text-neutral-800"
>
- Name
+ Reward
</label>
<div className="mt-2">
<input
- id="name"
+ id="rewardDescription"
type="text"
maxLength={100}
className={cn(
"block w-full rounded-md border-neutral-300 px-3 py-2 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",
- errors.name &&
+ errors.rewardDescription &&
"border-red-600 focus:border-red-500 focus:ring-red-600",
)}
- placeholder={`Create a YouTube video about${program?.name ? ` ${program.name}` : ""}...`}
- {...register("name", {
+ placeholder="Earn an additional 10% if you hit your revenue goal"
+ {...register("rewardDescription", {
setValueAs: (value) =>
value === "" ? null : value,
})}
/>
<div className="mt-1 text-left">
<span className="text-xs text-neutral-400">
- {name?.length || 0}/100
+ {rewardDescription?.length || 0}/100
</span>
</div>
</div>
@@ -503,6 +595,15 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {
</div>
</div>
</div>
+
+ {rewardType === "custom" && (
+ <div className="gap-4 rounded-lg bg-orange-50 px-4 py-2.5 text-center">
+ <span className="text-sm font-medium leading-5 text-orange-800">
+ When reviewing these submissions, a custom reward
+ amount will be required to approve.
+ </span>
+ </div>
+ )}
</div>
</ProgramSheetAccordionContent>
</ProgramSheetAccordionItem>
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-card.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-card.tsx
index 766a413a3e..245884228f 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-card.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-card.tsx
@@ -1,8 +1,9 @@
+import { getBountyRewardDescription } from "@/lib/partners/get-bounty-reward-description";
import usePartnersCount from "@/lib/swr/use-partners-count";
import useWorkspace from "@/lib/swr/use-workspace";
import { BountyListProps } from "@/lib/types";
import { BountyThumbnailImage } from "@/ui/partners/bounties/bounty-thumbnail-image";
-import { Calendar6, Users } from "@dub/ui/icons";
+import { Calendar6, Gift, Users } from "@dub/ui/icons";
import { formatDate, nFormatter, pluralize } from "@dub/utils";
import Link from "next/link";
import { useMemo } from "react";
@@ -70,6 +71,13 @@ export function BountyCard({ bounty }: { bounty: BountyListProps }) {
</span>
</div>
+ <div className="text-content-subtle flex items-center gap-2 text-sm font-medium">
+ <Gift className="size-3.5" />
+ <span className="truncate">
+ {getBountyRewardDescription(bounty)}
+ </span>
+ </div>
+
<div className="text-content-subtle flex items-center gap-2 text-sm font-medium">
<Users className="size-3.5" />
<div className="h-5">
diff --git a/apps/web/lib/api/bounties/generate-bounty-name.ts b/apps/web/lib/api/bounties/generate-bounty-name.ts
index 38a66a3165..7fdaf55b19 100644
--- a/apps/web/lib/api/bounties/generate-bounty-name.ts
+++ b/apps/web/lib/api/bounties/generate-bounty-name.ts
@@ -4,24 +4,15 @@ import { currencyFormatter, nFormatter } from "@dub/utils";
import { isCurrencyAttribute } from "../workflows/utils";
export const generateBountyName = ({
- rewardAmount,
condition,
}: {
- rewardAmount: number;
- condition?: WorkflowCondition | null;
+ condition: WorkflowCondition;
}) => {
- if (!condition) {
- return `Earn ${currencyFormatter(rewardAmount / 100, { trailingZeroDisplay: "stripIfInteger" })}`;
- }
-
const isCurrency = isCurrencyAttribute(condition.attribute);
- const rewardAmountFormatted = currencyFormatter(rewardAmount / 100, {
- trailingZeroDisplay: "stripIfInteger",
- });
const attributeLabel = WORKFLOW_ATTRIBUTE_LABELS[condition.attribute];
const valueFormatted = isCurrency
? `${currencyFormatter(condition.value / 100, { trailingZeroDisplay: "stripIfInteger" })} in`
: `${nFormatter(condition.value, { full: true })}`;
- return `Earn ${rewardAmountFormatted} after generating ${valueFormatted} ${attributeLabel.toLowerCase()}`;
+ return `Generate ${valueFormatted} ${attributeLabel.toLowerCase()}`;
};
diff --git a/apps/web/lib/api/bounties/get-bounty-with-details.ts b/apps/web/lib/api/bounties/get-bounty-with-details.ts
index af77851d22..d3c4ece849 100644
--- a/apps/web/lib/api/bounties/get-bounty-with-details.ts
+++ b/apps/web/lib/api/bounties/get-bounty-with-details.ts
@@ -17,6 +17,7 @@ export const getBountyWithDetails = async ({
b.startsAt,
b.endsAt,
b.rewardAmount,
+ b.rewardDescription,
b.submissionRequirements,
wf.triggerConditions,
@@ -92,6 +93,7 @@ export const getBountyWithDetails = async ({
startsAt: bounty.startsAt,
endsAt: bounty.endsAt,
rewardAmount: bounty.rewardAmount,
+ rewardDescription: bounty.rewardDescription,
submissionRequirements: bounty.submissionRequirements,
performanceCondition,
groups: bounty.groups.filter((group) => group !== null) ?? [],
diff --git a/apps/web/lib/partners/get-bounty-reward-description.ts b/apps/web/lib/partners/get-bounty-reward-description.ts
new file mode 100644
index 0000000000..211700aa2b
--- /dev/null
+++ b/apps/web/lib/partners/get-bounty-reward-description.ts
@@ -0,0 +1,20 @@
+import { currencyFormatter } from "@dub/utils";
+import { BountyProps } from "../types";
+
+export function getBountyRewardDescription(
+ bounty: Pick<BountyProps, "rewardAmount" | "rewardDescription">,
+) {
+ if (bounty.rewardAmount) {
+ const formattedAmount = currencyFormatter(bounty.rewardAmount / 100, {
+ trailingZeroDisplay: "stripIfInteger",
+ });
+
+ return `Earn ${formattedAmount}`;
+ }
+
+ if (bounty.rewardDescription) {
+ return bounty.rewardDescription;
+ }
+
+ return "";
+}
diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.ts
index 7d1c237d90..45b643e4ab 100644
--- a/apps/web/lib/zod/schemas/bounties.ts
+++ b/apps/web/lib/zod/schemas/bounties.ts
@@ -37,7 +37,15 @@ export const createBountySchema = z.object({
type: z.nativeEnum(BountyType),
startsAt: parseDateSchema,
endsAt: parseDateSchema.nullish(),
- rewardAmount: z.number().min(1, "Reward amount must be greater than 1"),
+ rewardAmount: z
+ .number()
+ .min(1, "Reward amount must be greater than 1")
+ .nullable(),
+ rewardDescription: z
+ .string()
+ .trim()
+ .max(100, "Reward description must be less than 100 characters")
+ .nullish(),
submissionRequirements: submissionRequirementsSchema.nullish(),
groupIds: z.array(z.string()).nullable(),
performanceCondition: workflowConditionSchema.nullish(),
@@ -63,7 +71,8 @@ export const BountySchema = z.object({
type: z.nativeEnum(BountyType),
startsAt: z.date(),
endsAt: z.date().nullable(),
- rewardAmount: z.number(),
+ rewardAmount: z.number().nullable(),
+ rewardDescription: z.string().nullable(),
performanceCondition: workflowConditionSchema.nullable().default(null),
submissionRequirements: submissionRequirementsSchema.nullable().default(null),
groups: z.array(GroupSchema.pick({ id: true })),
diff --git a/packages/prisma/schema/bounty.prisma b/packages/prisma/schema/bounty.prisma
index 73be73619b..a393f9e84c 100644
--- a/packages/prisma/schema/bounty.prisma
+++ b/packages/prisma/schema/bounty.prisma
@@ -26,7 +26,8 @@ model Bounty {
type BountyType
startsAt DateTime
endsAt DateTime?
- rewardAmount Int @default(0)
+ rewardAmount Int?
+ rewardDescription String?
submissionRequirements Json?
archivedAt DateTime?
createdAt DateTime @default(now())