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 bounty submissions table and update types

Kiran K35c7f2917cc0
diff --git a/apps/web/app/(ee)/api/bounties/[bountyId]/submissions/route.ts b/apps/web/app/(ee)/api/bounties/[bountyId]/submissions/route.ts
index fb36c2ff90..e25d4a0d3c 100644
--- a/apps/web/app/(ee)/api/bounties/[bountyId]/submissions/route.ts
+++ b/apps/web/app/(ee)/api/bounties/[bountyId]/submissions/route.ts
@@ -28,6 +28,9 @@ export const GET = withWorkspace(async ({ workspace, params }) => {
partner: true,
commission: true,
},
+ orderBy: {
+ createdAt: "desc",
+ },
});
return NextResponse.json(z.array(BountySubmissionSchema).parse(submissions));
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx
new file mode 100644
index 0000000000..76ac77014c
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx
@@ -0,0 +1,137 @@
+"use client";
+
+import useWorkspace from "@/lib/swr/use-workspace";
+import { BountySubmissionProps } from "@/lib/types";
+import { PartnerRowItem } from "@/ui/partners/partner-row-item";
+import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
+import { UserRowItem } from "@/ui/users/user-row-item";
+import { StatusBadge, Table, usePagination, useTable } from "@dub/ui";
+import { User } from "@dub/ui/icons";
+import { fetcher, formatDate } from "@dub/utils";
+import { useParams } from "next/navigation";
+import useSWR from "swr";
+
+export const BOUNTY_SUBMISSION_STATUS_BADGES = {
+ pending: {
+ label: "Pending",
+ variant: "new",
+ },
+ approved: {
+ label: "Approved",
+ variant: "success",
+ },
+ rejected: {
+ label: "Rejected",
+ variant: "error",
+ },
+} as const;
+
+export function BountySubmissionsTable() {
+ const { id: workspaceId } = useWorkspace();
+ const { bountyId } = useParams<{ bountyId: string }>();
+ const { pagination, setPagination } = usePagination();
+
+ const {
+ error,
+ isLoading,
+ data: submissions,
+ } = useSWR<BountySubmissionProps[]>(
+ workspaceId && bountyId
+ ? `/api/bounties/${bountyId}/submissions?${new URLSearchParams({
+ workspaceId,
+ }).toString()}`
+ : null,
+ fetcher,
+ {
+ keepPreviousData: true,
+ dedupingInterval: 30000,
+ },
+ );
+
+ const { table, ...tableProps } = useTable({
+ data: submissions || [],
+ columns: [
+ {
+ id: "partner",
+ header: "Partner",
+ minSize: 250,
+ cell: ({ row }) => {
+ return (
+ <PartnerRowItem
+ partner={row.original.partner}
+ showPermalink={false}
+ />
+ );
+ },
+ },
+ {
+ id: "status",
+ header: "Status",
+ cell: ({ row }) => {
+ const badge = BOUNTY_SUBMISSION_STATUS_BADGES[row.original.status];
+
+ return badge ? (
+ <StatusBadge icon={null} variant={badge.variant}>
+ {badge.label}
+ </StatusBadge>
+ ) : (
+ "-"
+ );
+ },
+ },
+ {
+ id: "createdAt",
+ header: "Submitted",
+ accessorFn: (d) => formatDate(d.createdAt, { month: "short" }),
+ },
+ {
+ id: "reviewedAt",
+ header: "Reviewed",
+ cell: ({ row }) => {
+ return row.original.reviewedAt ? (
+ <UserRowItem
+ user={row.original.user!}
+ date={row.original.reviewedAt}
+ label={
+ row.original.status === "approved"
+ ? "Approved at"
+ : "Rejected at"
+ }
+ />
+ ) : (
+ "-"
+ );
+ },
+ },
+ ],
+ pagination,
+ onPaginationChange: setPagination,
+ thClassName: "border-l-0",
+ tdClassName: "border-l-0",
+ resourceName: (p) => `submission${p ? "s" : ""}`,
+ rowCount: submissions?.length || 0,
+ loading: isLoading,
+ error: error ? "Failed to load bounty submissions" : undefined,
+ });
+
+ return (
+ <>
+ <div className="flex flex-col gap-6">
+ {submissions && submissions.length > 0 ? (
+ <Table {...tableProps} table={table} />
+ ) : (
+ <AnimatedEmptyState
+ title="No submissions found"
+ description="No submissions have been made for this bounty yet."
+ cardContent={() => (
+ <>
+ <User className="size-4 text-neutral-700" />
+ <div className="h-2.5 w-24 min-w-0 rounded-sm bg-neutral-200" />
+ </>
+ )}
+ />
+ )}
+ </div>
+ </>
+ );
+}
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index d81f424de2..700b57b2c8 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -22,6 +22,7 @@ import {
FOLDER_WORKSPACE_ACCESS,
} from "./folder/constants";
import { WEBHOOK_TRIGGER_DESCRIPTIONS } from "./webhook/constants";
+import { BountySchema, BountySubmissionSchema } from "./zod/schemas/bounties";
import {
clickEventResponseSchema,
clickEventSchemaTB,
@@ -87,7 +88,6 @@ import {
WebhookSchema,
} from "./zod/schemas/webhooks";
import { workspacePreferencesSchema } from "./zod/schemas/workspace-preferences";
-import { BountySchema } from "./zod/schemas/bounties";
export type LinkProps = Link;
@@ -516,3 +516,5 @@ export type ClickEventTB = z.infer<typeof clickEventSchemaTB>;
export type LeadEventTB = z.infer<typeof leadEventSchemaTB>;
export type BountyProps = z.infer<typeof BountySchema>;
+
+export type BountySubmissionProps = z.infer<typeof BountySubmissionSchema>;
diff --git a/apps/web/ui/users/user-row-item.tsx b/apps/web/ui/users/user-row-item.tsx
new file mode 100644
index 0000000000..6e742f0a28
--- /dev/null
+++ b/apps/web/ui/users/user-row-item.tsx
@@ -0,0 +1,66 @@
+import { UserSchema } from "@/lib/zod/schemas/users";
+import { Tooltip } from "@dub/ui";
+import { formatDate, formatDateTime, OG_AVATAR_URL } from "@dub/utils";
+import { z } from "zod";
+
+type UserProps = z.infer<typeof UserSchema>;
+
+export function UserRowItem({
+ user,
+ date,
+ label,
+}: {
+ user: Pick<UserProps, "id" | "name" | "image">;
+ date: Date;
+ label: string;
+}) {
+ const image = user.image || `${OG_AVATAR_URL}${user.name}`;
+ const name = user.name ?? user.id;
+
+ return (
+ <Tooltip
+ content={
+ <div className="flex flex-col gap-1 p-2.5">
+ {user && (
+ <div className="flex flex-col gap-2">
+ <img
+ src={image}
+ alt={name}
+ className="size-6 shrink-0 rounded-full"
+ />
+ <p className="text-sm font-medium">{user.name}</p>
+ </div>
+ )}
+
+ <div className="text-xs text-neutral-500">
+ {label}{" "}
+ <span className="font-medium text-neutral-700">
+ {formatDateTime(date, {
+ month: "short",
+ day: "numeric",
+ year: "numeric",
+ hour: "numeric",
+ minute: "numeric",
+ })}
+ </span>
+ </div>
+ </div>
+ }
+ >
+ <div className="flex items-center gap-2">
+ {user && (
+ <img
+ src={image}
+ alt={name}
+ className="size-5 shrink-0 rounded-full"
+ />
+ )}
+
+ {formatDate(date, {
+ month: "short",
+ year: undefined,
+ })}
+ </div>
+ </Tooltip>
+ );
+}
diff --git a/packages/prisma/schema/bounty.prisma b/packages/prisma/schema/bounty.prisma
index 0a14d94384..ae4ffc1101 100644
--- a/packages/prisma/schema/bounty.prisma
+++ b/packages/prisma/schema/bounty.prisma
@@ -7,7 +7,6 @@ enum BountySubmissionStatus {
pending
approved
rejected
- paid
}
// TODO: