The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add sorting
Tim Wilson06964187b3b3
diff --git a/apps/web/app/(ee)/api/network/programs/route.ts b/apps/web/app/(ee)/api/network/programs/route.tsindex 5e181accbc..4616066e4c 100644--- a/apps/web/app/(ee)/api/network/programs/route.ts+++ b/apps/web/app/(ee)/api/network/programs/route.ts@@ -10,8 +10,16 @@ import { z } from "zod";// GET /api/network/programs - get all available programs in the networkexport const GET = withPartnerProfile(async ({ partner, searchParams }) => {- const { search, category, rewardType, status, page, pageSize } =- getNetworkProgramsQuerySchema.parse(searchParams);+ const {+ search,+ category,+ rewardType,+ status,+ sortBy,+ sortOrder,+ page,+ pageSize,+ } = getNetworkProgramsQuerySchema.parse(searchParams);const programs = await prisma.program.findMany({where: {@@ -82,9 +90,14 @@ export const GET = withPartnerProfile(async ({ partner, searchParams }) => {},categories: true,},- orderBy: {- createdAt: "desc",- },+ orderBy:+ sortBy === "popularity"+ ? {+ partners: {+ _count: "desc",+ },+ }+ : { [sortBy]: sortOrder },skip: (page - 1) * pageSize,take: pageSize,});diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/page-client.tsxindex 938bc30468..dbc6850cf1 100644--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/page-client.tsx+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/page-client.tsx@@ -23,15 +23,22 @@ import {usePagination,useRouterStuff,} from "@dub/ui";-import { OG_AVATAR_URL, cn, fetcher, getPrettyUrl } from "@dub/utils";+import {+ OG_AVATAR_URL,+ cn,+ fetcher,+ getPrettyUrl,+ isClickOnInteractiveChild,+} from "@dub/utils";import * as HoverCard from "@radix-ui/react-hover-card";import { useRouter } from "next/navigation";import useSWR from "swr";import { MarketplaceEmptyState } from "./marketplace-empty-state";+import ProgramSort from "./program-sort";import { useProgramNetworkFilters } from "./use-program-network-filters";export function ProgramMarketplacePageClient() {- const { searchParams, getQueryString, queryParams } = useRouterStuff();+ const { getQueryString } = useRouterStuff();const { data: programsCount, error: countError } = useNetworkProgramsCount();@@ -58,13 +65,16 @@ export function ProgramMarketplacePageClient() {<div className="flex flex-col gap-6"><div><div className="xs:flex-row xs:items-center flex flex-col justify-between gap-4">- <Filter.Select- className="h-9 w-full rounded-lg md:w-fit"- filters={filters}- activeFilters={activeFilters}- onSelect={onSelect}- onRemove={onRemove}- />+ <div className="flex items-center gap-2">+ <Filter.Select+ className="h-9 w-full rounded-lg md:w-fit"+ filters={filters}+ activeFilters={activeFilters}+ onSelect={onSelect}+ onRemove={onRemove}+ />+ <ProgramSort />+ </div><SearchBoxPersistedplaceholder="Search the marketplace..."inputClassName="md:w-[19rem] h-9 rounded-lg"@@ -142,13 +152,21 @@ function ProgramCard({onClick={url? (e) => {+ if (isClickOnInteractiveChild(e)) return;e.metaKey || e.ctrlKey? window.open(url, "_blank"): router.push(url);}: undefined}- onAuxClick={url ? () => window.open(url, "_blank") : undefined}+ onAuxClick={+ url+ ? (e) => {+ if (isClickOnInteractiveChild(e)) return;+ window.open(url, "_blank");+ }+ : undefined+ }><div className="border-border-subtle rounded-xl border bg-white p-6"><div className="flex justify-between gap-4">diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/program-sort.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/program-sort.tsxnew file mode 100644index 0000000000..9882b042c9--- /dev/null+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/program-sort.tsx@@ -0,0 +1,100 @@+import {+ Calendar6,+ IconMenu,+ Popover,+ SortAlphaAscending,+ SortAlphaDescending,+ Star,+ Tick,+ useRouterStuff,+} from "@dub/ui";+import { cn } from "@dub/utils";+import { ChevronDown } from "lucide-react";+import { useState } from "react";++const programSortOptions = [+ {+ icon: Star,+ label: "Most popular",+ value: "popularity",+ order: "desc",+ },+ {+ icon: Calendar6,+ label: "Newest",+ value: "createdAt",+ order: "desc",+ },+ {+ icon: SortAlphaDescending,+ label: "Name A-Z",+ value: "name",+ order: "asc",+ },+ {+ icon: SortAlphaAscending,+ label: "Name Z-A",+ value: "name",+ order: "desc",+ },+] as const;++export default function ProgramSort() {+ const { queryParams, searchParams } = useRouterStuff();++ const [openPopover, setOpenPopover] = useState(false);++ const sortOrder = searchParams.get("sortOrder") === "asc" ? "asc" : "desc";++ const selectedSort =+ programSortOptions.find(+ (s) => s.value === searchParams.get("sortBy") && s.order === sortOrder,+ ) ?? programSortOptions[0];++ return (+ <Popover+ content={+ <div className="w-full p-2 md:w-48">+ {programSortOptions.map(({ label, value, order, icon: Icon }) => (+ <button+ key={value}+ onClick={() => {+ queryParams({+ set: {+ sortBy: value,+ sortOrder: order,+ },+ del: "page",+ });+ setOpenPopover(false);+ }}+ className="flex w-full items-center justify-between space-x-2 rounded-md px-1 py-2 hover:bg-neutral-100 active:bg-neutral-200"+ >+ <IconMenu text={label} icon={<Icon className="size-4" />} />+ {value === selectedSort.value && order === selectedSort.order && (+ <Tick className="size-4" aria-hidden="true" />+ )}+ </button>+ ))}+ </div>+ }+ openPopover={openPopover}+ setOpenPopover={setOpenPopover}+ >+ <button+ onClick={() => setOpenPopover(!openPopover)}+ className={cn(+ "group flex h-9 cursor-pointer appearance-none items-center gap-x-2 truncate rounded-lg border px-3 text-sm outline-none transition-all",+ "border-neutral-200 bg-white text-neutral-900 placeholder-neutral-400",+ "focus-visible:border-neutral-500 data-[state=open]:border-neutral-500 data-[state=open]:ring-4 data-[state=open]:ring-neutral-200",+ )}+ >+ <span className="text-content-emphasis flex-1 overflow-hidden text-ellipsis whitespace-nowrap text-left">+ Sort by{" "}+ <strong className="font-semibold">{selectedSort.label}</strong>+ </span>+ <ChevronDown className="size-4 flex-shrink-0 text-neutral-400 transition-transform duration-75 group-data-[state=open]:rotate-180" />+ </button>+ </Popover>+ );+}diff --git a/apps/web/lib/zod/schemas/program-network.ts b/apps/web/lib/zod/schemas/program-network.tsindex 17ccc6c63b..0772c8559d 100644--- a/apps/web/lib/zod/schemas/program-network.ts+++ b/apps/web/lib/zod/schemas/program-network.ts@@ -39,6 +39,8 @@ export const getNetworkProgramsQuerySchema = zz.nativeEnum(ProgramEnrollmentStatus).nullish(),),search: z.string().optional(),+ sortBy: z.enum(["name", "createdAt", "popularity"]).default("popularity"),+ sortOrder: z.enum(["asc", "desc"]).default("desc"),}).merge(getPaginationQuerySchema({diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.tsindex e5d0929629..7b727d2f67 100644--- a/packages/ui/src/icons/nucleo/index.ts+++ b/packages/ui/src/icons/nucleo/index.ts@@ -207,6 +207,8 @@ export * from "./shop";export * from "./shuffle";export * from "./sitemap";export * from "./sliders";+export * from "./sort-alpha-ascending";+export * from "./sort-alpha-descending";export * from "./sparkle3";export * from "./square-chart";export * from "./square-layout-grid5";diff --git a/packages/ui/src/icons/nucleo/sort-alpha-ascending.tsx b/packages/ui/src/icons/nucleo/sort-alpha-ascending.tsxnew file mode 100644index 0000000000..4929aaa3ec--- /dev/null+++ b/packages/ui/src/icons/nucleo/sort-alpha-ascending.tsx@@ -0,0 +1,62 @@+import { SVGProps } from "react";++export function SortAlphaAscending(props: SVGProps<SVGSVGElement>) {+ return (+ <svg+ height="18"+ width="18"+ viewBox="0 0 18 18"+ xmlns="http://www.w3.org/2000/svg"+ {...props}+ >+ <g fill="currentColor">+ <polyline+ fill="none"+ points="10.5 6.25 13.25 3.5 16 6.25"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ />+ <polyline+ fill="none"+ points="7.357 7.5 5.275 2 4.702 2 2.621 7.5"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ />+ <polyline+ fill="none"+ points="2.832 10 7.145 10 2.832 15.5 7.145 15.5"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="13.25"+ x2="13.25"+ y1="3.5"+ y2="14"+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="3.189"+ x2="6.789"+ y1="6"+ y2="6"+ />+ </g>+ </svg>+ );+}diff --git a/packages/ui/src/icons/nucleo/sort-alpha-descending.tsx b/packages/ui/src/icons/nucleo/sort-alpha-descending.tsxnew file mode 100644index 0000000000..111b2f9fd2--- /dev/null+++ b/packages/ui/src/icons/nucleo/sort-alpha-descending.tsx@@ -0,0 +1,62 @@+import { SVGProps } from "react";++export function SortAlphaDescending(props: SVGProps<SVGSVGElement>) {+ return (+ <svg+ height="18"+ width="18"+ viewBox="0 0 18 18"+ xmlns="http://www.w3.org/2000/svg"+ {...props}+ >+ <g fill="currentColor">+ <polyline+ fill="none"+ points="16 11.25 13.25 14 10.5 11.25"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ />+ <polyline+ fill="none"+ points="7.357 7.5 5.275 2 4.702 2 2.621 7.5"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ />+ <polyline+ fill="none"+ points="2.832 10 7.145 10 2.832 15.5 7.145 15.5"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="13.25"+ x2="13.25"+ y1="14"+ y2="3.5"+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="3.189"+ x2="6.789"+ y1="6"+ y2="6"+ />+ </g>+ </svg>+ );+}