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
feat: custom fields for customer location form
Brad Barbin3f41f504a2c2
diff --git a/apps/carbon/app/modules/purchasing/purchasing.service.ts b/apps/carbon/app/modules/purchasing/purchasing.service.tsindex aeec18e82b..4aa97cf1a3 100644--- a/apps/carbon/app/modules/purchasing/purchasing.service.ts+++ b/apps/carbon/app/modules/purchasing/purchasing.service.ts@@ -279,7 +279,7 @@ export async function getSupplierContact(return client.from("supplierContact").select(- "id, contact(id, firstName, lastName, email, mobilePhone, homePhone, workPhone, fax, title, addressLine1, addressLine2, city, state, postalCode, country(id, name), birthday, notes)"+ "*, contact(id, firstName, lastName, email, mobilePhone, homePhone, workPhone, fax, title, addressLine1, addressLine2, city, state, postalCode, country(id, name), birthday, notes)").eq("id", supplierContactId).single();@@ -292,7 +292,7 @@ export async function getSupplierContacts(return client.from("supplierContact").select(- "id, contact(id, firstName, lastName, email, mobilePhone, homePhone, workPhone, fax, title, addressLine1, addressLine2, city, state, postalCode, country(id, name), birthday, notes), user(id, active)"+ "*, contact(id, firstName, lastName, email, mobilePhone, homePhone, workPhone, fax, title, addressLine1, addressLine2, city, state, postalCode, country(id, name), birthday, notes), user(id, active)").eq("supplierId", supplierId);}@@ -304,7 +304,7 @@ export async function getSupplierLocations(return client.from("supplierLocation").select(- "id, address(id, addressLine1, addressLine2, city, state, country(id, name), postalCode)"+ "*, address(id, addressLine1, addressLine2, city, state, country(id, name), postalCode)").eq("supplierId", supplierId);}@@ -316,7 +316,7 @@ export async function getSupplierLocation(return client.from("supplierLocation").select(- "id, address(id, addressLine1, addressLine2, city, state, country(id, name), postalCode)"+ "*, address(id, addressLine1, addressLine2, city, state, country(id, name), postalCode)").eq("id", supplierContactId).single();@@ -638,24 +638,7 @@ export async function updateSupplierContact(client: SupabaseClient<Database>,supplierContact: {contactId: string;- contact: {- firstName?: string;- lastName?: string;- email: string;- mobilePhone?: string;- homePhone?: string;- workPhone?: string;- fax?: string;- title?: string;- addressLine1?: string;- addressLine2?: string;- city?: string;- state?: string;- // countryId: string;- postalCode?: string;- birthday?: string;- notes?: string;- };+ contact: z.infer<typeof supplierContactValidator>;}) {return clientdiff --git a/apps/carbon/app/modules/purchasing/ui/Suppliers/SuppliersTable.tsx b/apps/carbon/app/modules/purchasing/ui/Suppliers/SuppliersTable.tsxindex 882af82aeb..b96ccb60a9 100644--- a/apps/carbon/app/modules/purchasing/ui/Suppliers/SuppliersTable.tsx+++ b/apps/carbon/app/modules/purchasing/ui/Suppliers/SuppliersTable.tsx@@ -1,4 +1,10 @@-import { Button, Hyperlink, MenuIcon, MenuItem } from "@carbon/react";+import {+ Button,+ Enumerable,+ Hyperlink,+ MenuIcon,+ MenuItem,+} from "@carbon/react";import { useNavigate } from "@remix-run/react";import type { ColumnDef } from "@tanstack/react-table";import { memo, useMemo } from "react";@@ -31,12 +37,12 @@ const SuppliersTable = memo(({ data, count }: SuppliersTableProps) => {{accessorKey: "type",header: "Supplier Type",- cell: (item) => item.getValue(),+ cell: (item) => <Enumerable value={item.getValue<string>()} />,},{accessorKey: "status",header: "Supplier Status",- cell: (item) => item.getValue(),+ cell: (item) => <Enumerable value={item.getValue<string>()} />,},{id: "orders",diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.tsindex 3de11bac72..ed1b9ba127 100644--- a/apps/carbon/app/modules/sales/sales.service.ts+++ b/apps/carbon/app/modules/sales/sales.service.ts@@ -495,6 +495,7 @@ export async function insertCustomerLocation(// countryId: string;postalCode?: string;};+ customFields?: Json;}) {const insertAddress = await client@@ -517,6 +518,7 @@ export async function insertCustomerLocation({customerId: customerLocation.customerId,addressId,+ customFields: customerLocation.customFields,},]).select("id")@@ -622,8 +624,19 @@ export async function updateCustomerLocation(// countryId: string;postalCode?: string;};+ customFields?: Json;}) {+ if (customerLocation.customFields) {+ const customFieldUpdate = await client+ .from("customerLocation")+ .update({ customFields: customerLocation.customFields })+ .eq("addressId", customerLocation.addressId);++ if (customFieldUpdate.error) {+ return customFieldUpdate;+ }+ }return client.from("address").update(sanitize(customerLocation.address))diff --git a/apps/carbon/app/modules/sales/ui/CustomerStatuses/CustomerStatusesTable.tsx b/apps/carbon/app/modules/sales/ui/CustomerStatuses/CustomerStatusesTable.tsxindex d9417e78e4..e5ce231753 100644--- a/apps/carbon/app/modules/sales/ui/CustomerStatuses/CustomerStatusesTable.tsx+++ b/apps/carbon/app/modules/sales/ui/CustomerStatuses/CustomerStatusesTable.tsx@@ -1,4 +1,4 @@-import { Hyperlink, MenuIcon, MenuItem } from "@carbon/react";+import { Enumerable, MenuIcon, MenuItem } from "@carbon/react";import { useNavigate } from "@remix-run/react";import type { ColumnDef } from "@tanstack/react-table";import { memo, useCallback, useMemo } from "react";@@ -26,9 +26,11 @@ const CustomerStatusesTable = memo(accessorKey: "name",header: "Customer Status",cell: ({ row }) => (- <Hyperlink onClick={() => navigate(row.original.id as string)}>- {row.original.name}- </Hyperlink>+ <Enumerable+ value={row.original.name}+ onClick={() => navigate(row.original.id)}+ className="cursor-pointer"+ />),},];diff --git a/apps/carbon/app/modules/sales/ui/CustomerTypes/CustomerTypesTable.tsx b/apps/carbon/app/modules/sales/ui/CustomerTypes/CustomerTypesTable.tsxindex db4018cee6..c3e3781303 100644--- a/apps/carbon/app/modules/sales/ui/CustomerTypes/CustomerTypesTable.tsx+++ b/apps/carbon/app/modules/sales/ui/CustomerTypes/CustomerTypesTable.tsx@@ -1,4 +1,4 @@-import { Hyperlink, MenuIcon, MenuItem } from "@carbon/react";+import { Enumerable, MenuIcon, MenuItem } from "@carbon/react";import { useNavigate } from "@remix-run/react";import type { ColumnDef } from "@tanstack/react-table";import { memo, useCallback, useMemo } from "react";@@ -25,9 +25,11 @@ const CustomerTypesTable = memo(({ data, count }: CustomerTypesTableProps) => {accessorKey: "name",header: "Customer Type",cell: ({ row }) => (- <Hyperlink onClick={() => navigate(row.original.id)}>- {row.original.name}- </Hyperlink>+ <Enumerable+ value={row.original.name}+ onClick={() => navigate(row.original.id)}+ className="cursor-pointer"+ />),},];diff --git a/apps/carbon/app/modules/sales/ui/Customers/CustomersTable.tsx b/apps/carbon/app/modules/sales/ui/Customers/CustomersTable.tsxindex 9e82ce3fe8..384b77f5e5 100644--- a/apps/carbon/app/modules/sales/ui/Customers/CustomersTable.tsx+++ b/apps/carbon/app/modules/sales/ui/Customers/CustomersTable.tsx@@ -1,4 +1,4 @@-import { Hyperlink, MenuIcon, MenuItem } from "@carbon/react";+import { Enumerable, Hyperlink, MenuIcon, MenuItem } from "@carbon/react";import { useNavigate } from "@remix-run/react";import type { ColumnDef } from "@tanstack/react-table";import { memo, useMemo } from "react";@@ -31,12 +31,12 @@ const CustomersTable = memo(({ data, count }: CustomersTableProps) => {{accessorKey: "type",header: "Customer Type",- cell: (item) => item.getValue(),+ cell: (item) => <Enumerable value={item.getValue<string>()} />,},{accessorKey: "status",header: "Customer Status",- cell: (item) => item.getValue(),+ cell: (item) => <Enumerable value={item.getValue<string>()} />,},// {// id: "orders",diff --git a/apps/carbon/app/routes/x+/customer+/$customerId.contacts.$customerContactId.tsx b/apps/carbon/app/routes/x+/customer+/$customerId.contacts.$customerContactId.tsxindex 509866fea5..55bbc80cdd 100644--- a/apps/carbon/app/routes/x+/customer+/$customerId.contacts.$customerContactId.tsx+++ b/apps/carbon/app/routes/x+/customer+/$customerId.contacts.$customerContactId.tsx@@ -2,7 +2,6 @@ import { validationError, validator } from "@carbon/remix-validated-form";import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";import { json, redirect } from "@remix-run/node";import { useLoaderData, useNavigate, useParams } from "@remix-run/react";-import {CustomerContactForm,customerContactValidator,diff --git a/apps/carbon/app/routes/x+/customer+/$customerId.locations.$customerLocationId.tsx b/apps/carbon/app/routes/x+/customer+/$customerId.locations.$customerLocationId.tsxindex a5c1b26b37..8790ee6ddb 100644--- a/apps/carbon/app/routes/x+/customer+/$customerId.locations.$customerLocationId.tsx+++ b/apps/carbon/app/routes/x+/customer+/$customerId.locations.$customerLocationId.tsx@@ -10,6 +10,7 @@ import {} from "~/modules/sales";import { requirePermissions } from "~/services/auth";import { flash } from "~/services/session.server";+import { getCustomFields, setCustomFields } from "~/utils/form";import { assertIsPost, badRequest, notFound } from "~/utils/http";import { path } from "~/utils/path";import { error, success } from "~/utils/result";@@ -49,8 +50,9 @@ export async function action({ request, params }: ActionFunctionArgs) {if (!customerId) throw notFound("customerId not found");if (!customerLocationId) throw notFound("customerLocationId not found");+ const formData = await request.formData();const validation = await validator(customerLocationValidator).validate(- await request.formData()+ formData);if (validation.error) {@@ -65,6 +67,7 @@ export async function action({ request, params }: ActionFunctionArgs) {const update = await updateCustomerLocation(client, {addressId,address,+ customFields: setCustomFields(formData),});if (update.error) {return redirect(@@ -98,6 +101,7 @@ export default function EditCustomerLocationRoute() {city: location?.address?.city ?? "",state: location?.address?.state ?? "",postalCode: location?.address?.postalCode ?? "",+ ...getCustomFields(location?.customFields),};return (diff --git a/apps/carbon/app/routes/x+/customer+/$customerId.locations.new.tsx b/apps/carbon/app/routes/x+/customer+/$customerId.locations.new.tsxindex a01462fb8a..aaa380c252 100644--- a/apps/carbon/app/routes/x+/customer+/$customerId.locations.new.tsx+++ b/apps/carbon/app/routes/x+/customer+/$customerId.locations.new.tsx@@ -9,6 +9,7 @@ import {} from "~/modules/sales";import { requirePermissions } from "~/services/auth";import { flash } from "~/services/session.server";+import { setCustomFields } from "~/utils/form";import { assertIsPost, notFound } from "~/utils/http";import { path } from "~/utils/path";import { error, success } from "~/utils/result";@@ -38,6 +39,7 @@ export async function action({ request, params }: ActionFunctionArgs) {const createCustomerLocation = await insertCustomerLocation(client, {customerId,address,+ customFields: setCustomFields(formData),});if (createCustomerLocation.error) {return modaldiff --git a/packages/database/supabase/seed.sql b/packages/database/supabase/seed.sqlindex c6ced2addf..635f0c83db 100644--- a/packages/database/supabase/seed.sql+++ b/packages/database/supabase/seed.sql@@ -154,7 +154,7 @@ INSERT INTO "supplierStatus" ("name", "createdBy") VALUES ('Active', 'system'),-- customer status-INSERT INTO "customerStatus" ("name", "createdBy") VALUES ('Active', 'system'), ('Inactive', 'system'), ('Prospect', 'system'), ('Lead', 'system'), ('On Hold', 'system'), ('Cancelled', 'system'), ('Archived', 'system');+INSERT INTO "customerStatus" ("name", "createdBy") VALUES ('Active', 'system'), ('Inactive', 'system'), ('Lead', 'system'), ('On Hold', 'system'), ('Cancelled', 'system'), ('Archived', 'system');-- unit of measurediff --git a/packages/react/src/Enumerable.tsx b/packages/react/src/Enumerable.tsxindex fc8f07d854..0a60b925d3 100644--- a/packages/react/src/Enumerable.tsx+++ b/packages/react/src/Enumerable.tsx@@ -8,7 +8,11 @@ type EnumerableProps = BadgeProps & {const Enumerable = ({ value, ...props }: EnumerableProps) => {if (!value) return null;- return <Badge style={getColor(value)}>{value}</Badge>;+ return (+ <Badge style={getColor(value)} {...props}>+ {value}+ </Badge>+ );};export { Enumerable };diff --git a/packages/utils/src/color.ts b/packages/utils/src/color.tsindex bb96db67f0..d956c7d2d1 100644--- a/packages/utils/src/color.ts+++ b/packages/utils/src/color.ts@@ -11,8 +11,14 @@ const colors = [{ background: "#8ecae6", color: "#172a33" },{ background: "#219ebc", color: "#ffffff" },{ background: "#3a86ff", color: "#ffffff" },- { background: "#ff006e", color: "#ffffff" },{ background: "#8338ec", color: "#ffffff" },+ { background: "#ffadad", color: "#000000" },+ { background: "#ffd6a5", color: "#000000" },+ { background: "#fdffb6", color: "#000000" },+ { background: "#caffbf", color: "#000000" },+ { background: "#9bf6ff", color: "#000000" },+ { background: "#a0c4ff", color: "#000000" },+ { background: "#ffc6ff", color: "#000000" },];export function getColor(name: string) {