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.

Refactor bounty stats API and usage

Kiran K1319991be4bd
diff --git a/apps/web/app/(ee)/api/bounties/count/route.ts b/apps/web/app/(ee)/api/bounties/count/route.ts
new file mode 100644
index 0000000000..2991d690c9
--- /dev/null
+++ b/apps/web/app/(ee)/api/bounties/count/route.ts
@@ -0,0 +1,42 @@
+import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
+import { withWorkspace } from "@/lib/auth";
+import { prisma } from "@dub/prisma";
+import { BountySubmissionStatus } from "@dub/prisma/client";
+import { NextResponse } from "next/server";
+import { z } from "zod";
+
+const bountiesCountQuerySchema = z.object({
+ groupBy: z.enum(["status", "bountyId"]).optional().default("status"),
+});
+
+const statuses = Object.values(BountySubmissionStatus);
+
+// GET /api/bounties/count
+export const GET = withWorkspace(async ({ workspace, searchParams }) => {
+ const programId = getDefaultProgramIdOrThrow(workspace);
+ const { groupBy } = bountiesCountQuerySchema.parse(searchParams);
+
+ const count = await prisma.bountySubmission.groupBy({
+ by: ["status"],
+ where: {
+ programId,
+ },
+ _count: true,
+ });
+
+ const counts = count.map((c) => ({
+ status: c.status,
+ count: c._count,
+ }));
+
+ statuses.forEach((status) => {
+ if (!counts.some((c) => c.status === status)) {
+ counts.push({
+ status,
+ count: 0,
+ });
+ }
+ });
+
+ return NextResponse.json(counts);
+});
diff --git a/apps/web/app/(ee)/api/bounties/route.ts b/apps/web/app/(ee)/api/bounties/route.ts
index b8e85568d9..2b5d3dd44c 100644
--- a/apps/web/app/(ee)/api/bounties/route.ts
+++ b/apps/web/app/(ee)/api/bounties/route.ts
@@ -8,7 +8,6 @@ import { WorkflowAction } from "@/lib/types";
import { sendWorkspaceWebhook } from "@/lib/webhook/publish";
import {
BountySchema,
- BountySchemaExtended,
createBountySchema,
getBountiesQuerySchema,
} from "@/lib/zod/schemas/bounties";
@@ -21,7 +20,6 @@ import { Workflow } from "@dub/prisma/client";
import { APP_DOMAIN_WITH_NGROK } from "@dub/utils";
import { waitUntil } from "@vercel/functions";
import { NextResponse } from "next/server";
-import { z } from "zod";
// GET /api/bounties - get all bounties for a program
export const GET = withWorkspace(async ({ workspace, searchParams }) => {
@@ -33,7 +31,7 @@ export const GET = withWorkspace(async ({ workspace, searchParams }) => {
programId,
});
- return NextResponse.json(z.array(BountySchemaExtended).parse(bounties));
+ return NextResponse.json(bounties);
});
// POST /api/bounties - create a bounty
diff --git a/apps/web/app/(ee)/api/bounties/stats/route.ts b/apps/web/app/(ee)/api/bounties/stats/route.ts
deleted file mode 100644
index 85b09db8e6..0000000000
--- a/apps/web/app/(ee)/api/bounties/stats/route.ts
+++ /dev/null
@@ -1,89 +0,0 @@
-import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
-import { withWorkspace } from "@/lib/auth";
-import { bountyStatsSchema } from "@/lib/zod/schemas/bounties";
-import { prisma } from "@dub/prisma";
-import { NextResponse } from "next/server";
-import { z } from "zod";
-
-// TODO (kiran):
-// Simplify this route
-
-// GET /api/bounties/stats - get the stats for all bounties in a program
-export const GET = withWorkspace(async ({ workspace }) => {
- const programId = getDefaultProgramIdOrThrow(workspace);
-
- const [bounties, enrollmentsCount, pendingSubmissionsCounts] =
- await Promise.all([
- prisma.bounty.findMany({
- where: {
- programId,
- },
- include: {
- groups: {
- include: {
- partnerGroup: {
- include: {
- _count: {
- select: {
- partners: {
- where: {
- status: "approved",
- },
- },
- },
- },
- },
- },
- },
- },
- _count: {
- select: {
- submissions: true,
- },
- },
- },
- }),
-
- prisma.programEnrollment.count({
- where: {
- programId,
- status: "approved",
- },
- }),
-
- prisma.bountySubmission.groupBy({
- by: ["bountyId"],
- where: {
- bounty: {
- programId,
- },
- status: "pending",
- },
- _count: true,
- }),
- ]);
-
- const pendingSubmissionsMap = pendingSubmissionsCounts.reduce(
- (acc, item) => {
- acc[item.bountyId] = item._count;
- return acc;
- },
- {} as Record<string, number>,
- );
-
- const result = bounties.map((bounty) => {
- const totalPartners = bounty.groups.reduce(
- (acc, group) => acc + group.partnerGroup._count.partners,
- 0,
- );
-
- return {
- id: bounty.id,
- submissions: bounty._count.submissions,
- pendingSubmissions: pendingSubmissionsMap[bounty.id] || 0,
- partners: bounty.groups.length > 0 ? totalPartners : enrollmentsCount,
- };
- });
-
- return NextResponse.json(z.array(bountyStatsSchema).parse(result));
-});
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 7631639024..bdb565b1e7 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,14 +1,12 @@
"use client";
import useBounty from "@/lib/swr/use-bounty";
-import useBountyStats from "@/lib/swr/use-bounty-stats";
import { BountyThumbnailImage } from "@/ui/partners/bounties/bounty-thumbnail-image";
import { formatDate, pluralize } from "@dub/utils";
import { CalendarDays, Users } from "lucide-react";
export function BountyInfo() {
const { bounty } = useBounty();
- const { bountyStats } = useBountyStats();
return (
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:gap-6">
@@ -33,7 +31,7 @@ export function BountyInfo() {
</span>
</div>
- <div className="flex items-center space-x-2">
+ {/* <div className="flex items-center space-x-2">
<Users className="size-4 shrink-0" />
<div className="text-sm text-neutral-500">
<span className="font-medium text-neutral-700">
@@ -45,7 +43,7 @@ export function BountyInfo() {
</span>{" "}
{pluralize("partner", bountyStats?.partners ?? 0)} completed
</div>
- </div>
+ </div> */}
</div>
)}
</div>
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 e16ff573df..6d2a4020f8 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,5 +1,4 @@
import { mutatePrefix } from "@/lib/swr/mutate";
-import useBountiesStats from "@/lib/swr/use-bounties-stats";
import useWorkspace from "@/lib/swr/use-workspace";
import { BountyExtendedProps } from "@/lib/types";
import { useConfirmModal } from "@/ui/modals/confirm-modal";
@@ -9,18 +8,13 @@ import { Calendar6, Dots, PenWriting, Trash, Users } from "@dub/ui/icons";
import { formatDate, pluralize } from "@dub/utils";
import { Command } from "cmdk";
import Link from "next/link";
-import { useMemo, useState } from "react";
+import { useState } from "react";
import { toast } from "sonner";
export function BountyCard({ bounty }: { bounty: BountyExtendedProps }) {
- const { id: workspaceId, slug: workspaceSlug } = useWorkspace();
const { queryParams } = useRouterStuff();
- const { bountiesStats, isLoading: isLoadingStats } = useBountiesStats();
const [isMenuOpen, setIsMenuOpen] = useState(false);
-
- const stats = useMemo(() => {
- return bountiesStats?.find(({ id }) => id === bounty.id);
- }, [bountiesStats, bounty.id]);
+ const { id: workspaceId, slug: workspaceSlug } = useWorkspace();
const { confirmModal: deleteModal, setShowConfirmModal: setShowDeleteModal } =
useConfirmModal({
@@ -41,7 +35,7 @@ export function BountyCard({ bounty }: { bounty: BountyExtendedProps }) {
if (!response.ok) throw new Error("Failed to delete bounty");
- mutatePrefix("/api/bounties");
+ await mutatePrefix("/api/bounties");
},
{
loading: "Deleting bounty...",
@@ -65,9 +59,7 @@ export function BountyCard({ bounty }: { bounty: BountyExtendedProps }) {
<BountyThumbnailImage bounty={bounty} />
</div>
- {stats?.pendingSubmissions && stats.pendingSubmissions > 0 ? (
- <PendingSubmissionsBadge count={stats.pendingSubmissions} />
- ) : null}
+ <PendingSubmissionsBadge count={bounty.submissionsCount} />
</div>
<div className="flex flex-col gap-1.5">
@@ -91,20 +83,14 @@ export function BountyCard({ bounty }: { bounty: BountyExtendedProps }) {
<div className="text-content-subtle flex items-center gap-2 text-sm font-medium">
<Users className="size-3.5" />
<div className="h-5">
- {isLoadingStats || bountiesStats === undefined ? (
- <div className="h-5 w-48 animate-pulse rounded bg-neutral-300" />
- ) : stats ? (
- <>
- <span className="text-content-default">
- {stats.submissions}
- </span>{" "}
- of{" "}
- <span className="text-content-default">{stats.partners}</span>{" "}
- partners completed
- </>
- ) : (
- <span>Failed to load stats</span>
- )}
+ <span className="text-content-default">
+ {bounty.submissionsCount}
+ </span>{" "}
+ of{" "}
+ <span className="text-content-default">
+ {bounty.partnersCount}
+ </span>{" "}
+ partners completed
</div>
</div>
</div>
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-list.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-list.tsx
index 4754bf8e59..be6edcd593 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-list.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-list.tsx
@@ -13,7 +13,7 @@ import { BountyCard, BountyCardSkeleton } from "./bounty-card";
export function BountyList() {
const { searchParams } = useRouterStuff();
- const { id: workspaceId, defaultProgramId } = useWorkspace();
+ const { id: workspaceId } = useWorkspace();
const [bountySheetState, setBountySheetState] = useState<
{ open: false; bountyId: string | null } | { open: true; bountyId: string }
@@ -27,24 +27,14 @@ export function BountyList() {
);
}, [searchParams.get("bountyId")]);
- const {
- data: bounties,
- isLoading,
- error,
- } = useSWR<BountyExtendedProps[]>(
- workspaceId && defaultProgramId
- ? `/api/bounties?workspaceId=${workspaceId}&programId=${defaultProgramId}&includeExpandedFields=true`
- : null,
+ const { data: bounties, isLoading } = useSWR<BountyExtendedProps[]>(
+ workspaceId ? `/api/bounties?workspaceId=${workspaceId}` : null,
fetcher,
{
keepPreviousData: true,
},
);
- if (error) {
- return <></>;
- }
-
const currentBounty = bountySheetState.bountyId
? bounties?.find((b) => b?.id === bountySheetState.bountyId)
: undefined;
diff --git a/apps/web/lib/api/bounties/get-bounties.ts b/apps/web/lib/api/bounties/get-bounties.ts
index fd86e3e937..bb6680289a 100644
--- a/apps/web/lib/api/bounties/get-bounties.ts
+++ b/apps/web/lib/api/bounties/get-bounties.ts
@@ -1,4 +1,7 @@
-import { getBountiesQuerySchema } from "@/lib/zod/schemas/bounties";
+import {
+ BountySchemaExtended,
+ getBountiesQuerySchema,
+} from "@/lib/zod/schemas/bounties";
import { prisma } from "@dub/prisma";
import { Prisma } from "@prisma/client";
import { z } from "zod";
@@ -12,14 +15,7 @@ const sortColumnsMap = {
};
export async function getBounties(filters: BountyFilters) {
- const {
- page,
- pageSize,
- sortBy,
- sortOrder,
- programId,
- includeExpandedFields,
- } = filters;
+ const { page, pageSize, sortBy, sortOrder, programId } = filters;
const bounties: any[] = await prisma.$queryRaw`
SELECT
@@ -32,35 +28,54 @@ export async function getBounties(filters: BountyFilters) {
b.rewardAmount,
b.submissionRequirements,
wf.triggerConditions,
- ${
- includeExpandedFields
- ? Prisma.sql`
- COUNT(DISTINCT pe.partnerId) as partnersCount,
- COALESCE(
- (
- SELECT JSON_ARRAYAGG(
- JSON_OBJECT('id', bgSub.groupId)
- )
- FROM BountyGroup bgSub
- WHERE bgSub.bountyId = b.id
- ),
- JSON_ARRAY()
- ) as groups
- `
- : Prisma.sql`
- 0 as partnersCount,
- JSON_ARRAY() as groups
- `
- }
+
+ -- Partners count
+ COALESCE(
+ (
+ SELECT COUNT(DISTINCT pe.partnerId)
+ FROM ProgramEnrollment pe
+ WHERE pe.status IN ('approved', 'invited')
+ AND (
+ -- If bounty has specific groups, count only partners in those groups
+ EXISTS (
+ SELECT 1
+ FROM BountyGroup bg
+ WHERE bg.bountyId = b.id AND bg.groupId = pe.groupId
+ )
+ OR
+ -- If bounty has no groups, count all approved/invited partners
+ NOT EXISTS (
+ SELECT 1
+ FROM BountyGroup bg
+ WHERE bg.bountyId = b.id
+ )
+ )
+ ),
+ 0
+ ) as partnersCount,
+
+ -- Bounty groups
+ COALESCE(
+ (
+ SELECT JSON_ARRAYAGG(JSON_OBJECT('id', groupId))
+ FROM BountyGroup
+ WHERE bountyId = b.id
+ ),
+ JSON_ARRAY()
+ ) as groups,
+
+ -- Bounty submissions count
+ COALESCE(
+ (
+ SELECT COUNT(bs.id)
+ FROM BountySubmission bs
+ WHERE bs.bountyId = b.id
+ ),
+ 0
+ ) AS submissions
FROM Bounty b
- ${
- includeExpandedFields
- ? Prisma.sql`
- LEFT JOIN BountyGroup bg ON bg.bountyId = b.id
- LEFT JOIN ProgramEnrollment pe ON pe.groupId = bg.groupId AND pe.status IN ('approved', 'invited')
- `
- : Prisma.sql``
- }
+ LEFT JOIN BountyGroup bg ON bg.bountyId = b.id
+ LEFT JOIN ProgramEnrollment pe ON pe.groupId = bg.groupId AND pe.status IN ('approved', 'invited')
LEFT JOIN Workflow wf ON wf.id = b.workflowId
WHERE b.programId = ${programId}
GROUP BY b.id, b.name, b.description, b.type, b.startsAt, b.endsAt, b.rewardAmount, b.submissionRequirements
@@ -68,11 +83,25 @@ export async function getBounties(filters: BountyFilters) {
LIMIT ${pageSize} OFFSET ${(page - 1) * pageSize}
`;
- return bounties.map((bounty) => ({
- ...bounty,
- partnersCount: Number(bounty.partnersCount),
- groups: bounty.groups.filter((group) => group !== null),
- performanceCondition:
- bounty.triggerConditions?.length > 0 ? bounty.triggerConditions[0] : null,
- }));
+ const results = bounties.map((bounty) => {
+ const performanceCondition =
+ bounty.triggerConditions?.length > 0 ? bounty.triggerConditions[0] : null;
+
+ return {
+ id: bounty.id,
+ name: bounty.name,
+ description: bounty.description,
+ type: bounty.type,
+ startsAt: bounty.startsAt,
+ endsAt: bounty.endsAt,
+ rewardAmount: bounty.rewardAmount,
+ submissionRequirements: bounty.submissionRequirements,
+ performanceCondition,
+ partnersCount: Number(bounty.partnersCount),
+ submissionsCount: Number(bounty.submissions),
+ groups: bounty.groups.filter((group) => group !== null),
+ };
+ });
+
+ return z.array(BountySchemaExtended).parse(results);
}
diff --git a/apps/web/lib/swr/use-bounties-stats.ts b/apps/web/lib/swr/use-bounties-stats.ts
deleted file mode 100644
index 1120668d91..0000000000
--- a/apps/web/lib/swr/use-bounties-stats.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-import { fetcher } from "@dub/utils";
-import useSWR from "swr";
-import { BountyStats } from "../types";
-import useWorkspace from "./use-workspace";
-
-export default function useBountiesStats({
- enabled = true,
-}: {
- enabled?: boolean;
-} = {}) {
- const { id: workspaceId } = useWorkspace();
-
- const {
- data: bountiesStats,
- error,
- isLoading,
- } = useSWR<BountyStats[]>(
- enabled && workspaceId
- ? `/api/bounties/stats?workspaceId=${workspaceId}`
- : undefined,
- fetcher,
- );
-
- return {
- bountiesStats,
- isLoading,
- error,
- };
-}
diff --git a/apps/web/lib/swr/use-bounty-stats.ts b/apps/web/lib/swr/use-bounty-stats.ts
deleted file mode 100644
index 216937e385..0000000000
--- a/apps/web/lib/swr/use-bounty-stats.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import { useParams } from "next/navigation";
-import { useMemo } from "react";
-import useBountiesStats from "./use-bounties-stats";
-
-export default function useBountyStats() {
- const { bountiesStats } = useBountiesStats();
- const { bountyId } = useParams<{ bountyId: string }>();
-
- const bountyStats = useMemo(() => {
- return bountiesStats?.find((bounty) => bounty.id === bountyId);
- }, [bountiesStats, bountyId]);
-
- return {
- bountyStats,
- };
-}
diff --git a/apps/web/lib/swr/use-bounty-submissions-count.ts b/apps/web/lib/swr/use-bounty-submissions-count.ts
new file mode 100644
index 0000000000..99b7363cab
--- /dev/null
+++ b/apps/web/lib/swr/use-bounty-submissions-count.ts
@@ -0,0 +1,36 @@
+import { BountySubmissionStatus } from "@dub/prisma/client";
+import { useRouterStuff } from "@dub/ui";
+import { fetcher } from "@dub/utils";
+import useSWR from "swr";
+import useWorkspace from "./use-workspace";
+
+export interface SubmissionsCountByStatus {
+ status: BountySubmissionStatus;
+ count: number;
+}
+
+export function useBountySubmissionsCount<T>({
+ enabled,
+}: {
+ enabled?: boolean;
+}) {
+ const { id: workspaceId } = useWorkspace();
+ const { getQueryString } = useRouterStuff();
+
+ const { data: submissionsCount, error } = useSWR<T>(
+ enabled
+ ? `/api/bounties/count${getQueryString({
+ workspaceId,
+ })}`
+ : null,
+ fetcher,
+ {
+ keepPreviousData: true,
+ },
+ );
+
+ return {
+ submissionsCount,
+ error,
+ };
+}
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index e061ff0a9e..a1e04dcc18 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -6,6 +6,7 @@ import {
} from "@/lib/zod/schemas/partner-profile";
import { DirectorySyncProviders } from "@boxyhq/saml-jackson";
import {
+ BountySubmissionStatus,
CommissionStatus,
FolderUserRole,
Link,
@@ -566,3 +567,12 @@ export interface WorkflowContext {
export type BountySubmissionsQueryFilters = z.infer<
typeof getBountySubmissionsQuerySchema
>;
+
+// export type BountySubmissionsCount = Record<
+// BountySubmissionStatus,
+// {
+// count: number;
+// amount: number;
+// earnings: number;
+// }
+// >;
diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.ts
index 6e8e066ec5..94fc485836 100644
--- a/apps/web/lib/zod/schemas/bounties.ts
+++ b/apps/web/lib/zod/schemas/bounties.ts
@@ -6,7 +6,7 @@ import {
import { z } from "zod";
import { CommissionSchema } from "./commissions";
import { GroupSchema } from "./groups";
-import { booleanQuerySchema, getPaginationQuerySchema } from "./misc";
+import { getPaginationQuerySchema } from "./misc";
import { EnrolledPartnerSchema, PARTNERS_MAX_PAGE_SIZE } from "./partners";
import { UserSchema } from "./users";
import { parseDateSchema } from "./utils";
@@ -60,14 +60,9 @@ export const BountySchema = z.object({
});
export const BountySchemaExtended = BountySchema.extend({
+ groups: z.array(GroupSchema.pick({ id: true })).nullable(),
partnersCount: z.number().default(0),
- groups: z
- .array(
- GroupSchema.pick({
- id: true,
- }),
- )
- .nullable(),
+ submissionsCount: z.number().default(0),
});
export const BountySubmissionFileSchema = z.object({
@@ -136,7 +131,6 @@ export const getBountiesQuerySchema = z
.object({
sortBy: z.enum(["createdAt"]).default("createdAt"),
sortOrder: z.enum(["asc", "desc"]).default("desc"),
- includeExpandedFields: booleanQuerySchema.optional(),
})
.merge(getPaginationQuerySchema({ pageSize: BOUNTIES_MAX_PAGE_SIZE }));
diff --git a/apps/web/scripts/bounty.ts b/apps/web/scripts/bounty.ts
index c488a3cc0d..3e911d0ff4 100644
--- a/apps/web/scripts/bounty.ts
+++ b/apps/web/scripts/bounty.ts
@@ -5,13 +5,20 @@ import "dotenv-flow/config";
// TODO:
// Remove this
async function main() {
- await prisma.bountySubmission.create({
- data: {
+ const bountyId = "bnty_1K3BTNY5XCCZJT1RRYW8R6VVQ";
+ const partnerIds = [
+ "pn_1K33CAFZV1207H5XBR720XAK6",
+ "pn_1K33CAFZV2NSRHVY098A0DSPP",
+ "pn_1K33CAFZV9XKMBJFW23V1VEXP"
+ ];
+
+ await prisma.bountySubmission.createMany({
+ data: partnerIds.map((partnerId) => ({
id: createId({ prefix: "bnty_sub_" }),
programId: "prog_1K2J9DRWPPJ2F1RX53N92TSGA",
- partnerId: "pn_1K33CAFZV9XKMBJFW23V1VEXP",
- bountyId: "bnty_1K38BKWCB1CZYTCXAXYCDYKXQ",
- },
+ partnerId,
+ bountyId,
+ })),
});
}
diff --git a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
index 374d600e7d..d50abf7bbc 100644
--- a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
+++ b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
@@ -1,7 +1,10 @@
"use client";
import { getPlanCapabilities } from "@/lib/plan-capabilities";
-import useBountiesStats from "@/lib/swr/use-bounties-stats";
+import {
+ SubmissionsCountByStatus,
+ useBountySubmissionsCount,
+} from "@/lib/swr/use-bounty-submissions-count";
import useCustomersCount from "@/lib/swr/use-customers-count";
import useWorkspace from "@/lib/swr/use-workspace";
import { useRouterStuff } from "@dub/ui";
@@ -453,18 +456,14 @@ export function AppSidebarNav({
enabled: Boolean(currentArea === "program" && defaultProgramId),
});
- const { bountiesStats } = useBountiesStats({
+ const { submissionsCount } = useBountySubmissionsCount<
+ SubmissionsCountByStatus[]
+ >({
enabled: Boolean(currentArea === "program" && defaultProgramId),
});
- const pendingBountySubmissionsCount = useMemo(
- () =>
- bountiesStats?.reduce(
- (acc, { pendingSubmissions }) => acc + pendingSubmissions,
- 0,
- ),
- [bountiesStats],
- );
+ const pendingBountySubmissionsCount =
+ submissionsCount?.find(({ status }) => status === "pending")?.count || 0;
const { data: customersCount } = useCustomersCount({
enabled: canTrackConversions === true,