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.

calculate bountiesCount in usePartnerProgramBounties

Steven Teybb9ae2078514
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.tsx
index 9808852bcc..5e7788598c 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
@@ -24,7 +24,7 @@ const tabs = [
export function BountiesPageClient() {
const [activeTab, setActiveTab] = useState<"active" | "expired">("active");
- const { bounties, isLoading } = usePartnerProgramBounties();
+ const { bounties, bountiesCount, isLoading } = usePartnerProgramBounties();
// Filter bounties based on active tab
const filteredBounties = useMemo(() => {
@@ -42,21 +42,6 @@ export function BountiesPageClient() {
});
}, [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">
<div className="mb-6 grid grid-cols-2 gap-2">
@@ -80,7 +65,7 @@ export function BountiesPageClient() {
</span>
{bounties ? (
<span className="text-content-emphasis text-base font-semibold">
- {tabCounts[tab.id].toLocaleString()}
+ {bountiesCount[tab.id].toLocaleString()}
</span>
) : (
<div className="h-6 w-12 animate-pulse rounded-md bg-neutral-200" />
diff --git a/apps/web/lib/swr/use-partner-program-bounties.ts b/apps/web/lib/swr/use-partner-program-bounties.ts
index d66a67fd9b..1330eadfb7 100644
--- a/apps/web/lib/swr/use-partner-program-bounties.ts
+++ b/apps/web/lib/swr/use-partner-program-bounties.ts
@@ -1,5 +1,6 @@
import { fetcher } from "@dub/utils";
import { useParams } from "next/navigation";
+import { useMemo } from "react";
import useSWR from "swr";
import { PartnerBountyProps } from "../types";
@@ -25,8 +26,21 @@ export default function usePartnerProgramBounties({
},
);
+ const bountiesCount = useMemo(() => {
+ if (!bounties) return { active: 0, expired: 0 };
+ return bounties.reduce(
+ (counts, bounty) => {
+ const isExpired = bounty.endsAt && new Date(bounty.endsAt) < new Date();
+ counts[isExpired ? "expired" : "active"]++;
+ return counts;
+ },
+ { active: 0, expired: 0 },
+ );
+ }, [bounties]);
+
return {
bounties,
+ bountiesCount,
isLoading,
error,
};
diff --git a/apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx b/apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx
index 35ca8ffc8d..d845b34e6c 100644
--- a/apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx
+++ b/apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx
@@ -284,7 +284,7 @@ export function PartnersSidebarNav({
status: "invited",
});
- const { bounties } = usePartnerProgramBounties({
+ const { bountiesCount } = usePartnerProgramBounties({
enabled: isEnrolledProgramPage,
});
@@ -308,7 +308,7 @@ export function PartnersSidebarNav({
!!programEnrollment && programEnrollment.status !== "approved",
invitationsCount,
unreadMessagesCount,
- programBountiesCount: bounties?.length,
+ programBountiesCount: bountiesCount.active,
}}
toolContent={toolContent}
newsContent={newsContent}