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: allow user to assign customerLocation to a customer contact
Rob Carrington666a2ad83eae
diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.tsindex 8696e684d0..0683d223a1 100644--- a/apps/carbon/app/modules/sales/sales.service.ts+++ b/apps/carbon/app/modules/sales/sales.service.ts@@ -864,13 +864,17 @@ export async function insertCustomerContact(customerId: string;companyId: string;contact: z.infer<typeof customerContactValidator>;+ customerLocationId?: string;customFields?: Json;}) {const insertContact = await client.from("contact").insert([- { ...customerContact.contact, companyId: customerContact.companyId },+ {+ ...customerContact.contact,+ companyId: customerContact.companyId,+ },]).select("id").single();@@ -889,6 +893,7 @@ export async function insertCustomerContact({customerId: customerContact.customerId,contactId,+ customerLocationId: customerContact.customerLocationId,customFields: customerContact.customFields,},])@@ -1087,13 +1092,17 @@ export async function updateCustomerContact(customerContact: {contactId: string;contact: z.infer<typeof customerContactValidator>;+ customerLocationId?: string;customFields?: Json;}) {if (customerContact.customFields) {const customFieldUpdate = await client.from("customerContact")- .update({ customFields: customerContact.customFields })+ .update({+ customFields: customerContact.customFields,+ customerLocationId: customerContact.customerLocationId,+ }).eq("contactId", customerContact.contactId);if (customFieldUpdate.error) {diff --git a/apps/carbon/app/modules/sales/ui/Customer/CustomerContactForm.tsx b/apps/carbon/app/modules/sales/ui/Customer/CustomerContactForm.tsxindex 90290d9b31..1056225903 100644--- a/apps/carbon/app/modules/sales/ui/Customer/CustomerContactForm.tsx+++ b/apps/carbon/app/modules/sales/ui/Customer/CustomerContactForm.tsx@@ -11,8 +11,10 @@ import {} from "@carbon/react";import { ValidatedForm } from "@carbon/remix-validated-form";import { useFetcher } from "@remix-run/react";+import { useState } from "react";import type { z } from "zod";import {+ CustomerLocation,CustomFormFields,Hidden,Input,@@ -47,6 +49,8 @@ const CustomerContactForm = ({? !permissions.can("update", "sales"): !permissions.can("create", "sales");+ const [customer, setCustomer] = useState<string | undefined>(customerId);+return (<Draweropen={open}@@ -88,6 +92,11 @@ const CustomerContactForm = ({<PhoneInput name="homePhone" label="Home Phone" /><PhoneInput name="workPhone" label="Work Phone" /><PhoneInput name="fax" label="Fax" />+ <CustomerLocation+ name="customerLocationId"+ label="Location"+ customer={customer}+ /><TextArea name="notes" label="Notes" /><CustomFormFields table="customerContact" /></VStack>diff --git a/apps/carbon/app/routes/x+/customer+/$customerId.contacts.$customerContactId.tsx b/apps/carbon/app/routes/x+/customer+/$customerId.contacts.$customerContactId.tsxindex b6f5921603..59d118337b 100644--- a/apps/carbon/app/routes/x+/customer+/$customerId.contacts.$customerContactId.tsx+++ b/apps/carbon/app/routes/x+/customer+/$customerId.contacts.$customerContactId.tsx@@ -59,7 +59,9 @@ export async function action({ request, params }: ActionFunctionArgs) {return validationError(validation.error);}- const { id, contactId, ...contact } = validation.data;+ const { id, contactId, customerLocationId, ...contact } = validation.data;++ console.log({ customerLocationId });if (id !== customerContactId)throw badRequest("customerContactId does not match id from form data");@@ -70,6 +72,7 @@ export async function action({ request, params }: ActionFunctionArgs) {const update = await updateCustomerContact(client, {contactId,contact,+ customerLocationId,customFields: setCustomFields(formData),});@@ -107,12 +110,7 @@ export default function EditCustomerContactRoute() {homePhone: contact?.contact?.homePhone ?? "",workPhone: contact?.contact?.workPhone ?? "",fax: contact?.contact?.fax ?? "",- addressLine1: contact?.contact?.addressLine1 ?? "",- addressLine2: contact?.contact?.addressLine2 ?? "",- city: contact?.contact?.city ?? "",- state: contact?.contact?.state ?? "",- postalCode: contact?.contact?.postalCode ?? "",- birthday: contact?.contact?.birthday ?? undefined,+ customerLocationId: contact?.customerLocationId ?? "",...getCustomFields(contact?.customFields),};diff --git a/apps/carbon/app/routes/x+/customer+/$customerId.contacts.new.tsx b/apps/carbon/app/routes/x+/customer+/$customerId.contacts.new.tsxindex 85b9530913..3ef1e3fbf7 100644--- a/apps/carbon/app/routes/x+/customer+/$customerId.contacts.new.tsx+++ b/apps/carbon/app/routes/x+/customer+/$customerId.contacts.new.tsx@@ -38,12 +38,13 @@ export async function action({ request, params }: ActionFunctionArgs) {return validationError(validation.error);}- const { id, contactId, ...contact } = validation.data;+ const { id, contactId, customerLocationId, ...contact } = validation.data;const createCustomerContact = await insertCustomerContact(client, {customerId,companyId,contact,+ customerLocationId,customFields: setCustomFields(formData),});if (createCustomerContact.error) {