The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Implement currentStatsOnly functionality in bounty APIs and UI components
Kiran Kf78220507327
diff --git a/apps/web/app/(ee)/api/bounties/route.ts b/apps/web/app/(ee)/api/bounties/route.tsindex 7bbe84c695..0d97883f3e 100644--- a/apps/web/app/(ee)/api/bounties/route.ts+++ b/apps/web/app/(ee)/api/bounties/route.ts@@ -44,7 +44,6 @@ export const GET = withWorkspace(const bounties = await prisma.bounty.findMany({where: {programId,-// Filter only bounties the specified partner is eligible for...(programEnrollment && {OR: [@@ -132,13 +131,13 @@ export const POST = withWorkspace(if (type === "performance") {throw new DubApiError({code: "bad_request",- message: "Reward amount is required for performance bounties",+ message: "Reward amount is required for performance bounties.",});} else if (!rewardDescription) {throw new DubApiError({code: "bad_request",message:- "For submission bounties, either reward amount or reward description is required",+ "For submission bounties, either reward amount or reward description is required.",});}}@@ -161,7 +160,7 @@ export const POST = withWorkspace(if (!bountyName) {throw new DubApiError({code: "bad_request",- message: "Bounty name is required",+ message: "Bounty name is required.",});}@@ -203,6 +202,7 @@ export const POST = withWorkspace(endsAt,rewardAmount,rewardDescription,+ currentStatsOnly: type === "performance" ? currentStatsOnly : null,...(submissionRequirements &&type === "submission" && {submissionRequirements,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.tsxindex c016db5dca..52319d5a56 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@@ -129,6 +129,9 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {: {operator: "gte",},+ ...(bounty && {+ currentStatsOnly: bounty.currentStatsOnly,+ }),},});diff --git a/apps/web/lib/api/bounties/get-bounty-with-details.ts b/apps/web/lib/api/bounties/get-bounty-with-details.tsindex d3c4ece849..c52603e945 100644--- a/apps/web/lib/api/bounties/get-bounty-with-details.ts+++ b/apps/web/lib/api/bounties/get-bounty-with-details.ts@@ -19,6 +19,7 @@ export const getBountyWithDetails = async ({b.rewardAmount,b.rewardDescription,b.submissionRequirements,+ b.currentStatsOnly,wf.triggerConditions,-- Partners count@@ -84,6 +85,10 @@ export const getBountyWithDetails = async ({const bounty = bounties[0];const performanceCondition =bounty.triggerConditions?.length > 0 ? bounty.triggerConditions[0] : null;+ const currentStatsOnly =+ typeof bounty.currentStatsOnly === "number"+ ? bounty.currentStatsOnly === 1+ : null;return {id: bounty.id,@@ -95,6 +100,7 @@ export const getBountyWithDetails = async ({rewardAmount: bounty.rewardAmount,rewardDescription: bounty.rewardDescription,submissionRequirements: bounty.submissionRequirements,+ currentStatsOnly,performanceCondition,groups: bounty.groups.filter((group) => group !== null) ?? [],partnersCount: Number(bounty.partners),diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.tsindex 2bf14c8fb9..715c9fec34 100644--- a/apps/web/lib/zod/schemas/bounties.ts+++ b/apps/web/lib/zod/schemas/bounties.ts@@ -58,7 +58,7 @@ export const createBountySchema = z.object({submissionRequirements: submissionRequirementsSchema.nullish(),groupIds: z.array(z.string()).nullable(),performanceCondition: workflowConditionSchema.nullish(),- currentStatsOnly: z.boolean().default(false),+ currentStatsOnly: z.boolean().nullable(),});export const updateBountySchema = createBountySchema@@ -86,6 +86,7 @@ export const BountySchema = z.object({performanceCondition: workflowConditionSchema.nullable().default(null),submissionRequirements: submissionRequirementsSchema.nullable().default(null),groups: z.array(GroupSchema.pick({ id: true })),+ currentStatsOnly: z.boolean().nullable(),});export const getBountiesQuerySchema = z.object({diff --git a/apps/web/ui/partners/bounties/bounty-logic.tsx b/apps/web/ui/partners/bounties/bounty-logic.tsxindex f58d0b0270..78e0ee727a 100644--- a/apps/web/ui/partners/bounties/bounty-logic.tsx+++ b/apps/web/ui/partners/bounties/bounty-logic.tsx@@ -23,9 +23,10 @@ const WORKFLOW_ATTRIBUTE_LABELS: Record<WorkflowConditionAttribute, string> = {export function BountyLogic({ className }: { className?: string }) {const { control, watch } = useAddEditBountyForm();- const [attribute, value] = watch([+ const [attribute, value, currentStatsOnly] = watch(["performanceCondition.attribute","performanceCondition.value",+ "currentStatsOnly",]);return (@@ -40,29 +41,56 @@ export function BountyLogic({ className }: { className?: string }) {</div><span className="text-content-emphasis text-sm font-medium leading-relaxed">When partner{" "}- <Controller- control={control}- name="performanceCondition.attribute"- render={({ field }) => (- <InlineBadgePopover- text={- field.value- ? WORKFLOW_ATTRIBUTE_LABELS[field.value]- : "activity"- }- invalid={!field.value}- >- <InlineBadgePopoverMenu- selectedValue={field.value}- onSelect={field.onChange}- items={WORKFLOW_ATTRIBUTES.map((attribute) => ({- text: WORKFLOW_ATTRIBUTE_LABELS[attribute],- value: attribute,- }))}- />- </InlineBadgePopover>- )}- />+ <div className="inline-flex items-center gap-1">+ <Controller+ control={control}+ name="currentStatsOnly"+ render={({ field }) => (+ <InlineBadgePopover+ text={+ field.value === true+ ? "new"+ : field.value === false+ ? "all-time"+ : "type"+ }+ invalid={field.value === undefined || field.value === null}+ >+ <InlineBadgePopoverMenu+ selectedValue={field.value}+ onSelect={field.onChange}+ items={[+ { text: "new", value: true },+ { text: "all-time", value: false },+ ]}+ />+ </InlineBadgePopover>+ )}+ />+ <Controller+ control={control}+ name="performanceCondition.attribute"+ render={({ field }) => (+ <InlineBadgePopover+ text={+ field.value+ ? WORKFLOW_ATTRIBUTE_LABELS[field.value]+ : "activity"+ }+ invalid={!field.value}+ >+ <InlineBadgePopoverMenu+ selectedValue={field.value}+ onSelect={field.onChange}+ items={WORKFLOW_ATTRIBUTES.map((attribute) => ({+ text: WORKFLOW_ATTRIBUTE_LABELS[attribute],+ value: attribute,+ }))}+ />+ </InlineBadgePopover>+ )}+ />+ </div>{attribute && (<>{" "}diff --git a/packages/prisma/schema/bounty.prisma b/packages/prisma/schema/bounty.prismaindex c1e1bbf74e..5b9010d97f 100644--- a/packages/prisma/schema/bounty.prisma+++ b/packages/prisma/schema/bounty.prisma@@ -25,7 +25,7 @@ model Bounty {name Stringdescription String? @db.Texttype BountyType- currentStatsOnly Boolean? @default(false)+ currentStatsOnly Boolean?startsAt DateTimeendsAt DateTime?rewardAmount Int?