Customers Table
A complete customers screen: search, status and plan filters, sortable columns, bulk selection, CSV export, a details panel on row click and an add-customer form.
Built only from Niko Table pieces and shadcn/ui components. Install it, then swap the sample data for your own.
Installation
pnpm dlx shadcn@latest add @niko-table/customers-tablePreview
"use client"
import * as React from "react"import { DataTableRoot } from "@/components/niko-table/core/data-table-root"import { DataTable } from "@/components/niko-table/core/data-table"import { DataTableBody, DataTableEmptyBody, DataTableHeader,} from "@/components/niko-table/core/data-table-structure"import { useDataTable } from "@/components/niko-table/core/data-table-context"import { DataTableColumnHeader } from "@/components/niko-table/components/data-table-column-header"import { DataTableColumnTitle } from "@/components/niko-table/components/data-table-column-title"import { DataTableColumnSortMenu } from "@/components/niko-table/components/data-table-column-sort"import { DataTableToolbarSection } from "@/components/niko-table/components/data-table-toolbar-section"import { DataTableSearchFilter } from "@/components/niko-table/components/data-table-search-filter"import { DataTableFacetedFilter } from "@/components/niko-table/components/data-table-faceted-filter"import { DataTableClearFilter } from "@/components/niko-table/components/data-table-clear-filter"import { DataTableViewMenu } from "@/components/niko-table/components/data-table-view-menu"import { DataTableExportButton } from "@/components/niko-table/components/data-table-export-button"import { DataTableSelectionBar } from "@/components/niko-table/components/data-table-selection-bar"import { DataTablePagination } from "@/components/niko-table/components/data-table-pagination"import { DataTableEmptyDescription, DataTableEmptyFilteredMessage, DataTableEmptyIcon, DataTableEmptyMessage, DataTableEmptyTitle,} from "@/components/niko-table/components/data-table-empty-state"import { DataTableRowMenuScope, RowMenuItem, RowMenuSeparator, useDataTableRow,} from "@/components/niko-table/components/data-table-row-menu"import { DataTableRowContextMenuSlot } from "@/components/niko-table/components/data-table-row-context-menu-slot"import { SYSTEM_COLUMN_IDS } from "@/components/niko-table/lib/constants"import type { DataTableColumnDef } from "@/components/niko-table/types"import { Avatar, AvatarFallback } from "@/components/ui/avatar"import { Badge } from "@/components/ui/badge"import { Button } from "@/components/niko-table/primitives/button"import { Checkbox } from "@/components/niko-table/primitives/checkbox"import { Progress } from "@/components/ui/progress"import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger,} from "@/components/niko-table/primitives/dropdown-menu"import { ArrowDownRight, ArrowUpRight, Globe2, Mail, MoreHorizontal, SearchX, UserPlus, Users,} from "lucide-react"import { cn } from "@/lib/utils"import { customers as sampleCustomers, planOptions, statusOptions, type Customer,} from "./customers-data"import { formatDate, initials, money, statusDot } from "./customers-format"import { CustomerSheet } from "./customer-sheet"import { AddCustomerSheet, type NewCustomer } from "./add-customer-sheet"
/* * Row actions: one small piece per action, each reading its row from context. * `CustomersTable` composes them into ONE fragment that both the "⋯" dropdown * and the right-click menu render. */function ViewCustomerItem({ onView }: { onView: (c: Customer) => void }) { const customer = useDataTableRow<Customer>() return ( <RowMenuItem onClick={() => onView(customer)}>View customer</RowMenuItem> )}
function CopyEmailItem({ onCopied }: { onCopied: (c: Customer) => void }) { const customer = useDataTableRow<Customer>() return ( <RowMenuItem onClick={() => { void navigator.clipboard?.writeText(customer.email) onCopied(customer) }} > Copy email </RowMenuItem> )}
function CancelSubscriptionItem({ onCancel,}: { onCancel: (c: Customer) => void}) { const customer = useDataTableRow<Customer>() return ( <RowMenuItem variant="destructive" disabled={customer.status === "churned"} onClick={() => onCancel(customer)} > Cancel subscription </RowMenuItem> )}
function sortableHeader() { return ( <DataTableColumnHeader> <DataTableColumnTitle /> <DataTableColumnSortMenu /> </DataTableColumnHeader> )}
function useCustomerColumns(rowMenu: React.ReactNode) { return React.useMemo<DataTableColumnDef<Customer>[]>( () => [ { id: SYSTEM_COLUMN_IDS.SELECT, size: 40, enableSorting: false, enableHiding: false, header: ({ table }) => ( <Checkbox // Plain boolean: Radix and Base UI checkboxes take indeterminate differently. checked={table.getIsAllPageRowsSelected()} onCheckedChange={value => table.toggleAllPageRowsSelected(!!value)} aria-label="Select all customers on this page" /> ), cell: ({ row }) => ( <Checkbox checked={row.getIsSelected()} onCheckedChange={value => row.toggleSelected(!!value)} aria-label={`Select ${row.original.name}`} /> ), }, { accessorKey: "name", meta: { label: "Customer" }, header: sortableHeader, cell: ({ row }) => ( <div className="flex items-center gap-3"> <Avatar className="size-8"> <AvatarFallback className="text-xs"> {initials(row.original.name)} </AvatarFallback> </Avatar> <div className="flex min-w-0 flex-col"> <span className="truncate font-medium">{row.original.name}</span> <span className="truncate text-xs text-muted-foreground"> {row.original.email} </span> </div> </div> ), }, { accessorKey: "email", meta: { label: "Email" }, // Searchable and exported, but shown under the name instead. enableHiding: false, }, { accessorKey: "plan", meta: { label: "Plan", options: planOptions }, header: sortableHeader, enableColumnFilter: true, cell: ({ row }) => ( <Badge variant="secondary" className="capitalize"> {row.original.plan} </Badge> ), }, { accessorKey: "status", meta: { label: "Status", options: statusOptions }, header: sortableHeader, enableColumnFilter: true, cell: ({ row }) => ( <span className="flex items-center gap-2 capitalize"> <span className={cn( "size-2 rounded-full", statusDot[row.original.status], )} aria-hidden="true" /> {row.original.status} </span> ), }, { accessorKey: "mrr", meta: { label: "MRR" }, header: sortableHeader, cell: ({ row }) => { const { mrr, mrrChange, status } = row.original if (status !== "active") { return <span className="text-muted-foreground">—</span> } const up = mrrChange >= 0 return ( <div className="flex items-center gap-2 tabular-nums"> <span className="font-medium">{money.format(mrr)}</span> <span className={cn( "flex items-center text-xs", up ? "text-success" : "text-destructive", )} > {up ? ( <ArrowUpRight className="size-3.5" aria-hidden="true" /> ) : ( <ArrowDownRight className="size-3.5" aria-hidden="true" /> )} <span className="sr-only">{up ? "Up" : "Down"}</span> {Math.abs(mrrChange)}% </span> </div> ) }, }, { accessorKey: "seatsUsed", meta: { label: "Seats" }, header: sortableHeader, cell: ({ row }) => { const { seatsUsed, seatsTotal } = row.original return ( <div className="flex w-28 flex-col gap-1"> <span className="text-xs text-muted-foreground tabular-nums"> {seatsUsed} of {seatsTotal} </span> <Progress value={(seatsUsed / seatsTotal) * 100} className="h-1.5" aria-label={`${seatsUsed} of ${seatsTotal} seats used`} /> </div> ) }, }, { accessorKey: "signedUp", meta: { label: "Signed up" }, header: sortableHeader, cell: ({ row }) => ( <span className="text-muted-foreground tabular-nums"> {formatDate(row.original.signedUp)} </span> ), }, { accessorKey: "region", meta: { label: "Region" }, header: sortableHeader, cell: ({ row }) => ( <span className="flex items-center gap-2"> <Globe2 className="size-4 text-muted-foreground" aria-hidden="true" /> {row.original.region} </span> ), }, { id: "actions", size: 56, enableSorting: false, enableHiding: false, cell: ({ row }) => ( <div className="flex justify-end"> <DropdownMenu> <DropdownMenuTrigger asChild> <Button variant="ghost" size="icon" className="size-8" aria-label={`Open actions for ${row.original.name}`} > <MoreHorizontal className="size-4" /> </Button> </DropdownMenuTrigger> <DropdownMenuContent align="end"> <DataTableRowMenuScope row={row.original} surface="dropdown"> {rowMenu} </DataTableRowMenuScope> </DropdownMenuContent> </DropdownMenu> </div> ), }, ], [rowMenu], )}
function CustomersHeader({ onAddCustomer }: { onAddCustomer: () => void }) { const { table } = useDataTable<Customer>() const rows = table.getFilteredRowModel().rows const mrr = rows.reduce((sum, row) => sum + row.original.mrr, 0)
return ( <div className="flex flex-wrap items-start justify-between gap-3"> <div className="flex flex-col gap-0.5"> <h2 className="text-base font-semibold">Customers</h2> <p className="text-sm text-muted-foreground"> {rows.length} customers · {money.format(mrr)} MRR </p> </div> <div className="flex items-center gap-2"> <DataTableExportButton filename="customers" useHeaderLabels /> <Button size="sm" onClick={onAddCustomer}> <UserPlus className="size-4" aria-hidden="true" /> Add customer </Button> </div> </div> )}
function CustomersSelectionBar({ onAction,}: { onAction: (message: string) => void}) { const { table } = useDataTable<Customer>() const selected = table.getFilteredSelectedRowModel().rows return ( <DataTableSelectionBar selectedCount={selected.length} onClear={() => table.resetRowSelection()} > <Button size="sm" variant="outline" onClick={() => { onAction(`Emailed ${selected.length} customers`) table.resetRowSelection() }} > <Mail className="size-4" aria-hidden="true" /> Email selected </Button> </DataTableSelectionBar> )}
export default function CustomersTable() { const [customers, setCustomers] = React.useState(sampleCustomers) const [viewing, setViewing] = React.useState<Customer | null>(null) const [adding, setAdding] = React.useState(false) const [lastAction, setLastAction] = React.useState("")
const cancelSubscription = React.useCallback((customer: Customer) => { const churned = { ...customer, status: "churned" as const, mrr: 0, mrrChange: 0, seatsUsed: 0, } setCustomers(rows => rows.map(row => (row.id === customer.id ? churned : row)), ) setViewing(current => (current?.id === customer.id ? churned : current)) setLastAction(`Cancelled ${customer.name}'s subscription`) }, [])
const addCustomer = React.useCallback((input: NewCustomer) => { setCustomers(rows => [ { ...input, id: `cus_${(rows.length + 1).toString().padStart(3, "0")}`, status: "trial", mrr: 0, mrrChange: 0, seatsUsed: 1, signedUp: new Date(), }, ...rows, ]) setLastAction(`Added ${input.name} on a trial`) }, [])
// The row actions, composed ONCE and mounted in both the "⋯" dropdown and // the right-click menu. const rowMenu = React.useMemo( () => ( <> <ViewCustomerItem onView={setViewing} /> <CopyEmailItem onCopied={c => setLastAction(`Copied ${c.email}`)} /> <RowMenuSeparator /> <CancelSubscriptionItem onCancel={cancelSubscription} /> </> ), [cancelSubscription], ) const columns = useCustomerColumns(rowMenu)
return ( <div className="w-full rounded-xl border bg-card p-4 text-card-foreground shadow-sm"> <DataTableRoot data={customers} columns={columns} getRowId={row => row.id} initialState={{ columnVisibility: { email: false } }} > <div className="flex flex-col gap-4"> <CustomersHeader onAddCustomer={() => setAdding(true)} /> <DataTableToolbarSection className="flex-wrap px-0"> <DataTableSearchFilter placeholder="Search customers..." className="min-w-48 flex-none sm:w-72" /> <DataTableFacetedFilter accessorKey="status" multiple /> <DataTableFacetedFilter accessorKey="plan" multiple /> <DataTableClearFilter /> <div className="ml-auto"> <DataTableViewMenu /> </div> </DataTableToolbarSection> <CustomersSelectionBar onAction={setLastAction} /> <DataTable> <DataTableHeader /> <DataTableBody<Customer> onRowClick={row => setViewing(row)}> <DataTableRowContextMenuSlot> {rowMenu} </DataTableRowContextMenuSlot> <DataTableEmptyBody> <DataTableEmptyMessage> <DataTableEmptyIcon> <Users className="size-12" /> </DataTableEmptyIcon> <DataTableEmptyTitle>No customers yet</DataTableEmptyTitle> <DataTableEmptyDescription> Add your first customer to see them here. </DataTableEmptyDescription> </DataTableEmptyMessage> <DataTableEmptyFilteredMessage> <DataTableEmptyIcon> <SearchX className="size-12" /> </DataTableEmptyIcon> <DataTableEmptyTitle> No matching customers </DataTableEmptyTitle> <DataTableEmptyDescription> Try a different search or clear the filters. </DataTableEmptyDescription> </DataTableEmptyFilteredMessage> </DataTableEmptyBody> </DataTableBody> </DataTable> <DataTablePagination /> {lastAction && ( <p className="text-xs text-muted-foreground" aria-live="polite"> {lastAction} </p> )} </div> </DataTableRoot> <CustomerSheet customer={viewing} onOpenChange={open => !open && setViewing(null)} onCancelSubscription={cancelSubscription} /> <AddCustomerSheet open={adding} onOpenChange={setAdding} onAdd={addCustomer} /> </div> )}"use client"
import * as React from "react"import { Avatar, AvatarFallback } from "@/components/ui/avatar"import { Badge } from "@/components/ui/badge"import { Button } from "@/components/niko-table/primitives/button"import { Progress } from "@/components/ui/progress"import { Sheet, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle,} from "@/components/niko-table/primitives/sheet"import { Check, Copy, Mail } from "lucide-react"import { cn } from "@/lib/utils"import type { Customer } from "./customers-data"import { formatDate, initials, money, statusDot } from "./customers-format"
function DetailRow({ label, children,}: { label: string children: React.ReactNode}) { return ( <div className="flex items-center justify-between gap-4 py-2 text-sm"> <dt className="text-muted-foreground">{label}</dt> <dd className="text-right">{children}</dd> </div> )}
function DetailSection({ title, children,}: { title: string children: React.ReactNode}) { return ( <section className="flex flex-col gap-1"> <h3 className="text-xs font-medium tracking-wide text-muted-foreground uppercase"> {title} </h3> <dl className="divide-y">{children}</dl> </section> )}
function CopyButton({ value, label }: { value: string; label: string }) { const [copied, setCopied] = React.useState(false) return ( <Button variant="ghost" size="icon" className="size-6" aria-label={label} onClick={() => { void navigator.clipboard?.writeText(value) setCopied(true) setTimeout(() => setCopied(false), 1500) }} > {copied ? <Check className="size-3.5" /> : <Copy className="size-3.5" />} </Button> )}
/** Side panel with one customer's details. Opens on row click. */export function CustomerSheet({ customer, onOpenChange, onCancelSubscription,}: { customer: Customer | null onOpenChange: (open: boolean) => void onCancelSubscription: (customer: Customer) => void}) { return ( <Sheet open={customer !== null} onOpenChange={onOpenChange}> <SheetContent className="flex w-full flex-col gap-0 sm:max-w-md"> {customer && ( <> <SheetHeader className="flex-row items-center gap-3 border-b"> <Avatar className="size-10"> <AvatarFallback>{initials(customer.name)}</AvatarFallback> </Avatar> <div className="flex min-w-0 flex-col"> <SheetTitle className="truncate">{customer.name}</SheetTitle> <SheetDescription className="flex items-center gap-2 capitalize"> <span className={cn( "size-2 rounded-full", statusDot[customer.status], )} aria-hidden="true" /> {customer.status} · {customer.plan} plan </SheetDescription> </div> </SheetHeader>
<div className="flex flex-1 flex-col gap-6 overflow-y-auto p-4"> <DetailSection title="Subscription"> <DetailRow label="Plan"> <Badge variant="secondary" className="capitalize"> {customer.plan} </Badge> </DetailRow> <DetailRow label="MRR"> <span className="tabular-nums"> {customer.status === "active" ? `${money.format(customer.mrr)} (${customer.mrrChange >= 0 ? "+" : ""}${customer.mrrChange}%)` : "—"} </span> </DetailRow> <DetailRow label="Seats"> <div className="flex w-36 flex-col items-end gap-1"> <span className="tabular-nums"> {customer.seatsUsed} of {customer.seatsTotal} used </span> <Progress value={(customer.seatsUsed / customer.seatsTotal) * 100} className="h-1.5" aria-label="Seats used" /> </div> </DetailRow> <DetailRow label="Customer since"> {formatDate(customer.signedUp)} </DetailRow> </DetailSection>
<DetailSection title="Account"> <DetailRow label="Customer ID"> <span className="flex items-center gap-1 font-mono text-xs"> {customer.id} <CopyButton value={customer.id} label="Copy customer ID" /> </span> </DetailRow> <DetailRow label="Email">{customer.email}</DetailRow> <DetailRow label="Region">{customer.region}</DetailRow> </DetailSection> </div>
<SheetFooter className="flex-row justify-between border-t"> <Button variant="outline" size="sm" disabled={customer.status === "churned"} onClick={() => onCancelSubscription(customer)} > Cancel subscription </Button> <Button size="sm" asChild> <a href={`mailto:${customer.email}`}> <Mail className="size-4" aria-hidden="true" /> Email </a> </Button> </SheetFooter> </> )} </SheetContent> </Sheet> )}"use client"
import * as React from "react"import { Button } from "@/components/niko-table/primitives/button"import { Field, FieldDescription, FieldGroup, FieldLabel,} from "@/components/ui/field"import { Input } from "@/components/ui/input"import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue,} from "@/components/niko-table/primitives/select"import { Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle,} from "@/components/niko-table/primitives/sheet"import { UserPlus } from "lucide-react"import { planOptions, regions, type Customer, type CustomerPlan,} from "./customers-data"
export type NewCustomer = Pick< Customer, "name" | "email" | "plan" | "seatsTotal" | "region">
/** Form in a side panel. New customers start on a trial. */export function AddCustomerSheet({ open, onOpenChange, onAdd,}: { open: boolean onOpenChange: (open: boolean) => void onAdd: (customer: NewCustomer) => void}) { const [plan, setPlan] = React.useState<CustomerPlan>("starter") const [region, setRegion] = React.useState<string>(regions[0])
function handleSubmit(event: React.FormEvent<HTMLFormElement>) { event.preventDefault() const form = new FormData(event.currentTarget) onAdd({ name: String(form.get("name")).trim(), email: String(form.get("email")).trim(), seatsTotal: Math.max(1, Number(form.get("seats")) || 1), plan, region, }) event.currentTarget.reset() onOpenChange(false) }
return ( <Sheet open={open} onOpenChange={onOpenChange}> <SheetContent className="flex w-full flex-col gap-0 sm:max-w-md"> <SheetHeader className="border-b"> <SheetTitle>Add customer</SheetTitle> <SheetDescription> They start on a 14-day trial of the plan you pick. </SheetDescription> </SheetHeader> <form id="add-customer" onSubmit={handleSubmit} className="flex-1 overflow-y-auto p-4" > <FieldGroup> <Field> <FieldLabel htmlFor="customer-name">Name</FieldLabel> <Input id="customer-name" name="name" required autoComplete="off" placeholder="Jordan Park" /> </Field> <Field> <FieldLabel htmlFor="customer-email">Work email</FieldLabel> <Input id="customer-email" name="email" type="email" required autoComplete="off" /> <FieldDescription> Invoices and trial reminders go here. </FieldDescription> </Field> <div className="grid grid-cols-2 gap-4"> <Field> <FieldLabel htmlFor="customer-plan">Plan</FieldLabel> <Select value={plan} onValueChange={(value: string | null) => value && setPlan(value as CustomerPlan) } > <SelectTrigger id="customer-plan" className="w-full"> <SelectValue /> </SelectTrigger> <SelectContent> {planOptions.map(option => ( <SelectItem key={option.value} value={option.value}> {option.label} </SelectItem> ))} </SelectContent> </Select> </Field> <Field> <FieldLabel htmlFor="customer-seats">Seats</FieldLabel> <Input id="customer-seats" name="seats" type="number" min={1} defaultValue={5} required /> </Field> </div> <Field> <FieldLabel htmlFor="customer-region">Region</FieldLabel> <Select value={region} onValueChange={(value: string | null) => value && setRegion(value) } > <SelectTrigger id="customer-region" className="w-full"> <SelectValue /> </SelectTrigger> <SelectContent> {regions.map(option => ( <SelectItem key={option} value={option}> {option} </SelectItem> ))} </SelectContent> </Select> </Field> </FieldGroup> </form> <SheetFooter className="flex-row justify-end border-t"> <SheetClose asChild> <Button variant="outline" size="sm"> Cancel </Button> </SheetClose> <Button type="submit" form="add-customer" size="sm"> <UserPlus className="size-4" aria-hidden="true" /> Add customer </Button> </SheetFooter> </SheetContent> </Sheet> )}import type { CustomerStatus } from "./customers-data"
export const money = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", maximumFractionDigits: 0,})
const shortDate = new Intl.DateTimeFormat("en-US", { month: "short", day: "numeric", year: "numeric", timeZone: "UTC",})
export function formatDate(date: Date) { return shortDate.format(date)}
export const statusDot: Record<CustomerStatus, string> = { active: "bg-success", trial: "bg-warning", churned: "bg-muted-foreground",}
export function initials(name: string) { return name .split(" ") .filter(Boolean) .map(part => part[0]?.toUpperCase()) .slice(0, 2) .join("")}export type CustomerStatus = "active" | "trial" | "churned"export type CustomerPlan = "starter" | "growth" | "scale"
export type Customer = { id: string name: string email: string plan: CustomerPlan status: CustomerStatus /** Monthly recurring revenue in USD (0 while on trial or after churn). */ mrr: number /** MRR change over the last 30 days, in percent. */ mrrChange: number seatsUsed: number seatsTotal: number signedUp: Date region: string}
export const statusOptions = [ { label: "Active", value: "active" }, { label: "Trial", value: "trial" }, { label: "Churned", value: "churned" },]
export const planOptions = [ { label: "Starter", value: "starter" }, { label: "Growth", value: "growth" }, { label: "Scale", value: "scale" },]
/** * Sample data, generated rather than hand-written. A seeded PRNG * (mulberry32) keeps it random-looking but identical on every render, so the * server and client agree and screenshots/tests stay stable. Swap * `customers` for your own rows. */function seededRandom(seed: number) { let a = seed return () => { a = (a + 0x6d2b79f5) | 0 let t = Math.imul(a ^ (a >>> 15), 1 | a) t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t return ((t ^ (t >>> 14)) >>> 0) / 4294967296 }}
const firstNames = [ "Ada", "Bruno", "Cleo", "Dev", "Elif", "Finn", "Gia", "Hugo", "Ines", "Jonah", "Kai", "Lena", "Milo", "Nadia", "Omar", "Pia", "Quinn", "Rosa", "Sami", "Tess", "Uma", "Viktor", "Wren", "Yara",]const lastNames = [ "Abbott", "Barros", "Castell", "Dimitrov", "Eze", "Falk", "Gupta", "Holm", "Ito", "Jansen", "Kaur", "Lindgren", "Moreau", "Novak", "Osei", "Petrov", "Quist", "Reyes", "Sato", "Tan", "Varga", "Weber", "Young", "Zhou",]export const regions = [ "North America", "South America", "Europe", "Africa", "Middle East", "Asia Pacific",]const plans: { plan: CustomerPlan; seats: number[]; perSeat: number }[] = [ { plan: "starter", seats: [3, 5], perSeat: 12 }, { plan: "growth", seats: [10, 25], perSeat: 18 }, { plan: "scale", seats: [50, 100, 250], perSeat: 24 },]
function generateCustomers(count: number, seed: number): Customer[] { const random = seededRandom(seed) const pick = <T>(items: readonly T[]) => items[Math.floor(random() * items.length)] // Fixed reference date so the generated "signed up" dates never shift. const now = Date.UTC(2026, 10, 1)
return Array.from({ length: count }, (_, i) => { const first = pick(firstNames) const last = pick(lastNames) const { plan, seats, perSeat } = pick(plans) const seatsTotal = pick(seats) const roll = random() const status: CustomerStatus = roll < 0.7 ? "active" : roll < 0.88 ? "trial" : "churned" const seatsUsed = status === "churned" ? 0 : Math.max(1, Math.round(seatsTotal * (0.35 + random() * 0.65))) const mrr = status === "active" ? seatsTotal * perSeat : 0 const mrrChange = status === "active" ? Math.round((random() * 30 - 8) * 10) / 10 : 0
return { id: `cus_${(i + 1).toString().padStart(3, "0")}`, name: `${first} ${last}`, email: `${first}.${last}`.toLowerCase() + "@example.com", plan, status, mrr, mrrChange, seatsUsed, seatsTotal, signedUp: new Date(now - Math.floor(random() * 720) * 86_400_000), region: pick(regions), } })}
export const customers = generateCustomers(36, 20261126)Usage
The files land in components/customers-table/. Render the block anywhere:
import CustomersTable from "@/components/customers-table/customers-table"
export default function Page() { return <CustomersTable />}Then replace the generated rows in customers-data.ts with your own data, or load it from your API and pass it in.