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 submission details sheet and refactor components

Kiran K16e7a17b5737
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-details.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-info.tsx
similarity index 98%
rename from apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-details.tsx
rename to apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-info.tsx
index 23a41f3014..a77d9632bb 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-details.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-info.tsx
@@ -5,7 +5,7 @@ import { formatDate } from "@dub/utils";
import { CalendarDays, Trophy, Users } from "lucide-react";
import { useParams } from "next/navigation";
-export function BountyDetails() {
+export function BountyInfo() {
const { bountyId } = useParams<{ bountyId: string }>();
const { bounty } = useBounty({ bountyId });
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx
new file mode 100644
index 0000000000..a2cab4aa8a
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx
@@ -0,0 +1,97 @@
+"use client";
+
+import { BountySubmissionProps } from "@/lib/types";
+import { X } from "@/ui/shared/icons";
+import { Button, Sheet, useRouterStuff } from "@dub/ui";
+import { OG_AVATAR_URL } from "@dub/utils";
+import { Dispatch, SetStateAction, useState } from "react";
+
+type BountySubmissionDetailsSheetProps = {
+ submission: BountySubmissionProps;
+ setIsOpen: Dispatch<SetStateAction<boolean>>;
+};
+
+function BountySubmissionDetailsSheetContent({ submission }: BountySubmissionDetailsSheetProps) {
+ return (
+ <div className="flex h-full flex-col">
+ <div className="sticky top-0 z-10 border-b border-neutral-200 bg-white">
+ <div className="flex h-16 items-center justify-between px-6 py-4">
+ <Sheet.Title className="text-lg font-semibold">
+ Bounty submission details
+ </Sheet.Title>
+ <Sheet.Close asChild>
+ <Button
+ variant="outline"
+ icon={<X className="size-5" />}
+ className="h-auto w-fit p-1"
+ />
+ </Sheet.Close>
+ </div>
+ </div>
+
+ <div className="flex grow flex-col">
+ <div className="border-b border-neutral-200 bg-neutral-50 p-6">
+ {/* Basic partner info */}
+ <div className="flex items-start justify-between gap-6">
+ <div>
+ <div className="relative w-fit">
+ <img
+ src={submission.partner.image || `${OG_AVATAR_URL}${submission.partner.name}`}
+ alt={submission.partner.name}
+ className="size-12 rounded-full"
+ />
+ </div>
+ <div className="mt-4 flex items-start gap-2">
+ <span className="text-lg font-semibold leading-tight text-neutral-900">
+ {submission.partner.name}
+ </span>
+ </div>
+ {submission.partner.email && (
+ <span className="text-sm text-neutral-500">
+ {submission.partner.email}
+ </span>
+ )}
+ </div>
+ </div>
+ </div>
+
+ <div className="grow overflow-y-auto p-6">
+ {/* Content will be added later */}
+ </div>
+ </div>
+ </div>
+ );
+}
+
+
+
+export function BountySubmissionDetailsSheet({
+ isOpen,
+ ...rest
+}: BountySubmissionDetailsSheetProps & {
+ isOpen: boolean;
+}) {
+ const { queryParams } = useRouterStuff();
+ return (
+ <Sheet
+ open={isOpen}
+ onOpenChange={rest.setIsOpen}
+ onClose={() => queryParams({ del: "submissionId", scroll: false })}
+ >
+ <BountySubmissionDetailsSheetContent {...rest} />
+ </Sheet>
+ );
+}
+
+export function useBountySubmissionDetailsSheet(
+ props: { nested?: boolean } & Omit<BountySubmissionDetailsSheetProps, "setIsOpen">,
+) {
+ const [isOpen, setIsOpen] = useState(false);
+
+ return {
+ BountySubmissionDetailsSheet: (
+ <BountySubmissionDetailsSheet setIsOpen={setIsOpen} isOpen={isOpen} {...props} />
+ ),
+ setShowBountySubmissionDetailsSheet: setIsOpen,
+ };
+}
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
index 76ac77014c..c228684dc3 100644
--- 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
@@ -3,12 +3,20 @@
import useWorkspace from "@/lib/swr/use-workspace";
import { BountySubmissionProps } from "@/lib/types";
import { PartnerRowItem } from "@/ui/partners/partner-row-item";
+import { BountySubmissionDetailsSheet } from "./bounty-submission-details-sheet";
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 {
+ StatusBadge,
+ Table,
+ usePagination,
+ useRouterStuff,
+ useTable,
+} from "@dub/ui";
import { User } from "@dub/ui/icons";
import { fetcher, formatDate } from "@dub/utils";
import { useParams } from "next/navigation";
+import { useEffect, useState } from "react";
import useSWR from "swr";
export const BOUNTY_SUBMISSION_STATUS_BADGES = {
@@ -30,6 +38,7 @@ export function BountySubmissionsTable() {
const { id: workspaceId } = useWorkspace();
const { bountyId } = useParams<{ bountyId: string }>();
const { pagination, setPagination } = usePagination();
+ const { queryParams, searchParams } = useRouterStuff();
const {
error,
@@ -48,6 +57,29 @@ export function BountySubmissionsTable() {
},
);
+ const sortBy = searchParams.get("sortBy") || "saleAmount";
+ const sortOrder = searchParams.get("sortOrder") === "asc" ? "asc" : "desc";
+
+ const [detailsSheetState, setDetailsSheetState] = useState<
+ | { open: false; submission: BountySubmissionProps | null }
+ | { open: true; submission: BountySubmissionProps }
+ >({ open: false, submission: null });
+
+ // Open the details sheet if submissionId is set in params
+ useEffect(() => {
+ const submissionId = searchParams.get("submissionId");
+
+ if (!submissionId) {
+ setDetailsSheetState({ open: false, submission: null });
+ }
+
+ const submission = submissions?.find((s) => s.id === submissionId);
+
+ if (submission) {
+ setDetailsSheetState({ open: true, submission });
+ }
+ }, [searchParams]);
+
const { table, ...tableProps } = useTable({
data: submissions || [],
columns: [
@@ -104,6 +136,26 @@ export function BountySubmissionsTable() {
},
},
],
+ onRowClick: (row) => {
+ queryParams({
+ set: {
+ submissionId: row.original.id,
+ },
+ scroll: false,
+ });
+ },
+ sortableColumns: ["createdAt"],
+ sortBy,
+ sortOrder,
+ onSortChange: ({ sortBy, sortOrder }) =>
+ queryParams({
+ set: {
+ ...(sortBy && { sortBy }),
+ ...(sortOrder && { sortOrder }),
+ },
+ del: "page",
+ scroll: false,
+ }),
pagination,
onPaginationChange: setPagination,
thClassName: "border-l-0",
@@ -116,6 +168,16 @@ export function BountySubmissionsTable() {
return (
<>
+ {detailsSheetState.submission && (
+ <BountySubmissionDetailsSheet
+ isOpen={detailsSheetState.open}
+ setIsOpen={(open) =>
+ setDetailsSheetState((s) => ({ ...s, open }) as any)
+ }
+ submission={detailsSheetState.submission}
+ />
+ )}
+
<div className="flex flex-col gap-6">
{submissions && submissions.length > 0 ? (
<Table {...tableProps} table={table} />
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/page.tsx
index 8f41756daa..9d5c5b3a9a 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/page.tsx
@@ -2,7 +2,7 @@ import { PageContent } from "@/ui/layout/page-content";
import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";
import { ChevronRight } from "@dub/ui";
import { Trophy } from "lucide-react";
-import { BountyDetails } from "./bounty-details";
+import { BountyInfo } from "./bounty-info";
import { BountySubmissionsTable } from "./bounty-submissions-table";
export default function Page() {
@@ -24,7 +24,7 @@ export default function Page() {
>
<PageWidthWrapper>
<div className="flex flex-col gap-4">
- <BountyDetails />
+ <BountyInfo />
<BountySubmissionsTable />
</div>
</PageWidthWrapper>
diff --git a/apps/web/lib/api/create-id.ts b/apps/web/lib/api/create-id.ts
index a0642c5ee5..bfb765f2c1 100644
--- a/apps/web/lib/api/create-id.ts
+++ b/apps/web/lib/api/create-id.ts
@@ -28,7 +28,8 @@ const prefixes = [
"dub_embed_",
"audit_",
"import_",
- "bounty_",
+ "bounty_", // TODO: Finalize this
+ "bounty_submission_", // TODO: Finalize this
"wf_",
] as const;