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 BountyInfo to use useBountyStats for submission

Kiran K5bec3af1d2fa
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 10766de0f6..ac4632da3f 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,15 +1,13 @@
"use client";
import useBounty from "@/lib/swr/use-bounty";
+import useBountyStats from "@/lib/swr/use-bounty-stats";
import { formatDate } from "@dub/utils";
import { CalendarDays, Trophy, Users } from "lucide-react";
-import { useParams } from "next/navigation";
export function BountyInfo() {
- const { bountyId } = useParams<{ bountyId: string }>();
- const { bounty } = useBounty({ bountyId });
-
- const completed = 50;
+ const { bounty } = useBounty();
+ const { bountyStats } = useBountyStats();
return (
<div className="flex items-center gap-6">
@@ -37,10 +35,12 @@ export function BountyInfo() {
<div className="flex items-center space-x-2">
<Users className="size-4" />
<div className="text-sm text-neutral-500">
- <span className="font-medium text-neutral-700">{completed}</span>{" "}
+ <span className="font-medium text-neutral-700">
+ {bountyStats?.submissions}
+ </span>{" "}
of{" "}
<span className="font-medium text-neutral-700">
- {/* {bounty.submissionsCount} */} X
+ {bountyStats?.partners}
</span>{" "}
partners completed
</div>
diff --git a/apps/web/lib/swr/use-bounty-stats.ts b/apps/web/lib/swr/use-bounty-stats.ts
new file mode 100644
index 0000000000..216937e385
--- /dev/null
+++ b/apps/web/lib/swr/use-bounty-stats.ts
@@ -0,0 +1,16 @@
+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.ts b/apps/web/lib/swr/use-bounty.ts
index eeb354e35a..d412a1e828 100644
--- a/apps/web/lib/swr/use-bounty.ts
+++ b/apps/web/lib/swr/use-bounty.ts
@@ -1,10 +1,12 @@
import { fetcher } from "@dub/utils";
+import { useParams } from "next/navigation";
import useSWR from "swr";
import { BountyExtendedProps } from "../types";
import useWorkspace from "./use-workspace";
-export default function useBounty({ bountyId }: { bountyId: string }) {
+export default function useBounty() {
const { id: workspaceId } = useWorkspace();
+ const { bountyId } = useParams<{ bountyId: string }>();
const {
data: bounty,
diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.ts
index bfe1398fa7..86c804c76f 100644
--- a/apps/web/lib/zod/schemas/bounties.ts
+++ b/apps/web/lib/zod/schemas/bounties.ts
@@ -54,7 +54,7 @@ export const BountySchemaExtended = BountySchema.extend({
export const BountySubmissionSchema = z.object({
id: z.string(),
description: z.string().nullable(),
- evidenceUrl: z.string(),
+ evidenceUrl: z.string().nullable(),
status: z.nativeEnum(BountySubmissionStatus),
createdAt: z.date(),
updatedAt: z.date(),