Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
refactor: new table/filter components for customer accounts table
Brad Barbin65d76c334b0a
diff --git a/apps/carbon/app/modules/users/ui/Customers/CustomerAccountsTable.tsx b/apps/carbon/app/modules/users/ui/Customers/CustomerAccountsTable.tsxindex 732fd09463..9346cc2ad4 100644--- a/apps/carbon/app/modules/users/ui/Customers/CustomerAccountsTable.tsx+++ b/apps/carbon/app/modules/users/ui/Customers/CustomerAccountsTable.tsx@@ -1,4 +1,5 @@import {+ Checkbox,Enumerable,HStack,MenuIcon,@@ -9,16 +10,18 @@ import type { ColumnDef } from "@tanstack/react-table";import { memo, useCallback, useMemo, useState } from "react";import { BsEnvelope } from "react-icons/bs";import { FaBan } from "react-icons/fa";-import { Avatar, Table } from "~/components";-import { usePermissions } from "~/hooks";+import { Avatar, New, TableNew } from "~/components";+import { usePermissions, useUrlParams } from "~/hooks";import type { Customer } from "~/modules/users";import { DeactivateUsersModal, ResendInviteModal } from "~/modules/users";+import { useCustomers } from "~/stores";+import type { ListItem } from "~/types";import { path } from "~/utils/path";type CustomerAccountsTableProps = {data: Customer[];count: number;- isEditable?: boolean;+ customerTypes: ListItem[];};const defaultColumnVisibility = {@@ -27,13 +30,16 @@ const defaultColumnVisibility = {};const CustomerAccountsTable = memo(- ({ data, count, isEditable = false }: CustomerAccountsTableProps) => {+ ({ data, count, customerTypes }: CustomerAccountsTableProps) => {const permissions = usePermissions();-+ const [params] = useUrlParams();const [selectedUserIds, setSelectedUserIds] = useState<string[]>([]);const deactivateCustomerModal = useDisclosure();const resendInviteModal = useDisclosure();+ const [customers] = useCustomers();++ const canEdit = permissions.can("update", "users");const rows = useMemo(() =>@@ -96,16 +102,55 @@ const CustomerAccountsTable = memo(accessorKey: "customer.name",header: "Customer",cell: (item) => item.getValue(),+ meta: {+ filter: {+ type: "static",+ options: customers.map(({ name }) => ({+ value: name,+ label: name,+ })),+ },+ },},{+ accessorKey: "customer.customerType.name",header: "Customer Type",cell: ({ row }) => (// @ts-ignore<Enumerable value={row.original.customer?.customerType?.name} />),+ meta: {+ filter: {+ type: "static",+ options: customerTypes.map((type) => ({+ value: type.name,+ label: <Enumerable value={type.name} />,+ })),+ },+ },+ },+ {+ accessorKey: "user.active",+ header: "Active",+ cell: (item) => <Checkbox isChecked={item.getValue<boolean>()} />,+ meta: {+ filter: {+ type: "static",+ options: [+ {+ value: "true",+ label: "Active",+ },+ {+ value: "false",+ label: "Inactive",+ },+ ],+ },+ },},];- }, []);+ }, [customerTypes, customers]);const actions = useMemo(() => {return [@@ -181,17 +226,20 @@ const CustomerAccountsTable = memo(return (<>- <Table<(typeof rows)[number]>+ <TableNew<(typeof rows)[number]>actions={actions}count={count}columns={columns}data={rows}defaultColumnVisibility={defaultColumnVisibility}+ primaryAction={+ permissions.can("create", "users") && (+ <New label="Employee" to={`new?${params.toString()}`} />+ )+ }renderContextMenu={renderContextMenu}withColumnOrdering- withFilters- withPagination- withSelectableRows={isEditable}+ withSelectableRows={canEdit}/>{deactivateCustomerModal.isOpen && (diff --git a/apps/carbon/app/modules/users/ui/Customers/CustomerAccountsTableFilters.tsx b/apps/carbon/app/modules/users/ui/Customers/CustomerAccountsTableFilters.tsxdeleted file mode 100644index ef8cf10356..0000000000--- a/apps/carbon/app/modules/users/ui/Customers/CustomerAccountsTableFilters.tsx+++ /dev/null@@ -1,69 +0,0 @@-import { Button, HStack } from "@carbon/react";-import { Link } from "@remix-run/react";-import { IoMdAdd } from "react-icons/io";-import { Combobox, Select } from "~/components";-import { TableFilters } from "~/components/Layout";-import { DebouncedInput } from "~/components/Search";-import { usePermissions, useUrlParams } from "~/hooks";-import type { ListItem } from "~/types";--type CustomerAccountsTableFiltersProps = {- customerTypes: ListItem[];-};--const CustomerAccountsTableFilters = ({- customerTypes,-}: CustomerAccountsTableFiltersProps) => {- const [params, setParams] = useUrlParams();- const permissions = usePermissions();-- const customerTypeOptions =- customerTypes?.map<{ value: string; label: string }>((type) => ({- value: type.id!,- label: type.name!,- })) ?? [];-- return (- <TableFilters>- <HStack>- <DebouncedInput param="name" size="sm" placeholder="Search" />- <Combobox- size="sm"- value={params.get("type") ?? ""}- isClearable- options={customerTypeOptions}- onChange={(selected) => {- setParams({ type: selected });- }}- placeholder="Customer Type"- />- <Select- size="sm"- value={params.get("active") === "false" ? "false" : "true"}- options={[- {- value: "true",- label: "Active",- },- {- value: "false",- label: "Inactive",- },- ]}- onChange={(selected) => {- setParams({ active: selected });- }}- />- </HStack>- <HStack>- {permissions.can("create", "users") && (- <Button asChild leftIcon={<IoMdAdd />}>- <Link to={`new?${params.toString()}`}>New Customer</Link>- </Button>- )}- </HStack>- </TableFilters>- );-};--export default CustomerAccountsTableFilters;diff --git a/apps/carbon/app/modules/users/ui/Customers/index.ts b/apps/carbon/app/modules/users/ui/Customers/index.tsindex aa276fb31c..e1ab5be334 100644--- a/apps/carbon/app/modules/users/ui/Customers/index.ts+++ b/apps/carbon/app/modules/users/ui/Customers/index.ts@@ -1,9 +1,4 @@import CreateCustomerModal from "./CreateCustomerModal";import CustomerAccountsTable from "./CustomerAccountsTable";-import CustomerAccountsTableFilters from "./CustomerAccountsTableFilters";-export {- CreateCustomerModal,- CustomerAccountsTable,- CustomerAccountsTableFilters,-};+export { CreateCustomerModal, CustomerAccountsTable };diff --git a/apps/carbon/app/modules/users/ui/Employees/index.ts b/apps/carbon/app/modules/users/ui/Employees/index.tsindex e93d3d9501..bb65d7eeed 100644--- a/apps/carbon/app/modules/users/ui/Employees/index.ts+++ b/apps/carbon/app/modules/users/ui/Employees/index.ts@@ -1,13 +1,11 @@-import CreateEmployeeModal from "./CreateEmployeeModal";import BulkEditPermissionsForm from "./BulkEditPermissionsForm";+import CreateEmployeeModal from "./CreateEmployeeModal";import EmployeePermissionsForm from "./EmployeePermissionsForm";import EmployeesTable from "./EmployeesTable";-import EmployeesTableFilters from "./EmployeesTableFilters";export {- CreateEmployeeModal,BulkEditPermissionsForm,+ CreateEmployeeModal,EmployeePermissionsForm,EmployeesTable,- EmployeesTableFilters,};diff --git a/apps/carbon/app/modules/users/users.service.ts b/apps/carbon/app/modules/users/users.service.tsindex 5ffd3d1664..73fc72dbb5 100644--- a/apps/carbon/app/modules/users/users.service.ts+++ b/apps/carbon/app/modules/users/users.service.ts@@ -22,10 +22,9 @@ export async function getCustomers(client: SupabaseClient<Database>,args: GenericQueryFilters & {search: string | null;- type: string | null;- active: boolean | null;}) {+ // TODO: this breaks on customerType filters -- convert to viewlet query = client.from("customerAccount").select(`user!inner(id, fullName, firstName, lastName, email, avatarUrl, active),customer!inner(name, customerType!left(name))`,@@ -36,14 +35,6 @@ export async function getCustomers(query = query.ilike("user.fullName", `%${args.search}%`);}- if (args.type) {- query = query.eq("customer.customerTypeId", args.type);- }-- if (args.active !== null) {- query = query.eq("user.active", args.active);- }-query = setGenericQueryFilters(query, args, [{ column: "user(lastName)", ascending: true },]);@@ -170,6 +161,7 @@ export async function getSuppliers(active: boolean | null;}) {+ // TODO: this breaks on supplierType filters -- convert to viewlet query = client.from("supplierAccount").select(`user!inner(id, fullName, firstName, lastName, email, avatarUrl, active),supplier!inner(name, supplierType!left(name))`,diff --git a/apps/carbon/app/routes/x+/users+/customers.tsx b/apps/carbon/app/routes/x+/users+/customers.tsxindex 3c3eab03e3..6a110a1d14 100644--- a/apps/carbon/app/routes/x+/users+/customers.tsx+++ b/apps/carbon/app/routes/x+/users+/customers.tsx@@ -2,13 +2,8 @@ import { VStack } from "@carbon/react";import type { LoaderFunctionArgs } from "@remix-run/node";import { json, redirect } from "@remix-run/node";import { Outlet, useLoaderData } from "@remix-run/react";-import { usePermissions } from "~/hooks";import { getCustomerTypes } from "~/modules/sales";-import {- CustomerAccountsTable,- CustomerAccountsTableFilters,- getCustomers,-} from "~/modules/users";+import { CustomerAccountsTable, getCustomers } from "~/modules/users";import { requirePermissions } from "~/services/auth";import { flash } from "~/services/session.server";import type { Handle } from "~/utils/handle";@@ -28,15 +23,13 @@ export async function loader({ request }: LoaderFunctionArgs) {const url = new URL(request.url);const searchParams = new URLSearchParams(url.search);- const name = searchParams.get("name");- const type = searchParams.get("type");- const active = searchParams.get("active") !== "false";+ const search = searchParams.get("search");const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);const [customers, customerTypes] = await Promise.all([- getCustomers(client, { name, type, active, limit, offset, sorts, filters }),+ getCustomers(client, { search, limit, offset, sorts, filters }),getCustomerTypes(client),]);@@ -56,15 +49,13 @@ export async function loader({ request }: LoaderFunctionArgs) {export default function UsersCustomersRoute() {const { count, customers, customerTypes } = useLoaderData<typeof loader>();- const permissions = usePermissions();return (<VStack spacing={0} className="h-full">- <CustomerAccountsTableFilters customerTypes={customerTypes} /><CustomerAccountsTabledata={customers}count={count}- isEditable={permissions.can("update", "users")}+ customerTypes={customerTypes}/><Outlet /></VStack>