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 department form

Brad Barbin0757062b9e2d
diff --git a/apps/carbon/app/modules/resources/resources.service.ts b/apps/carbon/app/modules/resources/resources.service.ts
index f5cbdad68f..b0f4c62616 100644
--- a/apps/carbon/app/modules/resources/resources.service.ts
+++ b/apps/carbon/app/modules/resources/resources.service.ts
@@ -8,6 +8,7 @@ import type { GenericQueryFilters } from "~/utils/query";
import { setGenericQueryFilters } from "~/utils/query";
import { sanitize } from "~/utils/supabase";
import type {
+ departmentValidator,
employeeJobValidator,
equipmentTypeValidator,
equipmentValidator,
@@ -1012,19 +1013,15 @@ export async function upsertContractor(
export async function upsertDepartment(
client: SupabaseClient<Database>,
department:
- | {
- name: string;
- color?: string;
- parentDepartmentId?: string;
+ | (Omit<z.infer<typeof departmentValidator>, "id"> & {
createdBy: string;
- }
- | {
+ customFields?: Json;
+ })
+ | (Omit<z.infer<typeof departmentValidator>, "id"> & {
id: string;
- name: string;
- color?: string;
- parentDepartmentId?: string;
updatedBy: string;
- }
+ customFields?: Json;
+ })
) {
if ("id" in department) {
return client
diff --git a/apps/carbon/app/routes/x+/resources+/departments.$departmentId.tsx b/apps/carbon/app/routes/x+/resources+/departments.$departmentId.tsx
index fef371fc6b..c957694137 100644
--- a/apps/carbon/app/routes/x+/resources+/departments.$departmentId.tsx
+++ b/apps/carbon/app/routes/x+/resources+/departments.$departmentId.tsx
@@ -10,6 +10,7 @@ import {
} from "~/modules/resources";
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";
@@ -42,9 +43,8 @@ export async function action({ request }: ActionFunctionArgs) {
create: "resources",
});
- const validation = await validator(departmentValidator).validate(
- await request.formData()
- );
+ const formData = await request.formData();
+ const validation = await validator(departmentValidator).validate(formData);
if (validation.error) {
return validationError(validation.error);
@@ -57,6 +57,7 @@ export async function action({ request }: ActionFunctionArgs) {
id,
...data,
updatedBy: userId,
+ customFields: setCustomFields(formData),
});
if (updateDepartment.error) {
@@ -83,6 +84,7 @@ export default function DepartmentRoute() {
id: department.id,
name: department.name,
parentDepartmentId: department.parentDepartmentId ?? undefined,
+ ...getCustomFields(department.customFields),
};
return (
diff --git a/apps/carbon/app/routes/x+/resources+/departments.new.tsx b/apps/carbon/app/routes/x+/resources+/departments.new.tsx
index 6f8081972b..19667a8e7d 100644
--- a/apps/carbon/app/routes/x+/resources+/departments.new.tsx
+++ b/apps/carbon/app/routes/x+/resources+/departments.new.tsx
@@ -9,6 +9,7 @@ import {
} from "~/modules/resources";
import { requirePermissions } from "~/services/auth";
import { flash } from "~/services/session.server";
+import { setCustomFields } from "~/utils/form";
import { assertIsPost } from "~/utils/http";
import { path } from "~/utils/path";
import { error, success } from "~/utils/result";
@@ -33,6 +34,7 @@ export async function action({ request }: ActionFunctionArgs) {
const createDepartment = await upsertDepartment(client, {
...data,
createdBy: userId,
+ customFields: setCustomFields(formData),
});
if (createDepartment.error) {