The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix BountyProps vs BountyExtendedProps
Steven Teydae735216116
diff --git a/apps/web/app/(ee)/api/bounties/route.ts b/apps/web/app/(ee)/api/bounties/route.tsindex f95ef80e63..5285bef725 100644--- a/apps/web/app/(ee)/api/bounties/route.ts+++ b/apps/web/app/(ee)/api/bounties/route.ts@@ -29,7 +29,7 @@ export const GET = withWorkspace(include: {groups: {select: {- id: true,+ groupId: true,},},_count: {@@ -40,14 +40,15 @@ export const GET = withWorkspace(},});- return NextResponse.json(- bounties.map((bounty) =>- BountySchema.parse({- ...bounty,- submissionsCount: bounty._count.submissions,- }),- ),+ const data = bounties.map((bounty) =>+ BountySchema.parse({+ ...bounty,+ groups: bounty.groups.map(({ groupId }) => ({ id: groupId })),+ submissionsCount: bounty._count.submissions,+ }),);++ return NextResponse.json(data);},{requiredPlan: [diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsxindex d8b29d18d9..a7d9678be0 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx@@ -1,7 +1,11 @@import { isCurrencyAttribute } from "@/lib/api/workflows/utils";import { mutatePrefix } from "@/lib/swr/mutate";import useWorkspace from "@/lib/swr/use-workspace";-import { BountyProps, BountySubmissionRequirement } from "@/lib/types";+import {+ BountyExtendedProps,+ BountyProps,+ BountySubmissionRequirement,+} from "@/lib/types";import { createBountySchema } from "@/lib/zod/schemas/bounties";import { workflowConditionSchema } from "@/lib/zod/schemas/workflows";import {@@ -41,7 +45,7 @@ import { z } from "zod";type BountySheetProps = {setIsOpen: Dispatch<SetStateAction<boolean>>;- bounty?: BountyProps;+ bounty?: BountyExtendedProps;};type FormData = z.infer<typeof createBountySchema>;diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-action-button.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-action-button.tsxindex da1616d7c0..239a580c6e 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-action-button.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-action-button.tsx@@ -2,7 +2,7 @@import { mutatePrefix } from "@/lib/swr/mutate";import useWorkspace from "@/lib/swr/use-workspace";-import { BountyProps } from "@/lib/types";+import { BountyExtendedProps } from "@/lib/types";import { useConfirmModal } from "@/ui/modals/confirm-modal";import { ThreeDots } from "@/ui/shared/icons";import { Button, MenuItem, Popover } from "@dub/ui";@@ -13,7 +13,7 @@ import { toast } from "sonner";import { useBountySheet } from "./add-edit-bounty-sheet";interface BountyActionButtonProps {- bounty: BountyProps;+ bounty: BountyExtendedProps;className?: string;buttonClassName?: string;}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.tsxindex 0e575e3c6f..de1cd62e3b 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,13 +1,40 @@+import usePartnersCount from "@/lib/swr/use-partners-count";import useWorkspace from "@/lib/swr/use-workspace";import { BountyProps } from "@/lib/types";import { BountyThumbnailImage } from "@/ui/partners/bounties/bounty-thumbnail-image";import { Calendar6, Users } from "@dub/ui/icons";import { formatDate, pluralize } from "@dub/utils";import Link from "next/link";-import { BountyActionButton } from "./bounty-action-button";+import { useMemo } from "react";export function BountyCard({ bounty }: { bounty: BountyProps }) {const { slug: workspaceSlug } = useWorkspace();+ const { partnersCount: groupCount } = usePartnersCount<+ | {+ groupId: string;+ _count: number;+ }[]+ | undefined+ >({+ groupBy: "groupId",+ });++ const totalPartnersForBounty = useMemo(() => {+ if (bounty.groups.length === 0) {+ // if no groups set, return all partners+ return groupCount?.reduce((acc, curr) => acc + curr._count, 0) ?? 0;+ }++ return (+ groupCount?.reduce((acc, curr) => {+ if (bounty.groups.some((group) => group.id === curr.groupId)) {+ return acc + curr._count;+ }++ return acc;+ }, 0) ?? 0+ );+ }, [groupCount, bounty.groups]);return (<div className="border-border-subtle hover:border-border-default relative cursor-pointer rounded-xl border bg-white p-5 transition-all hover:shadow-lg">@@ -20,9 +47,9 @@ export function BountyCard({ bounty }: { bounty: BountyProps }) {<BountyThumbnailImage bounty={bounty} /></div>- {bounty.submissionsCount > 0 ? (- <SubmissionsCountBadge count={bounty.submissionsCount} />- ) : null}+ {/* {bounty.pendingSubmissions > 0 ? (+ <SubmissionsCountBadge count={bounty.pendingSubmissions} />+ ) : null} */}</div><div className="flex flex-col gap-1.5">@@ -46,18 +73,24 @@ export function BountyCard({ bounty }: { bounty: BountyProps }) {<div className="text-content-subtle flex items-center gap-2 text-sm font-medium"><Users className="size-3.5" /><div className="h-5">- Applied to {bounty.groups?.length ?? 0}{" "}- {pluralize("group", bounty.groups?.length ?? 0)}+ {bounty.submissionsCount === totalPartnersForBounty ? (+ <>All</>+ ) : (+ <>+ <span className="text-content-default">+ {bounty.submissionsCount}+ </span>{" "}+ of+ </>+ )}{" "}+ <span className="text-content-default">+ {totalPartnersForBounty}+ </span>{" "}+ {pluralize("partner", totalPartnersForBounty)} completed</div></div></div></Link>-- <BountyActionButton- bounty={bounty}- className="absolute right-7 top-7"- buttonClassName="size-7 whitespace-nowrap p-0 hover:bg-neutral-200 active:bg-neutral-300 data-[state=open]:bg-neutral-300"- /></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.tsxindex e347bbd922..fa07cb78ce 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@@ -1,7 +1,7 @@"use client";import useWorkspace from "@/lib/swr/use-workspace";-import { BountyExtendedProps } from "@/lib/types";+import { BountyProps } from "@/lib/types";import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";import { Button } from "@dub/ui";import { fetcher } from "@dub/utils";@@ -18,7 +18,7 @@ export function BountyList() {data: bounties,isLoading,error,- } = useSWR<BountyExtendedProps[]>(+ } = useSWR<BountyProps[]>(workspaceId ? `/api/bounties?workspaceId=${workspaceId}` : null,fetcher,{diff --git a/apps/web/lib/api/bounties/get-bounty-or-throw.ts b/apps/web/lib/api/bounties/get-bounty-or-throw.tsindex ea6f2a8262..63fee011a0 100644--- a/apps/web/lib/api/bounties/get-bounty-or-throw.ts+++ b/apps/web/lib/api/bounties/get-bounty-or-throw.ts@@ -109,7 +109,7 @@ export const getBountyOrThrow = async ({rewardAmount: bounty.rewardAmount,submissionRequirements: bounty.submissionRequirements,performanceCondition,- groups: bounty.groups.filter((group) => group !== null),+ groups: bounty.groups.filter((group) => group !== null) ?? [],partners: Number(bounty.partners),submissions: bounty.submissions,};diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.tsindex a7df70d344..8cf8dd41b3 100644--- a/apps/web/lib/zod/schemas/bounties.ts+++ b/apps/web/lib/zod/schemas/bounties.ts@@ -62,13 +62,12 @@ export const BountySchema = z.object({endsAt: z.date().nullable(),rewardAmount: z.number(),submissionRequirements: submissionRequirementsSchema.nullable(),- performanceCondition: workflowConditionSchema.nullable().default(null),groups: z.array(GroupSchema.pick({ id: true })),submissionsCount: z.number().default(0),});export const BountySchemaExtended = BountySchema.extend({- groups: z.array(GroupSchema.pick({ id: true })).nullable(),+ performanceCondition: workflowConditionSchema.nullable().default(null),partners: z.number().default(0),submissions: z.record(z.nativeEnum(BountySubmissionStatus), z.number()),});