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
fix: update people's table
Sidwebworks861a04ed11f3
diff --git a/apps/erp/app/modules/people/people.service.ts b/apps/erp/app/modules/people/people.service.tsindex 4e8eb5d9eb..92fca79b42 100644--- a/apps/erp/app/modules/people/people.service.ts+++ b/apps/erp/app/modules/people/people.service.ts@@ -349,6 +349,38 @@ export async function getPeople(};}+export async function getContacts(+ client: SupabaseClient<Database>,+ companyId: string,+ args: GenericQueryFilters & {+ search: string | null;+ }+) {+ let query = client+ .from("contact")+ .select("*", { count: "exact" })+ .eq("companyId", companyId);++ if (args.search) {+ query = query.or(+ `firstName.ilike.%${args.search}%,lastName.ilike.%${args.search}%,email.ilike.%${args.search}%`+ );+ }++ query = setGenericQueryFilters(query, args, [+ { column: "lastName", ascending: true }+ ]);++ const contacts = await query;++ if (!contacts.data) throw new Error("Failed to get contacts data");++ return {+ count: contacts.count,+ data: contacts.data,+ error: null+ };+}export async function getShift(client: SupabaseClient<Database>,shiftId: stringdiff --git a/apps/erp/app/modules/people/types.ts b/apps/erp/app/modules/people/types.tsindex e987ea4a9c..e020126224 100644--- a/apps/erp/app/modules/people/types.ts+++ b/apps/erp/app/modules/people/types.ts@@ -2,6 +2,7 @@ import type {getAttribute,getAttributeCategories,getAttributeCategory,+ getContacts,getDepartments,getEmployeeJob,getEmployeeSummary,@@ -58,3 +59,7 @@ export type Person = NonNullable<export type Shift = NonNullable<Awaited<ReturnType<typeof getShifts>>["data"]>[number];++export type Contact = NonNullable<+ Awaited<ReturnType<typeof getContacts>>["data"]+>[number];diff --git a/apps/erp/app/modules/people/ui/Contact/ContactTable.tsx b/apps/erp/app/modules/people/ui/Contact/ContactTable.tsxnew file mode 100644index 0000000000..213accff64--- /dev/null+++ b/apps/erp/app/modules/people/ui/Contact/ContactTable.tsx@@ -0,0 +1,82 @@+import type { ColumnDef } from "@tanstack/react-table";+import { memo, useMemo } from "react";+import { LuMail, LuPhone, LuUser } from "react-icons/lu";+import { Table } from "~/components";+import type { Contact } from "../../types";++type ContactTableProps = {+ data: Contact[];+ count: number;+};++const ContactTable = memo(({ data, count }: ContactTableProps) => {+ const columns = useMemo<ColumnDef<Contact>[]>(() => {+ return [+ {+ accessorKey: "firstName",+ header: "First Name",+ cell: (item) => item.getValue(),+ meta: {+ icon: <LuUser />+ }+ },+ {+ accessorKey: "lastName",+ header: "Last Name",+ cell: (item) => item.getValue(),+ meta: {+ icon: <LuUser />+ }+ },+ {+ accessorKey: "email",+ header: "Email",+ cell: (item) => item.getValue(),+ meta: {+ icon: <LuMail />+ }+ },+ {+ accessorKey: "mobilePhone",+ header: "Mobile Phone",+ cell: (item) => item.getValue(),+ meta: {+ icon: <LuPhone />+ }+ },+ {+ accessorKey: "workPhone",+ header: "Work Phone",+ cell: (item) => item.getValue(),+ meta: {+ icon: <LuPhone />+ }+ },+ {+ accessorKey: "homePhone",+ header: "Home Phone",+ cell: (item) => item.getValue(),+ meta: {+ icon: <LuPhone />+ }+ }+ ];+ }, []);++ return (+ <Table<Contact>+ count={count}+ columns={columns}+ data={data}+ defaultColumnPinning={{+ left: ["Select"]+ }}+ title="Contacts"+ table="contact"+ />+ );+});++ContactTable.displayName = "ContactTable";++export default ContactTable;diff --git a/apps/erp/app/modules/people/ui/Contact/index.ts b/apps/erp/app/modules/people/ui/Contact/index.tsnew file mode 100644index 0000000000..eebdaffc53--- /dev/null+++ b/apps/erp/app/modules/people/ui/Contact/index.ts@@ -0,0 +1,3 @@+import ContactTable from "./ContactTable";++export { ContactTable };diff --git a/apps/erp/app/modules/people/ui/usePeopleSubmodules.tsx b/apps/erp/app/modules/people/ui/usePeopleSubmodules.tsxindex bcb68c7eb9..8c163968a1 100644--- a/apps/erp/app/modules/people/ui/usePeopleSubmodules.tsx+++ b/apps/erp/app/modules/people/ui/usePeopleSubmodules.tsx@@ -1,4 +1,5 @@import {+ LuBookUser,LuCalendarClock,LuCalendarHeart,LuListChecks,@@ -14,10 +15,16 @@ const peopleRoutes: RouteGroup[] = [name: "Manage",routes: [{- name: "People",+ name: "Employees",to: path.to.people,icon: <LuUsers />,table: "employee"+ },+ {+ name: "Contacts",+ to: path.to.contact,+ icon: <LuBookUser />,+ table: "contact"}]},diff --git a/apps/erp/app/routes/x+/people+/contact.tsx b/apps/erp/app/routes/x+/people+/contact.tsxnew file mode 100644index 0000000000..1b4c82af1e--- /dev/null+++ b/apps/erp/app/routes/x+/people+/contact.tsx@@ -0,0 +1,55 @@+import { error } from "@carbon/auth";+import { requirePermissions } from "@carbon/auth/auth.server";+import { flash } from "@carbon/auth/session.server";+import { VStack } from "@carbon/react";+import type { LoaderFunctionArgs } from "react-router";+import { Outlet, redirect, useLoaderData } from "react-router";+import { getContacts } from "~/modules/people";+import { ContactTable } from "~/modules/people/ui/Contact";+import { path } from "~/utils/path";+import { getGenericQueryFilters } from "~/utils/query";++export async function loader({ request }: LoaderFunctionArgs) {+ const { client, companyId } = await requirePermissions(request, {+ view: "sales",+ role: "employee"+ });++ const url = new URL(request.url);+ const searchParams = new URLSearchParams(url.search);+ const search = searchParams.get("search");++ const { limit, offset, sorts, filters } =+ getGenericQueryFilters(searchParams);++ const contacts = await getContacts(client, companyId, {+ search,+ limit,+ offset,+ sorts,+ filters+ });++ if (contacts.error) {+ throw redirect(+ path.to.authenticatedRoot,+ await flash(request, error(contacts.error, "Error loading contacts"))+ );+ }++ return {+ contacts: contacts.data ?? [],+ count: contacts.count+ };+}++export default function ResourcesContactRoute() {+ const { contacts, count } = useLoaderData<typeof loader>();++ return (+ <VStack spacing={0} className="h-full">+ <ContactTable data={contacts} count={count ?? 0} />+ <Outlet />+ </VStack>+ );+}diff --git a/apps/erp/app/routes/x+/people+/employee.tsx b/apps/erp/app/routes/x+/people+/employee.tsxnew file mode 100644index 0000000000..c59c2f7d03--- /dev/null+++ b/apps/erp/app/routes/x+/people+/employee.tsx@@ -0,0 +1,80 @@+import { error } from "@carbon/auth";+import { requirePermissions } from "@carbon/auth/auth.server";+import { flash } from "@carbon/auth/session.server";+import { VStack } from "@carbon/react";+import type { LoaderFunctionArgs } from "react-router";+import { Outlet, redirect, useLoaderData } from "react-router";+import { getAttributeCategories, getPeople } from "~/modules/people";+import { PeopleTable } from "~/modules/people/ui/People";+import { getEmployeeTypes } from "~/modules/users";+import { path } from "~/utils/path";+import { getGenericQueryFilters } from "~/utils/query";++export async function loader({ request }: LoaderFunctionArgs) {+ const { client, companyId } = await requirePermissions(request, {+ view: "people",+ role: "employee",+ bypassRls: true+ });++ const url = new URL(request.url);+ const searchParams = new URLSearchParams(url.search);+ const search = searchParams.get("name");++ const { limit, offset, sorts, filters } =+ getGenericQueryFilters(searchParams);++ const [attributeCategories, employeeTypes, people] = await Promise.all([+ getAttributeCategories(client, companyId),+ getEmployeeTypes(client, companyId),+ getPeople(client, companyId, { search, limit, offset, sorts, filters })+ ]);+ if (attributeCategories.error) {+ throw redirect(+ path.to.authenticatedRoot,+ await flash(+ request,+ error(attributeCategories.error, "Error loading attribute categories")+ )+ );+ }+ if (employeeTypes.error) {+ throw redirect(+ path.to.authenticatedRoot,+ await flash(+ request,+ error(employeeTypes.error, "Error loading employee types")+ )+ );+ }+ if (people.error) {+ throw redirect(+ path.to.authenticatedRoot,+ await flash(request, error(people.error, "Error loading people"))+ );+ }++ return {+ attributeCategories: attributeCategories.data,+ employeeTypes: employeeTypes.data ?? [],+ people: people.data?.filter((p) => !p.email?.includes("@carbon.ms")) ?? [],+ count: people.count+ };+}++export default function ResourcesPeopleRoute() {+ const { attributeCategories, count, employeeTypes, people } =+ useLoaderData<typeof loader>();++ return (+ <VStack spacing={0} className="h-full">+ <PeopleTable+ attributeCategories={attributeCategories}+ data={people ?? []}+ count={count ?? 0}+ employeeTypes={employeeTypes}+ />+ <Outlet />+ </VStack>+ );+}diff --git a/apps/erp/app/routes/x+/people+/people.tsx b/apps/erp/app/routes/x+/people+/people.tsxindex c59c2f7d03..eeda2bd035 100644--- a/apps/erp/app/routes/x+/people+/people.tsx+++ b/apps/erp/app/routes/x+/people+/people.tsx@@ -1,80 +1,5 @@-import { error } from "@carbon/auth";-import { requirePermissions } from "@carbon/auth/auth.server";-import { flash } from "@carbon/auth/session.server";-import { VStack } from "@carbon/react";-import type { LoaderFunctionArgs } from "react-router";-import { Outlet, redirect, useLoaderData } from "react-router";-import { getAttributeCategories, getPeople } from "~/modules/people";-import { PeopleTable } from "~/modules/people/ui/People";-import { getEmployeeTypes } from "~/modules/users";-import { path } from "~/utils/path";-import { getGenericQueryFilters } from "~/utils/query";--export async function loader({ request }: LoaderFunctionArgs) {- const { client, companyId } = await requirePermissions(request, {- view: "people",- role: "employee",- bypassRls: true- });-- const url = new URL(request.url);- const searchParams = new URLSearchParams(url.search);- const search = searchParams.get("name");-- const { limit, offset, sorts, filters } =- getGenericQueryFilters(searchParams);-- const [attributeCategories, employeeTypes, people] = await Promise.all([- getAttributeCategories(client, companyId),- getEmployeeTypes(client, companyId),- getPeople(client, companyId, { search, limit, offset, sorts, filters })- ]);- if (attributeCategories.error) {- throw redirect(- path.to.authenticatedRoot,- await flash(- request,- error(attributeCategories.error, "Error loading attribute categories")- )- );- }- if (employeeTypes.error) {- throw redirect(- path.to.authenticatedRoot,- await flash(- request,- error(employeeTypes.error, "Error loading employee types")- )- );- }- if (people.error) {- throw redirect(- path.to.authenticatedRoot,- await flash(request, error(people.error, "Error loading people"))- );- }-- return {- attributeCategories: attributeCategories.data,- employeeTypes: employeeTypes.data ?? [],- people: people.data?.filter((p) => !p.email?.includes("@carbon.ms")) ?? [],- count: people.count- };-}+import { Navigate } from "react-router";export default function ResourcesPeopleRoute() {- const { attributeCategories, count, employeeTypes, people } =- useLoaderData<typeof loader>();-- return (- <VStack spacing={0} className="h-full">- <PeopleTable- attributeCategories={attributeCategories}- data={people ?? []}- count={count ?? 0}- employeeTypes={employeeTypes}- />- <Outlet />- </VStack>- );+ return <Navigate to="../employees" />;}diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.tsindex 887ddfe173..5092592172 100644--- a/apps/erp/app/utils/path.ts+++ b/apps/erp/app/utils/path.ts@@ -1184,7 +1184,8 @@ export const path = {paymentTerm: (id: string) =>generatePath(`${x}/accounting/payment-terms/${id}`),paymentTerms: `${x}/accounting/payment-terms`,- people: `${x}/people/people`,+ people: `${x}/people/employee`,+ contact: `${x}/people/contact`,person: (id: string) => generatePath(`${x}/person/${id}`),personDetails: (id: string) => generatePath(`${x}/person/${id}/details`),personJob: (id: string) => generatePath(`${x}/person/${id}/job`),