Skip to content

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.

feat: custom fields for customer type form

Brad Barbinef79668a5e83
diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.ts
index cbd7536cda..0a0a60de11 100644
--- a/apps/carbon/app/modules/sales/sales.service.ts
+++ b/apps/carbon/app/modules/sales/sales.service.ts
@@ -696,10 +696,12 @@ export async function upsertCustomerType(
customerType:
| (Omit<z.infer<typeof customerTypeValidator>, "id"> & {
createdBy: string;
+ customFields?: Json;
})
| (Omit<z.infer<typeof customerTypeValidator>, "id"> & {
id: string;
updatedBy: string;
+ customFields?: Json;
})
) {
if ("createdBy" in customerType) {
diff --git a/apps/carbon/app/routes/x+/sales+/customer-types.$customerTypeId.tsx b/apps/carbon/app/routes/x+/sales+/customer-types.$customerTypeId.tsx
index a0cfc0cd97..cab0479a4d 100644
--- a/apps/carbon/app/routes/x+/sales+/customer-types.$customerTypeId.tsx
+++ b/apps/carbon/app/routes/x+/sales+/customer-types.$customerTypeId.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, notFound } from "~/utils/http";
import { path } from "~/utils/path";
import { error, success } from "~/utils/result";
@@ -43,9 +44,8 @@ export async function action({ request }: ActionFunctionArgs) {
update: "sales",
});
- const validation = await validator(customerTypeValidator).validate(
- await request.formData()
- );
+ const formData = await request.formData();
+ const validation = await validator(customerTypeValidator).validate(formData);
if (validation.error) {
return validationError(validation.error);
@@ -58,6 +58,7 @@ export async function action({ request }: ActionFunctionArgs) {
id,
...data,
updatedBy: userId,
+ customFields: setCustomFields(formData),
});
if (updateCustomerType.error) {
@@ -83,6 +84,7 @@ export default function EditCustomerTypesRoute() {
const initialValues = {
id: customerType?.id ?? undefined,
name: customerType?.name ?? "",
+ ...getCustomFields(customerType?.customFields),
};
return (
diff --git a/apps/carbon/app/routes/x+/sales+/customer-types.new.tsx b/apps/carbon/app/routes/x+/sales+/customer-types.new.tsx
index c1f59bb2b3..b969dfed47 100644
--- a/apps/carbon/app/routes/x+/sales+/customer-types.new.tsx
+++ b/apps/carbon/app/routes/x+/sales+/customer-types.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 } from "~/utils/http";
import { path, requestReferrer } from "~/utils/path";
import { error, success } from "~/utils/result";
@@ -41,6 +42,7 @@ export async function action({ request }: ActionFunctionArgs) {
const insertCustomerType = await upsertCustomerType(client, {
...data,
createdBy: userId,
+ customFields: setCustomFields(formData),
});
if (insertCustomerType.error) {
return modal