The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
show expired bounties tab
Steven Tey44c4f4bf79e7
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/bounties/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/bounties/route.tsindex 5f62e8637c..dce239a102 100644--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/bounties/route.ts+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/bounties/route.ts@@ -7,83 +7,74 @@ import { NextResponse } from "next/server";import { z } from "zod";// GET /api/partner-profile/programs/[programId]/bounties – get available bounties for an enrolled program-export const GET = withPartnerProfile(async ({ partner, params }) => {- const { program, totalCommissions, groupId, links } =- await getProgramEnrollmentOrThrow({- partnerId: partner.id,- programId: params.programId,- include: {- program: true,- links: true,- },- });+export const GET = withPartnerProfile(+ async ({ partner, params, searchParams }) => {+ const { program, totalCommissions, groupId, links } =+ await getProgramEnrollmentOrThrow({+ partnerId: partner.id,+ programId: params.programId,+ include: {+ program: true,+ links: true,+ },+ });- const now = new Date();- const partnerGroupId = groupId || program.defaultGroupId;+ const now = new Date();+ const partnerGroupId = groupId || program.defaultGroupId;- const bounties = await prisma.bounty.findMany({- where: {- programId: program.id,- startsAt: {- lte: now,- },- // Check if the bounty is active- OR: [- {- endsAt: null,+ const bounties = await prisma.bounty.findMany({+ where: {+ programId: program.id,+ startsAt: {+ lte: now,},- {- endsAt: {- gt: now,- },- },- ],- // If bounty has no groups, it's available to all partners- // If bounty has groups, only partners in those groups can see it- AND: [- {- OR: [- {- groups: {- none: {},+ // If bounty has no groups, it's available to all partners+ // If bounty has groups, only partners in those groups can see it+ AND: [+ {+ OR: [+ {+ groups: {+ none: {},+ },},- },- {- groups: {- some: {- groupId: partnerGroupId,+ {+ groups: {+ some: {+ groupId: partnerGroupId,+ },},},- },- ],- },- ],- },- include: {- workflow: {- select: {- triggerConditions: true,- },+ ],+ },+ ],},- submissions: {- where: {- partnerId: partner.id,+ include: {+ workflow: {+ select: {+ triggerConditions: true,+ },+ },+ submissions: {+ where: {+ partnerId: partner.id,+ },},},- },- });+ });- return NextResponse.json(- z.array(PartnerBountySchema).parse(- bounties.map((bounty) => ({- ...bounty,- submission: bounty.submissions?.[0] || null,- performanceCondition: bounty.workflow?.triggerConditions?.[0] || null,- partner: {- ...aggregatePartnerLinksStats(links),- totalCommissions,- },- })),- ),- );-});+ return NextResponse.json(+ z.array(PartnerBountySchema).parse(+ bounties.map((bounty) => ({+ ...bounty,+ submission: bounty.submissions?.[0] || null,+ performanceCondition: bounty.workflow?.triggerConditions?.[0] || null,+ partner: {+ ...aggregatePartnerLinksStats(links),+ totalCommissions,+ },+ })),+ ),+ );+ },+);diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/page-client.tsxindex 753e0514d2..9808852bcc 100644--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/page-client.tsx+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/page-client.tsx@@ -4,20 +4,96 @@ import usePartnerProgramBounties from "@/lib/swr/use-partner-program-bounties";import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";import { Heart, Trophy } from "@dub/ui/icons";+import { cn } from "@dub/utils";+import { useMemo, useState } from "react";import {PartnerBountyCard,PartnerBountyCardSkeleton,} from "./partner-bounty-card";+const tabs = [+ {+ label: "Active",+ id: "active",+ },+ {+ label: "Expired",+ id: "expired",+ },+] as const;+export function BountiesPageClient() {+ const [activeTab, setActiveTab] = useState<"active" | "expired">("active");const { bounties, isLoading } = usePartnerProgramBounties();+ // Filter bounties based on active tab+ const filteredBounties = useMemo(() => {+ if (!bounties) return [];++ const now = new Date();+ return bounties.filter((bounty) => {+ const isExpired = bounty.endsAt && new Date(bounty.endsAt) <= now;++ if (activeTab === "active") {+ return !isExpired;+ } else {+ return isExpired;+ }+ });+ }, [bounties, activeTab]);++ // Calculate counts for each tab+ const tabCounts = useMemo(() => {+ if (!bounties) return { active: 0, expired: 0 };++ const now = new Date();+ return bounties.reduce(+ (counts, bounty) => {+ const isExpired = bounty.endsAt && new Date(bounty.endsAt) <= now;+ counts[isExpired ? "expired" : "active"]++;+ return counts;+ },+ { active: 0, expired: 0 },+ );+ }, [bounties]);+return (<PageWidthWrapper className="pb-10">- {bounties?.length !== 0 || isLoading ? (+ <div className="mb-6 grid grid-cols-2 gap-2">+ {tabs.map((tab) => {+ const isActive = activeTab === tab.id;++ return (+ <button+ key={tab.id}+ type="button"+ className={cn(+ "border-border-subtle flex flex-col gap-1 rounded-lg border p-4 text-left transition-colors duration-100",+ isActive+ ? "border-black ring-1 ring-black"+ : "hover:bg-bg-muted",+ )}+ onClick={() => setActiveTab(tab.id)}+ >+ <span className="text-content-default text-xs font-semibold">+ {tab.label}+ </span>+ {bounties ? (+ <span className="text-content-emphasis text-base font-semibold">+ {tabCounts[tab.id].toLocaleString()}+ </span>+ ) : (+ <div className="h-6 w-12 animate-pulse rounded-md bg-neutral-200" />+ )}+ </button>+ );+ })}+ </div>++ {filteredBounties?.length !== 0 || isLoading ? (<div className="grid grid-cols-1 gap-6 md:grid-cols-2 xl:grid-cols-3">- {bounties?.length- ? bounties?.map((bounty) => (+ {filteredBounties?.length+ ? filteredBounties?.map((bounty) => (<PartnerBountyCard key={bounty.id} bounty={bounty} />)): Array.from({ length: 3 }, (_, index) => (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.tsxindex 8c5bf298a0..e9edca7cf1 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@@ -5,25 +5,42 @@ import { BountyThumbnailImage } from "@/ui/partners/bounties/bounty-thumbnail-imimport { useClaimBountyModal } from "@/ui/partners/bounties/claim-bounty-modal";import { StatusBadge } from "@dub/ui";import { Calendar6, Gift } from "@dub/ui/icons";-import { formatDate } from "@dub/utils";+import { cn, formatDate } from "@dub/utils";export function PartnerBountyCard({ bounty }: { bounty: PartnerBountyProps }) {const { claimBountyModal, setShowClaimBountyModal } = useClaimBountyModal({bounty,});+ const expiredBounty =+ bounty.endsAt && new Date(bounty.endsAt) < new Date() ? true : false;+return (<>{claimBountyModal}<buttontype="button"onClick={() => setShowClaimBountyModal(true)}- className="border-border-subtle hover:border-border-default group relative flex cursor-pointer flex-col gap-5 overflow-hidden rounded-xl border bg-white p-5 text-left transition-all hover:shadow-lg"+ disabled={expiredBounty}+ className={cn(+ "border-border-subtle group relative flex cursor-pointer flex-col gap-5 overflow-hidden rounded-xl border bg-white p-5 text-left",+ expiredBounty+ ? "cursor-not-allowed"+ : "hover:border-border-default transition-all hover:shadow-lg",+ )}><div className="relative flex h-[132px] items-center justify-center rounded-lg bg-neutral-100 py-1.5"><div className="relative size-full"><BountyThumbnailImage bounty={bounty} /></div>++ {expiredBounty && (+ <div className="absolute left-2 top-2 z-10">+ <div className="flex h-5 items-center gap-1 rounded-md bg-red-100 px-2 py-1 text-xs font-semibold text-red-600">+ Expired {formatDate(bounty.endsAt!, { month: "short" })}+ </div>+ </div>+ )}</div><div className="flex min-w-0 flex-col gap-1.5">@@ -35,7 +52,10 @@ export function PartnerBountyCard({ bounty }: { bounty: PartnerBountyProps }) {<Calendar6 className="size-3.5" /><span>{bounty.endsAt ? (- <>Ends {formatDate(bounty.endsAt, { month: "short" })}</>+ <>+ End{expiredBounty ? "ed" : "s"}{" "}+ {formatDate(bounty.endsAt, { month: "short" })}+ </>) : ("No end date")}@@ -50,12 +70,14 @@ export function PartnerBountyCard({ bounty }: { bounty: PartnerBountyProps }) {</div></div>- <div className="flex grow flex-col justify-end">- {renderSubmissionStatus({- bounty,- setShowClaimBountyModal,- })}- </div>+ {!expiredBounty && (+ <div className="flex grow flex-col justify-end">+ {renderSubmissionStatus({+ bounty,+ setShowClaimBountyModal,+ })}+ </div>+ )}</button></>);@@ -88,7 +110,6 @@ function renderSubmissionStatus({setShowClaimBountyModal: (show: boolean) => void;}) {const { submission } = bounty;-// When there is no submission, we show the performance or claim bounty buttonif (!submission) {return bounty.type === "performance" ? (diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsxindex ebb913f504..25af1dc88f 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx@@ -86,6 +86,28 @@ function BountySubmissionDetailsSheetContent({},});+ // right arrow key onNext+ useKeyboardShortcut(+ "ArrowRight",+ () => {+ if (onNext) {+ onNext();+ }+ },+ { sheet: true },+ );++ // left arrow key onPrevious+ useKeyboardShortcut(+ "ArrowLeft",+ () => {+ if (onPrevious) {+ onPrevious();+ }+ },+ { sheet: true },+ );+useKeyboardShortcut("a",() => {diff --git a/apps/web/ui/partners/partner-application-sheet.tsx b/apps/web/ui/partners/partner-application-sheet.tsxindex 3b338ef869..c7fd8dffbc 100644--- a/apps/web/ui/partners/partner-application-sheet.tsx+++ b/apps/web/ui/partners/partner-application-sheet.tsx@@ -45,6 +45,28 @@ function PartnerApplicationSheetContent({partner.groupId ?? null,);+ // right arrow key onNext+ useKeyboardShortcut(+ "ArrowRight",+ () => {+ if (onNext) {+ onNext();+ }+ },+ { sheet: true },+ );++ // left arrow key onPrevious+ useKeyboardShortcut(+ "ArrowLeft",+ () => {+ if (onPrevious) {+ onPrevious();+ }+ },+ { sheet: true },+ );+// Reset selection when navigating between partnersuseEffect(() => {setSelectedGroupId(partner.groupId ?? null);