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 filters

Tim Wilsonfb4bfb51d413
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 b986d9c16e..39f2c8dc05 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
@@ -14,9 +14,12 @@ import { PartnerRowItem } from "@/ui/partners/partner-row-item";
import { useRejectBountySubmissionModal } from "@/ui/partners/reject-bounty-submission-modal";
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
import { X } from "@/ui/shared/icons";
+import SimpleDateRangePicker from "@/ui/shared/simple-date-range-picker";
import { UserRowItem } from "@/ui/users/user-row-item";
import {
+ AnimatedSizeContainer,
Button,
+ Filter,
Popover,
ProgressCircle,
StatusBadge,
@@ -43,6 +46,7 @@ import { useEffect, useMemo, useState } from "react";
import { toast } from "sonner";
import useSWR from "swr";
import { BountySubmissionDetailsSheet } from "./bounty-submission-details-sheet";
+import { useBountySubmissionFilters } from "./use-bounty-submission-filters";
export const BOUNTY_SUBMISSION_STATUS_BADGES = {
pending: {
@@ -77,6 +81,15 @@ export function BountySubmissionsTable() {
const sortBy = searchParams.get("sortBy") || "createdAt";
const sortOrder = searchParams.get("sortOrder") === "asc" ? "asc" : "desc";
+ const {
+ filters,
+ activeFilters,
+ onSelect,
+ onRemove,
+ onRemoveAll,
+ isFiltered,
+ } = useBountySubmissionFilters();
+
const {
error,
isLoading,
@@ -117,7 +130,7 @@ export function BountySubmissionsTable() {
}, [searchParams, submissions]);
// Decide the columns to show based on the bounty type
- const columns = useMemo(() => {
+ const showColumns = useMemo(() => {
const columns = ["partner", "group", "createdAt"];
if (!bounty) {
@@ -144,9 +157,8 @@ export function BountySubmissionsTable() {
? WORKFLOW_ATTRIBUTE_LABELS[performanceCondition.attribute]
: "Progress";
- const { table, ...tableProps } = useTable({
- data: submissions || [],
- columns: [
+ const columns = useMemo(
+ () => [
{
id: "partner",
header: "Partner",
@@ -181,7 +193,7 @@ export function BountySubmissionsTable() {
},
},
- ...(columns.includes("status")
+ ...(showColumns.includes("status")
? [
{
id: "status",
@@ -215,7 +227,7 @@ export function BountySubmissionsTable() {
},
// TODO: fix this
- ...(columns.includes("performanceMetrics")
+ ...(showColumns.includes("performanceMetrics")
? [
{
id: metricColumnId,
@@ -264,7 +276,7 @@ export function BountySubmissionsTable() {
]
: []),
- ...(columns.includes("reviewedAt")
+ ...(showColumns.includes("reviewedAt")
? [
{
id: "reviewedAt",
@@ -298,6 +310,20 @@ export function BountySubmissionsTable() {
),
},
],
+ [
+ groups,
+ bounty,
+ showColumns,
+ metricColumnId,
+ metricColumnLabel,
+ performanceCondition,
+ workspaceId,
+ ],
+ );
+
+ const { table, ...tableProps } = useTable({
+ data: submissions || [],
+ columns,
onRowClick: (row) => {
if (!row.original.submission) {
return;
@@ -348,6 +374,43 @@ export function BountySubmissionsTable() {
)}
<div className="flex flex-col gap-6">
+ <div>
+ <div className="flex flex-col gap-3 md:flex-row md:items-center">
+ <Filter.Select
+ className="w-full md:w-fit"
+ filters={filters}
+ activeFilters={activeFilters}
+ onSelect={onSelect}
+ onRemove={onRemove}
+ />
+ <SimpleDateRangePicker
+ className="w-full sm:min-w-[200px] md:w-fit"
+ defaultInterval="all"
+ />
+ </div>
+ <AnimatedSizeContainer height>
+ <div>
+ {activeFilters.length > 0 && (
+ <div className="pt-3">
+ <Filter.List
+ filters={[
+ ...filters,
+ {
+ key: "payoutId",
+ icon: MoneyBill2,
+ label: "Payout",
+ options: [],
+ },
+ ]}
+ activeFilters={activeFilters}
+ onRemove={onRemove}
+ onRemoveAll={onRemoveAll}
+ />
+ </div>
+ )}
+ </div>
+ </AnimatedSizeContainer>
+ </div>
{submissions?.length !== 0 || isLoading ? (
<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 420af63659..11558169f6 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
@@ -8,7 +8,7 @@ export default function Page() {
return (
<PageContent title={<BountyHeaderTitle />}>
<PageWidthWrapper>
- <div className="flex flex-col gap-4">
+ <div className="flex flex-col gap-6">
<BountyInfo />
<BountySubmissionsTable />
</div>
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/use-bounty-submission-filters.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/use-bounty-submission-filters.tsx
new file mode 100644
index 0000000000..0db96463d9
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/use-bounty-submission-filters.tsx
@@ -0,0 +1,121 @@
+import useGroups from "@/lib/swr/use-groups";
+import useWorkspace from "@/lib/swr/use-workspace";
+import { GroupColorCircle } from "@/ui/partners/groups/group-color-circle";
+import { CircleDotted, useRouterStuff } from "@dub/ui";
+import {
+ CircleCheck,
+ CircleHalfDottedCheck,
+ CircleXmark,
+ Users6,
+} from "@dub/ui/icons";
+import { cn } from "@dub/utils";
+import { useCallback, useMemo } from "react";
+import { BOUNTY_SUBMISSION_STATUS_BADGES } from "./bounty-submissions-table";
+
+const statusIcons = {
+ pending: {
+ icon: CircleHalfDottedCheck,
+ className: "text-orange-600",
+ },
+ approved: {
+ icon: CircleCheck,
+ className: "text-green-600",
+ },
+ rejected: {
+ icon: CircleXmark,
+ className: "text-red-600",
+ },
+};
+
+export function useBountySubmissionFilters() {
+ const { slug } = useWorkspace();
+ const { searchParamsObj, queryParams } = useRouterStuff();
+
+ const { groups } = useGroups();
+
+ const filters = useMemo(
+ () => [
+ {
+ key: "status",
+ icon: CircleDotted,
+ label: "Status",
+ options: Object.entries(BOUNTY_SUBMISSION_STATUS_BADGES).map(
+ ([value, { label }]) => {
+ const { icon: Icon, className } = statusIcons[value];
+
+ return {
+ value,
+ label,
+ icon: <Icon className={cn("size-4 bg-transparent", className)} />,
+ };
+ },
+ ),
+ },
+ {
+ key: "groupId",
+ icon: Users6,
+ label: "Partner Group",
+ options:
+ groups?.map((group) => {
+ return {
+ value: group.id,
+ label: group.name,
+ icon: <GroupColorCircle group={group} />,
+ permalink: `/${slug}/program/groups/${group.slug}/rewards`,
+ };
+ }) ?? null,
+ },
+ ],
+ [groups],
+ );
+
+ const activeFilters = useMemo(() => {
+ const { status, groupId } = searchParamsObj;
+
+ return [
+ ...(status ? [{ key: "status", value: status }] : []),
+ ...(groupId ? [{ key: "groupId", value: groupId }] : []),
+ ];
+ }, [searchParamsObj.status, searchParamsObj.groupId]);
+
+ const onSelect = useCallback(
+ (key: string, value: any) =>
+ queryParams({
+ set: {
+ [key]: value,
+ },
+ del: "page",
+ }),
+ [queryParams],
+ );
+
+ const onRemove = useCallback(
+ (key: string) =>
+ queryParams({
+ del: [key, "page"],
+ }),
+ [queryParams],
+ );
+
+ const onRemoveAll = useCallback(
+ () =>
+ queryParams({
+ del: ["status", "groupId"],
+ }),
+ [queryParams],
+ );
+
+ const isFiltered = useMemo(
+ () => activeFilters.length > 0 || searchParamsObj.search,
+ [activeFilters, searchParamsObj.search],
+ );
+
+ return {
+ filters,
+ activeFilters,
+ onSelect,
+ onRemove,
+ onRemoveAll,
+ isFiltered,
+ };
+}
diff --git a/apps/web/lib/swr/use-bounty-submissions-count.ts b/apps/web/lib/swr/use-bounty-submissions-count.ts
index 1ed0710125..bdb68704fa 100644
--- a/apps/web/lib/swr/use-bounty-submissions-count.ts
+++ b/apps/web/lib/swr/use-bounty-submissions-count.ts
@@ -13,7 +13,7 @@ export function useBountySubmissionsCount<T>({
enabled,
}: {
enabled?: boolean;
-}) {
+} = {}) {
const { id: workspaceId } = useWorkspace();
const { getQueryString } = useRouterStuff();