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 eligible bounties

Tim Wilsone9c6eb3caa3f
diff --git a/apps/web/app/(ee)/api/bounties/route.ts b/apps/web/app/(ee)/api/bounties/route.ts
index 9474538398..e6ce982fdd 100644
--- a/apps/web/app/(ee)/api/bounties/route.ts
+++ b/apps/web/app/(ee)/api/bounties/route.ts
@@ -4,6 +4,7 @@ import { createId } from "@/lib/api/create-id";
import { DubApiError } from "@/lib/api/errors";
import { throwIfInvalidGroupIds } from "@/lib/api/groups/throw-if-invalid-group-ids";
import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
+import { getProgramEnrollmentOrThrow } from "@/lib/api/programs/get-program-enrollment-or-throw";
import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
import { qstash } from "@/lib/cron";
@@ -13,6 +14,7 @@ import {
BountyListSchema,
BountySchema,
createBountySchema,
+ getBountiesQuerySchema,
} from "@/lib/zod/schemas/bounties";
import {
WORKFLOW_ACTION_TYPES,
@@ -26,12 +28,42 @@ import { NextResponse } from "next/server";
// GET /api/bounties - get all bounties for a program
export const GET = withWorkspace(
- async ({ workspace }) => {
+ async ({ workspace, searchParams }) => {
const programId = getDefaultProgramIdOrThrow(workspace);
+ const { partnerId } = getBountiesQuerySchema.parse(searchParams);
+
+ const programEnrollment = partnerId
+ ? await getProgramEnrollmentOrThrow({
+ partnerId,
+ programId,
+ includeProgram: true,
+ })
+ : null;
+
const bounties = await prisma.bounty.findMany({
where: {
programId,
+
+ // Filter only bounties the specified partner is eligible for
+ ...(programEnrollment && {
+ OR: [
+ {
+ groups: {
+ none: {},
+ },
+ },
+ {
+ groups: {
+ some: {
+ groupId:
+ programEnrollment.groupId ||
+ programEnrollment.program.defaultGroupId,
+ },
+ },
+ },
+ ],
+ }),
},
include: {
groups: {
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/[partnerId]/partner-info.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/[partnerId]/partner-info.tsx
index be166e931d..03ec52702a 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/[partnerId]/partner-info.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/[partnerId]/partner-info.tsx
@@ -3,7 +3,11 @@
import { sortRewardsByEventOrder } from "@/lib/partners/sort-rewards-by-event-order";
import useGroup from "@/lib/swr/use-group";
import useWorkspace from "@/lib/swr/use-workspace";
-import { EnrolledPartnerProps, RewardProps } from "@/lib/types";
+import {
+ BountyListProps,
+ EnrolledPartnerProps,
+ RewardProps,
+} from "@/lib/types";
import { EventDatum } from "@/ui/analytics/events/events-table";
import { PartnerInfoGroup } from "@/ui/partners/partner-info-group";
import { ProgramRewardList } from "@/ui/partners/program-reward-list";
@@ -11,8 +15,10 @@ import {
CalendarIcon,
ChartActivity2,
CopyButton,
+ Heart,
OfficeBuilding,
Tooltip,
+ Trophy,
} from "@dub/ui";
import {
COUNTRIES,
@@ -21,11 +27,16 @@ import {
formatDate,
timeAgo,
} from "@dub/utils";
+import Link from "next/link";
import { useParams } from "next/navigation";
import useSWR from "swr";
export function PartnerInfo({ partner }: { partner?: EnrolledPartnerProps }) {
- const { id: workspaceId, defaultProgramId } = useWorkspace();
+ const {
+ id: workspaceId,
+ slug: workspaceSlug,
+ defaultProgramId,
+ } = useWorkspace();
const { partnerId } = useParams() as { partnerId: string };
const { data: eventsData, isLoading: isLoadingEvents } = useSWR<EventDatum[]>(
@@ -39,6 +50,17 @@ export function PartnerInfo({ partner }: { partner?: EnrolledPartnerProps }) {
groupIdOrSlug: partner?.groupId ?? undefined,
});
+ const {
+ data: bounties,
+ isLoading: isLoadingBounties,
+ error: errorBounties,
+ } = useSWR<BountyListProps[]>(
+ workspaceId
+ ? `/api/bounties?workspaceId=${workspaceId}&partnerId=${partnerId}`
+ : null,
+ fetcher,
+ );
+
const basicFields = [
{
id: "event",
@@ -180,6 +202,43 @@ export function PartnerInfo({ partner }: { partner?: EnrolledPartnerProps }) {
<div className="h-4 w-32 animate-pulse rounded bg-neutral-200" />
)}
</div>
+
+ {/* Eligible bounties */}
+ <div className="flex flex-col gap-2">
+ <h3 className="text-content-emphasis text-xs font-semibold">
+ Eligible Bounties
+ </h3>
+ {bounties ? (
+ bounties.length ? (
+ <div className="flex flex-col gap-2">
+ {bounties.map((bounty) => {
+ const Icon = bounty.type === "performance" ? Trophy : Heart;
+ return (
+ <Link
+ key={bounty.id}
+ target="_blank"
+ href={`/${workspaceSlug}/program/bounties/${bounty.id}`}
+ className="text-content-subtle flex cursor-alias items-center gap-2 decoration-dotted underline-offset-2 hover:underline"
+ >
+ <Icon className="size-3.5 shrink-0" />
+ <span className="text-xs font-medium">{bounty.name}</span>
+ </Link>
+ );
+ })}
+ </div>
+ ) : (
+ <p className="text-content-subtle text-xs">
+ No eligible bounties
+ </p>
+ )
+ ) : errorBounties ? (
+ <p className="text-content-subtle text-xs">
+ Failed to load bounties
+ </p>
+ ) : (
+ <div className="h-4 w-24 animate-pulse rounded bg-neutral-200" />
+ )}
+ </div>
</div>
</div>
);
diff --git a/apps/web/lib/api/programs/get-program-enrollment-or-throw.ts b/apps/web/lib/api/programs/get-program-enrollment-or-throw.ts
index 3b5316404e..16b416f114 100644
--- a/apps/web/lib/api/programs/get-program-enrollment-or-throw.ts
+++ b/apps/web/lib/api/programs/get-program-enrollment-or-throw.ts
@@ -7,6 +7,7 @@ export async function getProgramEnrollmentOrThrow({
partnerId,
programId,
includePartner = false,
+ includeProgram = false,
includeClickReward = false,
includeLeadReward = false,
includeSaleReward = false,
@@ -16,6 +17,7 @@ export async function getProgramEnrollmentOrThrow({
partnerId: string;
programId: string;
includePartner?: boolean;
+ includeProgram?: boolean;
includeClickReward?: boolean;
includeLeadReward?: boolean;
includeSaleReward?: boolean;
@@ -32,6 +34,9 @@ export async function getProgramEnrollmentOrThrow({
...(includePartner && {
partner: true,
}),
+ ...(includeProgram && {
+ program: true,
+ }),
...(includeClickReward && {
clickReward: true,
}),
diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.ts
index 09c081f2eb..57180a5bb0 100644
--- a/apps/web/lib/zod/schemas/bounties.ts
+++ b/apps/web/lib/zod/schemas/bounties.ts
@@ -79,6 +79,10 @@ export const BountySchema = z.object({
groups: z.array(GroupSchema.pick({ id: true })),
});
+export const getBountiesQuerySchema = z.object({
+ partnerId: z.string().optional(),
+});
+
// used in GET /bounties
export const BountyListSchema = BountySchema.extend({
submissionsCount: z.number().default(0),