* feat(schema): add auth, people, and financial tables Add users, organizations, teams, groups, and project members tables. Extend customers/vendors with netsuite fields. Add netsuite schema for invoices, bills, payments, and credit memos. Include all migrations, seeds, new UI primitives, and config updates. * feat(auth): add WorkOS authentication system Add login, signup, password reset, email verification, and invitation flows via WorkOS AuthKit. Includes auth middleware, permission helpers, dev mode fallbacks, and auth page components. * feat(people): add people management system Add user, team, group, and organization management with CRUD actions, dashboard pages, invite dialog, user drawer, and role-based filtering. Includes WorkOS invitation integration. * feat(netsuite): add NetSuite integration and financials Add bidirectional NetSuite REST API integration with OAuth 2.0, rate limiting, sync engine, and conflict resolution. Includes invoices, vendor bills, payments, credit memos CRUD, customer/vendor management pages, and financial dashboard with tabbed views. * ci: retrigger build * fix: add mobile-list-card dependency for people-table --------- Co-authored-by: Nicholai <nicholaivogelfilms@gmail.com>
375 lines
11 KiB
TypeScript
Executable File
375 lines
11 KiB
TypeScript
Executable File
"use client"
|
|
|
|
import * as React from "react"
|
|
import { IconDotsVertical } from "@tabler/icons-react"
|
|
import {
|
|
flexRender,
|
|
getCoreRowModel,
|
|
getFilteredRowModel,
|
|
getPaginationRowModel,
|
|
getSortedRowModel,
|
|
useReactTable,
|
|
type ColumnDef,
|
|
type ColumnFiltersState,
|
|
type SortingState,
|
|
} from "@tanstack/react-table"
|
|
|
|
import type { Customer } from "@/db/schema"
|
|
import { useIsMobile } from "@/hooks/use-mobile"
|
|
import { Badge } from "@/components/ui/badge"
|
|
import { Button } from "@/components/ui/button"
|
|
import { Checkbox } from "@/components/ui/checkbox"
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
} from "@/components/ui/dropdown-menu"
|
|
import { Input } from "@/components/ui/input"
|
|
import {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from "@/components/ui/select"
|
|
import {
|
|
Table,
|
|
TableBody,
|
|
TableCell,
|
|
TableHead,
|
|
TableHeader,
|
|
TableRow,
|
|
} from "@/components/ui/table"
|
|
|
|
interface CustomersTableProps {
|
|
customers: Customer[]
|
|
onEdit?: (customer: Customer) => void
|
|
onDelete?: (id: string) => void
|
|
}
|
|
|
|
export function CustomersTable({
|
|
customers,
|
|
onEdit,
|
|
onDelete,
|
|
}: CustomersTableProps) {
|
|
const isMobile = useIsMobile()
|
|
const [sorting, setSorting] = React.useState<SortingState>([
|
|
{ id: "name", desc: false },
|
|
])
|
|
const [columnFilters, setColumnFilters] =
|
|
React.useState<ColumnFiltersState>([])
|
|
const [rowSelection, setRowSelection] = React.useState({})
|
|
|
|
const sortKey = React.useMemo(() => {
|
|
if (!sorting.length) return "name-asc"
|
|
const s = sorting[0]
|
|
if (s.id === "name") return s.desc ? "name-desc" : "name-asc"
|
|
if (s.id === "createdAt") return s.desc ? "newest" : "oldest"
|
|
return "name-asc"
|
|
}, [sorting])
|
|
|
|
const handleSort = (value: string) => {
|
|
switch (value) {
|
|
case "name-asc":
|
|
setSorting([{ id: "name", desc: false }])
|
|
break
|
|
case "name-desc":
|
|
setSorting([{ id: "name", desc: true }])
|
|
break
|
|
case "newest":
|
|
setSorting([{ id: "createdAt", desc: true }])
|
|
break
|
|
case "oldest":
|
|
setSorting([{ id: "createdAt", desc: false }])
|
|
break
|
|
}
|
|
}
|
|
|
|
const columns: ColumnDef<Customer>[] = [
|
|
{
|
|
id: "select",
|
|
header: ({ table }) => (
|
|
<Checkbox
|
|
checked={table.getIsAllPageRowsSelected()}
|
|
onCheckedChange={(v) => table.toggleAllPageRowsSelected(!!v)}
|
|
aria-label="select all"
|
|
/>
|
|
),
|
|
cell: ({ row }) => (
|
|
<Checkbox
|
|
checked={row.getIsSelected()}
|
|
onCheckedChange={(v) => row.toggleSelected(!!v)}
|
|
aria-label="select row"
|
|
/>
|
|
),
|
|
enableSorting: false,
|
|
enableHiding: false,
|
|
},
|
|
{
|
|
accessorKey: "name",
|
|
header: "Name",
|
|
cell: ({ row }) => (
|
|
<span className="font-medium">{row.getValue("name")}</span>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "company",
|
|
header: "Company",
|
|
cell: ({ row }) =>
|
|
row.getValue("company") || (
|
|
<span className="text-muted-foreground">-</span>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "email",
|
|
header: "Email",
|
|
cell: ({ row }) =>
|
|
row.getValue("email") || (
|
|
<span className="text-muted-foreground">-</span>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "phone",
|
|
header: "Phone",
|
|
cell: ({ row }) =>
|
|
row.getValue("phone") || (
|
|
<span className="text-muted-foreground">-</span>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "netsuiteId",
|
|
header: "NetSuite ID",
|
|
cell: ({ row }) => {
|
|
const nsId = row.getValue("netsuiteId") as string | null
|
|
if (!nsId) return <span className="text-muted-foreground">-</span>
|
|
return <Badge variant="outline">{nsId}</Badge>
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "createdAt",
|
|
header: "Created",
|
|
cell: ({ row }) => {
|
|
const d = row.getValue("createdAt") as string
|
|
return new Date(d).toLocaleDateString()
|
|
},
|
|
},
|
|
{
|
|
id: "actions",
|
|
cell: ({ row }) => {
|
|
const customer = row.original
|
|
return (
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button variant="ghost" className="size-8 p-0">
|
|
<span className="sr-only">open menu</span>
|
|
<IconDotsVertical className="size-4" />
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end">
|
|
<DropdownMenuItem onClick={() => onEdit?.(customer)}>
|
|
Edit
|
|
</DropdownMenuItem>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuItem
|
|
className="text-destructive"
|
|
onClick={() => onDelete?.(customer.id)}
|
|
>
|
|
Delete
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
)
|
|
},
|
|
},
|
|
]
|
|
|
|
const table = useReactTable({
|
|
data: customers,
|
|
columns,
|
|
onSortingChange: setSorting,
|
|
onColumnFiltersChange: setColumnFilters,
|
|
getCoreRowModel: getCoreRowModel(),
|
|
getPaginationRowModel: getPaginationRowModel(),
|
|
getSortedRowModel: getSortedRowModel(),
|
|
getFilteredRowModel: getFilteredRowModel(),
|
|
onRowSelectionChange: setRowSelection,
|
|
state: { sorting, columnFilters, rowSelection },
|
|
})
|
|
|
|
const emptyState = (
|
|
<div className="rounded-md border border-dashed p-8 text-center">
|
|
<p className="text-muted-foreground">No customers yet</p>
|
|
<p className="text-sm text-muted-foreground/70 mt-1">
|
|
Add your first customer to start tracking contacts and invoices.
|
|
</p>
|
|
</div>
|
|
)
|
|
|
|
if (isMobile) {
|
|
const rows = table.getRowModel().rows
|
|
return (
|
|
<div className="space-y-3">
|
|
<Input
|
|
placeholder="Search customers..."
|
|
value={
|
|
(table.getColumn("name")?.getFilterValue() as string) ?? ""
|
|
}
|
|
onChange={(e) =>
|
|
table.getColumn("name")?.setFilterValue(e.target.value)
|
|
}
|
|
className="w-full"
|
|
/>
|
|
<Select value={sortKey} onValueChange={handleSort}>
|
|
<SelectTrigger className="w-[150px]">
|
|
<SelectValue />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem value="name-asc">Name A-Z</SelectItem>
|
|
<SelectItem value="name-desc">Name Z-A</SelectItem>
|
|
<SelectItem value="newest">Newest</SelectItem>
|
|
<SelectItem value="oldest">Oldest</SelectItem>
|
|
</SelectContent>
|
|
</Select>
|
|
{rows.length ? (
|
|
<div className="rounded-md border divide-y">
|
|
{rows.map((row) => {
|
|
const c = row.original
|
|
return (
|
|
<div
|
|
key={row.id}
|
|
className="flex items-center gap-3 px-3 py-2.5"
|
|
>
|
|
<div className="flex-1 min-w-0">
|
|
<p className="text-sm font-medium truncate">
|
|
{c.name}
|
|
</p>
|
|
<p className="text-xs text-muted-foreground truncate">
|
|
{[c.company, c.email, c.phone]
|
|
.filter(Boolean)
|
|
.join(" \u00b7 ") || "No contact info"}
|
|
</p>
|
|
</div>
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className="size-8 shrink-0"
|
|
>
|
|
<IconDotsVertical className="size-4" />
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end">
|
|
<DropdownMenuItem onClick={() => onEdit?.(c)}>
|
|
Edit
|
|
</DropdownMenuItem>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuItem
|
|
className="text-destructive"
|
|
onClick={() => onDelete?.(c.id)}
|
|
>
|
|
Delete
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</div>
|
|
)
|
|
})}
|
|
</div>
|
|
) : (
|
|
emptyState
|
|
)}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<div className="space-y-4">
|
|
<Input
|
|
placeholder="Search customers..."
|
|
value={(table.getColumn("name")?.getFilterValue() as string) ?? ""}
|
|
onChange={(e) =>
|
|
table.getColumn("name")?.setFilterValue(e.target.value)
|
|
}
|
|
className="w-full sm:max-w-sm"
|
|
/>
|
|
<div className="rounded-md border overflow-hidden">
|
|
<div className="overflow-x-auto">
|
|
<Table>
|
|
<TableHeader>
|
|
{table.getHeaderGroups().map((headerGroup) => (
|
|
<TableRow key={headerGroup.id}>
|
|
{headerGroup.headers.map((header) => (
|
|
<TableHead key={header.id} className="whitespace-nowrap">
|
|
{header.isPlaceholder
|
|
? null
|
|
: flexRender(
|
|
header.column.columnDef.header,
|
|
header.getContext()
|
|
)}
|
|
</TableHead>
|
|
))}
|
|
</TableRow>
|
|
))}
|
|
</TableHeader>
|
|
<TableBody>
|
|
{table.getRowModel().rows?.length ? (
|
|
table.getRowModel().rows.map((row) => (
|
|
<TableRow
|
|
key={row.id}
|
|
data-state={row.getIsSelected() && "selected"}
|
|
>
|
|
{row.getVisibleCells().map((cell) => (
|
|
<TableCell key={cell.id} className="whitespace-nowrap">
|
|
{flexRender(
|
|
cell.column.columnDef.cell,
|
|
cell.getContext()
|
|
)}
|
|
</TableCell>
|
|
))}
|
|
</TableRow>
|
|
))
|
|
) : (
|
|
<TableRow>
|
|
<TableCell
|
|
colSpan={columns.length}
|
|
className="h-24 text-center"
|
|
>
|
|
No customers found
|
|
</TableCell>
|
|
</TableRow>
|
|
)}
|
|
</TableBody>
|
|
</Table>
|
|
</div>
|
|
</div>
|
|
<div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
|
<div className="text-sm text-muted-foreground">
|
|
{table.getFilteredSelectedRowModel().rows.length} of{" "}
|
|
{table.getFilteredRowModel().rows.length} row(s) selected
|
|
</div>
|
|
<div className="flex items-center space-x-2">
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
onClick={() => table.previousPage()}
|
|
disabled={!table.getCanPreviousPage()}
|
|
>
|
|
Previous
|
|
</Button>
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
onClick={() => table.nextPage()}
|
|
disabled={!table.getCanNextPage()}
|
|
>
|
|
Next
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|