The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Sort+filter
Tim Wilson7971421eaffd
diff --git a/apps/web/app/api/customers/route.ts b/apps/web/app/api/customers/route.tsindex d83ad2bbd6..9676471393 100644--- a/apps/web/app/api/customers/route.ts+++ b/apps/web/app/api/customers/route.ts@@ -46,10 +46,13 @@ export const GET = withWorkspace(email,externalId,search,+ country,includeExpandedFields,page,pageSize,customerIds,+ sortBy,+ sortOrder,} = getCustomersQuerySchemaExtended.parse(searchParams);const customers = (await prisma.customer.findMany({@@ -64,18 +67,21 @@ export const GET = withWorkspace(? { email }: externalId? { externalId }- : search- ? {+ : {+ ...(search && {OR: [{ email: { startsWith: search } },{ externalId: { startsWith: search } },{ name: { startsWith: search } },],- }- : {}),+ }),+ ...(country && {+ country,+ }),+ }),},orderBy: {- createdAt: "desc",+ [sortBy]: sortOrder,},skip: (page - 1) * pageSize,take: pageSize,diff --git a/apps/web/lib/zod/schemas/customers.ts b/apps/web/lib/zod/schemas/customers.tsindex 884077ab63..0c9d260b05 100644--- a/apps/web/lib/zod/schemas/customers.ts+++ b/apps/web/lib/zod/schemas/customers.ts@@ -26,11 +26,30 @@ export const getCustomersQuerySchema = z.describe("A search query to filter customers by email, externalId, or name. If `email` or `externalId` is provided, this will be ignored.",),+ country: z+ .string()+ .optional()+ .describe(+ "A filter on the list based on the customer's `country` field.",+ ),includeExpandedFields: booleanQuerySchema.optional().describe("Whether to include expanded fields on the customer (`link`, `partner`, `discount`).",),++ sortBy: z+ .enum(["createdAt"])+ .optional()+ .default("createdAt")+ .describe(+ "The field to sort the customers by. The default is `createdAt`.",+ ),+ sortOrder: z+ .enum(["asc", "desc"])+ .optional()+ .default("desc")+ .describe("The sort order. The default is `desc`."),}).merge(getPaginationQuerySchema({ pageSize: CUSTOMERS_MAX_PAGE_SIZE }));diff --git a/apps/web/ui/customers/customer-table/customer-table.tsx b/apps/web/ui/customers/customer-table/customer-table.tsxindex 60adecb939..fa03781105 100644--- a/apps/web/ui/customers/customer-table/customer-table.tsx+++ b/apps/web/ui/customers/customer-table/customer-table.tsx@@ -19,7 +19,7 @@ import {useRouterStuff,useTable,} from "@dub/ui";-import { Dots, Users } from "@dub/ui/icons";+import { Dots, User } from "@dub/ui/icons";import { COUNTRIES, fetcher, formatDate, getPrettyUrl } from "@dub/utils";import { Row } from "@tanstack/react-table";import { Command } from "cmdk";@@ -235,7 +235,7 @@ export function CustomerTable() {}cardContent={() => (<>- <Users className="size-4 text-neutral-700" />+ <User className="size-4 text-neutral-700" /><div className="h-2.5 w-24 min-w-0 rounded-sm bg-neutral-200" /></>)}