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: implement process deactivation (soft delete)

udayjain26627216072e35
diff --git a/apps/erp/app/modules/resources/resources.service.ts b/apps/erp/app/modules/resources/resources.service.ts
index a456adb111..41861c97e2 100644
--- a/apps/erp/app/modules/resources/resources.service.ts
+++ b/apps/erp/app/modules/resources/resources.service.ts
@@ -128,11 +128,18 @@ export async function deletePartner(
return client.from("partner").delete().eq("id", partnerId);
}
+export async function activateProcess(
+ client: SupabaseClient<Database>,
+ processId: string
+) {
+ return client.from("process").update({ active: true }).eq("id", processId);
+}
+
export async function deleteProcess(
client: SupabaseClient<Database>,
processId: string
) {
- return client.from("process").delete().eq("id", processId);
+ return client.from("process").update({ active: false }).eq("id", processId);
}
export async function deleteShift(
@@ -708,6 +715,7 @@ export async function getProcessesList(
.from("process")
.select(`id, name`)
.eq("companyId", companyId)
+ .eq("active", true)
.order("name");
}
diff --git a/apps/erp/app/modules/resources/ui/Processes/ProcessesTable.tsx b/apps/erp/app/modules/resources/ui/Processes/ProcessesTable.tsx
index e7ffd5c781..a5b9e8061c 100644
--- a/apps/erp/app/modules/resources/ui/Processes/ProcessesTable.tsx
+++ b/apps/erp/app/modules/resources/ui/Processes/ProcessesTable.tsx
@@ -13,6 +13,7 @@ import type { ColumnDef } from "@tanstack/react-table";
import { memo, useCallback, useMemo } from "react";
import {
LuBuilding2,
+ LuCheck,
LuCog,
LuFactory,
LuPencil,
@@ -178,6 +179,26 @@ const ProcessesTable = memo(({ data, count }: ProcessesTableProps) => {
}
}
},
+ {
+ accessorKey: "active",
+ header: "Active",
+ cell: ({ row }) => (
+ <div className="flex w-full items-center justify-center">
+ <Checkbox isChecked={row.original.active ?? true} />
+ </div>
+ ),
+ meta: {
+ icon: <LuCheck />,
+ filter: {
+ type: "static",
+ options: [
+ { value: "true", label: "Active" },
+ { value: "false", label: "Inactive" }
+ ]
+ },
+ pluralHeader: "Active Statuses"
+ }
+ },
{
id: "createdBy",
header: "Created By",
@@ -228,18 +249,32 @@ const ProcessesTable = memo(({ data, count }: ProcessesTableProps) => {
<MenuIcon icon={<LuPencil />} />
Edit Process
</MenuItem>
- <MenuItem
- destructive
- disabled={!permissions.can("delete", "resources")}
- onClick={() => {
- navigate(
- `${path.to.deleteProcess(row.id!)}?${params.toString()}`
- );
- }}
- >
- <MenuIcon icon={<LuTrash />} />
- Delete Process
- </MenuItem>
+ {row.active ? (
+ <MenuItem
+ destructive
+ disabled={!permissions.can("delete", "resources")}
+ onClick={() => {
+ navigate(
+ `${path.to.deleteProcess(row.id!)}?${params.toString()}`
+ );
+ }}
+ >
+ <MenuIcon icon={<LuTrash />} />
+ Deactivate Process
+ </MenuItem>
+ ) : (
+ <MenuItem
+ disabled={!permissions.can("delete", "resources")}
+ onClick={() => {
+ navigate(
+ `${path.to.activateProcess(row.id!)}?${params.toString()}`
+ );
+ }}
+ >
+ <MenuIcon icon={<LuCheck />} />
+ Activate Process
+ </MenuItem>
+ )}
</>
);
},
diff --git a/apps/erp/app/routes/x+/resources+/processes.activate.$processId.tsx b/apps/erp/app/routes/x+/resources+/processes.activate.$processId.tsx
new file mode 100644
index 0000000000..295983d2c8
--- /dev/null
+++ b/apps/erp/app/routes/x+/resources+/processes.activate.$processId.tsx
@@ -0,0 +1,99 @@
+import { error, notFound, success } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import type {
+ ActionFunctionArgs,
+ ClientActionFunctionArgs,
+ LoaderFunctionArgs
+} from "react-router";
+import { redirect, useLoaderData, useNavigate, useParams } from "react-router";
+import { Confirm } from "~/components/Modals";
+import { activateProcess, getProcess } from "~/modules/resources";
+import { path } from "~/utils/path";
+import { getCompanyId, processesQuery } from "~/utils/react-query";
+
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ view: "resources",
+ role: "employee"
+ });
+
+ const { processId } = params;
+ if (!processId) throw notFound("processId not found");
+
+ const process = await getProcess(client, processId);
+ if (process.error) {
+ throw redirect(
+ path.to.processes,
+ await flash(request, error(process.error, "Failed to get process"))
+ );
+ }
+
+ return {
+ process: process.data
+ };
+}
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ delete: "resources"
+ });
+
+ const { processId } = params;
+ if (!processId) {
+ throw redirect(
+ path.to.processes,
+ await flash(request, error(params, "Failed to get process id"))
+ );
+ }
+
+ const { error: activateProcessError } = await activateProcess(
+ client,
+ processId
+ );
+ if (activateProcessError) {
+ throw redirect(
+ path.to.processes,
+ await flash(
+ request,
+ error(activateProcessError, "Failed to activate process")
+ )
+ );
+ }
+
+ throw redirect(
+ path.to.processes,
+ await flash(request, success("Successfully activated process"))
+ );
+}
+
+export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
+ window.clientCache?.setQueryData(
+ processesQuery(getCompanyId()).queryKey,
+ null
+ );
+ return await serverAction();
+}
+
+export default function ActivateProcessRoute() {
+ const { processId } = useParams();
+ const { process } = useLoaderData<typeof loader>();
+ const navigate = useNavigate();
+
+ if (!process) return null;
+ if (!processId) throw new Error("processId is not found");
+
+ const onCancel = () => navigate(path.to.processes);
+
+ return (
+ <Confirm
+ action={path.to.activateProcess(processId)}
+ title={`Activate ${process.name}`}
+ text={`Are you sure you want to activate the process: ${process.name}? It will appear in dropdowns again.`}
+ confirmText="Activate"
+ isOpen={true}
+ onCancel={onCancel}
+ onSubmit={onCancel}
+ />
+ );
+}
diff --git a/apps/erp/app/routes/x+/resources+/processes.delete.$processId.tsx b/apps/erp/app/routes/x+/resources+/processes.delete.$processId.tsx
index 008a9bc603..464b92400c 100644
--- a/apps/erp/app/routes/x+/resources+/processes.delete.$processId.tsx
+++ b/apps/erp/app/routes/x+/resources+/processes.delete.$processId.tsx
@@ -7,7 +7,7 @@ import type {
LoaderFunctionArgs
} from "react-router";
import { redirect, useLoaderData, useNavigate, useParams } from "react-router";
-import { ConfirmDelete } from "~/components/Modals";
+import { Confirm } from "~/components/Modals";
import { deleteProcess, getProcess } from "~/modules/resources";
import { path } from "~/utils/path";
import { getCompanyId, processesQuery } from "~/utils/react-query";
@@ -60,7 +60,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
throw redirect(
path.to.processes,
- await flash(request, success("Successfully deleted process"))
+ await flash(request, success("Successfully deactivated process"))
);
}
@@ -83,11 +83,14 @@ export default function DeleteProcessRoute() {
const onCancel = () => navigate(path.to.processes);
return (
- <ConfirmDelete
+ <Confirm
action={path.to.deleteProcess(processId)}
- name={process.name!}
- text={`Are you sure you want to delete the process: ${process.name}? This cannot be undone.`}
+ title={`Deactivate ${process.name}`}
+ text={`Are you sure you want to deactivate the process: ${process.name}? It will no longer appear in dropdowns.`}
+ confirmText="Deactivate"
+ isOpen={true}
onCancel={onCancel}
+ onSubmit={onCancel}
/>
);
}
diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.ts
index 4d687d86ba..d1e3d28bc6 100644
--- a/apps/erp/app/utils/path.ts
+++ b/apps/erp/app/utils/path.ts
@@ -1591,7 +1591,9 @@ export const path = {
workCenter: (id: string) =>
generatePath(`${x}/resources/work-centers/${id}`),
workCenterActivate: (id: string) =>
- generatePath(`${x}/resources/work-centers/activate/${id}`)
+ generatePath(`${x}/resources/work-centers/activate/${id}`),
+ activateProcess: (id: string) =>
+ generatePath(`${x}/resources/processes/activate/${id}`)
}
} as const;
diff --git a/packages/database/supabase/migrations/20260120171236_process-active-column.sql b/packages/database/supabase/migrations/20260120171236_process-active-column.sql
new file mode 100644
index 0000000000..cc19bc1517
--- /dev/null
+++ b/packages/database/supabase/migrations/20260120171236_process-active-column.sql
@@ -0,0 +1,28 @@
+-- Add active column to process table for soft delete functionality
+ALTER TABLE "process" ADD COLUMN IF NOT EXISTS "active" BOOLEAN NOT NULL DEFAULT true;
+
+-- Recreate the processes view to include the new active column
+-- (PostgreSQL views with SELECT * don't auto-update when columns are added)
+DROP VIEW IF EXISTS "processes";
+CREATE OR REPLACE VIEW "processes" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ p.*,
+ wcp."workCenters",
+ sp."suppliers"
+ FROM "process" p
+ LEFT JOIN (
+ SELECT
+ "processId",
+ array_agg("workCenterId"::text) as "workCenters"
+ FROM "workCenterProcess" wcp
+ INNER JOIN "workCenter" wc ON wcp."workCenterId" = wc.id
+ GROUP BY "processId"
+ ) wcp ON p.id = wcp."processId"
+ LEFT JOIN (
+ SELECT
+ "processId",
+ jsonb_agg(jsonb_build_object('id', sp."id", 'name', s.name)) as "suppliers"
+ FROM "supplierProcess" sp
+ INNER JOIN "supplier" s ON sp."supplierId" = s.id
+ GROUP BY "processId"
+ ) sp ON p.id = sp."processId";