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.

Add submission statuses

Tim Wilsonaca330ae8ece
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.ts
new file mode 100644
index 0000000000..4681cd77b0
--- /dev/null
+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/bounties/route.ts
@@ -0,0 +1,47 @@
+import { getProgramEnrollmentOrThrow } from "@/lib/api/programs/get-program-enrollment-or-throw";
+import { withPartnerProfile } from "@/lib/auth/partner";
+import { BountyWithSubmissionsSchema } from "@/lib/zod/schemas/bounties";
+import { prisma } from "@dub/prisma";
+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 } = await getProgramEnrollmentOrThrow({
+ partnerId: partner.id,
+ programId: params.programId,
+ });
+
+ const bounties = await prisma.bounty.findMany({
+ where: {
+ programId: program.id,
+ startsAt: {
+ lte: new Date(),
+ },
+ OR: [
+ {
+ endsAt: null,
+ },
+ {
+ endsAt: {
+ gt: new Date(),
+ },
+ },
+ ],
+ },
+ include: {
+ submissions: {
+ where: {
+ partnerId: partner.id,
+ status: {
+ not: "rejected",
+ },
+ },
+ },
+ },
+ });
+
+ return NextResponse.json(
+ z.array(BountyWithSubmissionsSchema).parse(bounties),
+ );
+});
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/bounty-card.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/bounty-card.tsx
new file mode 100644
index 0000000000..f950849fca
--- /dev/null
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/bounties/bounty-card.tsx
@@ -0,0 +1,88 @@
+import { BountyWithSubmissionsProps } from "@/lib/types";
+import { BountyThumbnailImage } from "@/ui/partners/bounties/bounty-thumbnail-image";
+import { Button } from "@dub/ui";
+import { CalendarDays, CircleCheckFill } from "@dub/ui/icons";
+import { formatDate } from "@dub/utils";
+
+export function BountyCard({ bounty }: { bounty: BountyWithSubmissionsProps }) {
+ const submission = bounty.submissions?.[0];
+
+ return (
+ <div className="border-border-subtle flex flex-col gap-5 rounded-xl border bg-white p-5">
+ <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>
+ </div>
+
+ <div className="flex flex-col gap-1.5">
+ <h3 className="text-content-emphasis truncate text-sm font-semibold">
+ {bounty.name}
+ </h3>
+
+ <div className="text-content-subtle flex items-center gap-2 text-sm font-medium">
+ <CalendarDays className="size-3.5" />
+ <span>
+ {bounty.endsAt ? (
+ <>
+ Ends
+ {formatDate(bounty.endsAt, { month: "short" })}
+ </>
+ ) : (
+ "No end date"
+ )}
+ </span>
+ </div>
+ </div>
+
+ <div className="flex grow flex-col justify-end">
+ {submission ? (
+ submission.status === "pending" ? (
+ <div className="flex h-7 w-fit items-center gap-1 rounded-lg bg-neutral-100 px-2.5">
+ <CircleCheckFill className="size-3 text-green-600" />
+ <span className="text-content-default text-xs font-medium">
+ Completed
+ {submission.reviewedAt &&
+ formatDate(submission.reviewedAt, { month: "short" })}
+ </span>
+ </div>
+ ) : (
+ <div className="flex h-7 w-fit items-center gap-1 rounded-lg bg-orange-100 px-2.5">
+ <span className="text-xs font-medium text-orange-600">
+ Submitted
+ {submission.createdAt &&
+ formatDate(submission.createdAt, { month: "short" })}
+ </span>
+ </div>
+ )
+ ) : (
+ <Button
+ variant="primary"
+ text="Claim bounty"
+ className="h-7 w-fit rounded-lg px-2.5"
+ onClick={() => {}}
+ />
+ )}
+ </div>
+ </div>
+ );
+}
+
+export const BountyCardSkeleton = () => {
+ return (
+ <div className="border-border-subtle rounded-xl border bg-white p-5">
+ <div className="flex flex-col gap-5">
+ <div className="flex h-[132px] animate-pulse items-center justify-center rounded-lg bg-neutral-100 px-32 py-4" />
+
+ <div className="flex flex-col gap-1.5">
+ <div className="h-5 w-48 animate-pulse rounded-md bg-neutral-200" />
+
+ <div className="flex h-5 items-center space-x-2">
+ <div className="size-4 animate-pulse rounded bg-neutral-200" />
+ <div className="h-4 w-32 animate-pulse rounded bg-neutral-200" />
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+};
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 8d8e0d0855..347fd54fcc 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
@@ -1,37 +1,68 @@
"use client";
+import { BountyWithSubmissionsProps } from "@/lib/types";
import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
import { Heart, Trophy } from "@dub/ui/icons";
+import { fetcher } from "@dub/utils";
+import { useParams } from "next/navigation";
+import useSWR from "swr";
+import { BountyCard, BountyCardSkeleton } from "./bounty-card";
export function BountiesPageClient() {
+ const { programSlug } = useParams();
+
+ const {
+ data: bounties,
+ isLoading,
+ error,
+ } = useSWR<BountyWithSubmissionsProps[]>(
+ `/api/partner-profile/programs/${programSlug}/bounties`,
+ fetcher,
+ {
+ keepPreviousData: true,
+ },
+ );
+
return (
<PageWidthWrapper className="pb-10">
- <AnimatedEmptyState
- title="No bounties to collect"
- description={
- <>
- This program isn't offering any bounties at the moment.{" "}
- <a
- href="https://dub.co/help/article/bounties"
- target="_blank"
- className="hover:text-content-default underline sm:whitespace-nowrap"
- >
- Learn more about bounties
- </a>
- .
- </>
- }
- cardContent={(idx) => {
- const Icon = [Trophy, Heart][idx % 2];
- return (
+ {bounties?.length !== 0 || isLoading ? (
+ <div className="grid grid-cols-1 gap-6 md:grid-cols-2 xl:grid-cols-3">
+ {isLoading
+ ? Array.from({ length: 3 }, (_, index) => (
+ <BountyCardSkeleton key={index} />
+ ))
+ : bounties?.map((bounty) => (
+ <BountyCard key={bounty.id} bounty={bounty} />
+ ))}
+ </div>
+ ) : (
+ <AnimatedEmptyState
+ title="No bounties to collect"
+ description={
<>
- <Icon className="size-4 text-neutral-700" />
- <div className="h-2.5 w-24 min-w-0 rounded-sm bg-neutral-200" />
+ This program isn't offering any bounties at the moment.{" "}
+ <a
+ href="https://dub.co/help/article/bounties"
+ target="_blank"
+ className="hover:text-content-default underline sm:whitespace-nowrap"
+ >
+ Learn more about bounties
+ </a>
+ .
</>
- );
- }}
- />
+ }
+ cardContent={(idx) => {
+ const Icon = [Trophy, Heart][idx % 2];
+ return (
+ <>
+ <Icon className="size-4 text-neutral-700" />
+ <div className="h-2.5 w-24 min-w-0 rounded-sm bg-neutral-200" />
+ </>
+ );
+ }}
+ />
+ )}
</PageWidthWrapper>
);
}
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 0ce927ec18..4754bf8e59 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
@@ -72,41 +72,39 @@ export function BountyList() {
))}
</div>
) : (
- <>
- <AnimatedEmptyState
- title="No bounties active"
- description={
- <>
- This program doesn't have any active bounties.{" "}
- <a
- href="https://dub.co/help/article/bounties"
- target="_blank"
- className="hover:text-content-default underline sm:whitespace-nowrap"
- >
- Learn more about bounties
- </a>
- .
- </>
- }
- cardContent={() => (
- <>
- <Trophy className="size-4 text-neutral-700" />
- <div className="h-2.5 w-24 min-w-0 rounded-sm bg-neutral-200" />
- </>
- )}
- addButton={
- <Button
- text="Create bounty"
- variant="primary"
- onClick={() =>
- setBountySheetState(
- (s) => ({ bountyId: null, open: true }) as any,
- )
- }
- />
- }
- />
- </>
+ <AnimatedEmptyState
+ title="No bounties active"
+ description={
+ <>
+ This program doesn't have any active bounties.{" "}
+ <a
+ href="https://dub.co/help/article/bounties"
+ target="_blank"
+ className="hover:text-content-default underline sm:whitespace-nowrap"
+ >
+ Learn more about bounties
+ </a>
+ .
+ </>
+ }
+ cardContent={() => (
+ <>
+ <Trophy className="size-4 text-neutral-700" />
+ <div className="h-2.5 w-24 min-w-0 rounded-sm bg-neutral-200" />
+ </>
+ )}
+ addButton={
+ <Button
+ text="Create bounty"
+ variant="primary"
+ onClick={() =>
+ setBountySheetState(
+ (s) => ({ bountyId: null, open: true }) as any,
+ )
+ }
+ />
+ }
+ />
)}
</>
);
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 8623c54012..dd0fa5731c 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -28,6 +28,7 @@ import {
BountySchemaExtended,
bountyStatsSchema,
BountySubmissionSchema,
+ BountyWithSubmissionsSchema,
SUBMISSION_REQUIREMENTS,
} from "./zod/schemas/bounties";
import {
@@ -527,6 +528,10 @@ export type BountyProps = z.infer<typeof BountySchema>;
export type BountyExtendedProps = z.infer<typeof BountySchemaExtended>;
+export type BountyWithSubmissionsProps = z.infer<
+ typeof BountyWithSubmissionsSchema
+>;
+
export type BountySubmissionProps = z.infer<typeof BountySubmissionSchema>;
export type BountySubmissionRequirement =
diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.ts
index b708eb457d..8865d9ee12 100644
--- a/apps/web/lib/zod/schemas/bounties.ts
+++ b/apps/web/lib/zod/schemas/bounties.ts
@@ -82,6 +82,16 @@ export const BountySubmissionSchema = z.object({
}).nullable(),
});
+export const BountyWithSubmissionsSchema = BountySchema.extend({
+ submissions: z.array(
+ BountySubmissionSchema.omit({
+ partner: true,
+ commission: true,
+ user: true,
+ }),
+ ),
+});
+
export const BOUNTIES_MAX_PAGE_SIZE = 100;
export const getBountiesQuerySchema = z