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: add the ability to reactivate work centers

Brad Barbin00b3879c26ea
diff --git a/apps/erp/app/modules/purchasing/ui/Supplier/SupplierSidebar/useSupplierSidebar.tsx b/apps/erp/app/modules/purchasing/ui/Supplier/SupplierSidebar/useSupplierSidebar.tsx
index 20e2e683a4..59ebb9a37c 100644
--- a/apps/erp/app/modules/purchasing/ui/Supplier/SupplierSidebar/useSupplierSidebar.tsx
+++ b/apps/erp/app/modules/purchasing/ui/Supplier/SupplierSidebar/useSupplierSidebar.tsx
@@ -6,8 +6,7 @@ import {
LuLayoutList,
LuMapPin,
LuPackageSearch,
-} from "react-icons/lu";
-import { TbRoute } from "react-icons/tb";
+ LuCog } from "react-icons/lu";
import { usePermissions } from "~/hooks";
import type { Role } from "~/types";
import { path } from "~/utils/path";
@@ -56,7 +55,7 @@ export function useSupplierSidebar({ contacts, locations }: Props) {
name: "Processes",
to: path.to.supplierProcesses(supplierId),
role: ["employee"],
- icon: <TbRoute />,
+ icon: <LuCog />,
shortcut: "Command+Shift+r",
},
{
diff --git a/apps/erp/app/modules/resources/resources.service.ts b/apps/erp/app/modules/resources/resources.service.ts
index 5fd05d8f87..37dde6644f 100644
--- a/apps/erp/app/modules/resources/resources.service.ts
+++ b/apps/erp/app/modules/resources/resources.service.ts
@@ -11,6 +11,13 @@ import type {
workCenterValidator,
} from "./resources.models";
+export async function activateWorkCenter(
+ client: SupabaseClient<Database>,
+ id: string
+) {
+ return client.from("workCenter").update({ active: true }).eq("id", id);
+}
+
export async function deleteAbility(
client: SupabaseClient<Database>,
abilityId: string,
@@ -341,8 +348,7 @@ export async function getWorkCenters(
.select("*", {
count: "exact",
})
- .eq("companyId", companyId)
- .eq("active", true);
+ .eq("companyId", companyId);
if (args?.search) {
query = query.ilike("name", `%${args.search}%`);
diff --git a/apps/erp/app/modules/resources/ui/WorkCenters/WorkCentersTable.tsx b/apps/erp/app/modules/resources/ui/WorkCenters/WorkCentersTable.tsx
index 968011cb71..3668d82e33 100644
--- a/apps/erp/app/modules/resources/ui/WorkCenters/WorkCentersTable.tsx
+++ b/apps/erp/app/modules/resources/ui/WorkCenters/WorkCentersTable.tsx
@@ -1,10 +1,17 @@
-import { HStack, MenuIcon, MenuItem, useDisclosure } from "@carbon/react";
+import {
+ Checkbox,
+ HStack,
+ MenuIcon,
+ MenuItem,
+ useDisclosure,
+} from "@carbon/react";
import { useNavigate } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { memo, useCallback, useMemo, useState } from "react";
import {
LuAlignLeft,
LuBuilding2,
+ LuCheck,
LuCog,
LuDollarSign,
LuPencil,
@@ -15,7 +22,7 @@ import {
} from "react-icons/lu";
import { EmployeeAvatar, Hyperlink, New, Table } from "~/components";
import { Enumerable } from "~/components/Enumerable";
-import { ConfirmDelete } from "~/components/Modals";
+import { Confirm, ConfirmDelete } from "~/components/Modals";
import { useCurrencyFormatter, usePermissions, useUrlParams } from "~/hooks";
import { useCustomColumns } from "~/hooks/useCustomColumns";
import type { WorkCenter } from "~/modules/resources";
@@ -45,19 +52,26 @@ const WorkCentersTable = memo(
const permissions = usePermissions();
const deleteModal = useDisclosure();
+ const activateModal = useDisclosure();
const [selectedWorkCenter, setSelectedWorkCenter] =
useState<WorkCenter | null>(null);
const formatter = useCurrencyFormatter();
+ const onActivate = (data: WorkCenter) => {
+ setSelectedWorkCenter(data);
+ activateModal.onOpen();
+ };
+
const onDelete = (data: WorkCenter) => {
setSelectedWorkCenter(data);
deleteModal.onOpen();
};
- const onDeleteCancel = () => {
+ const onCancel = () => {
setSelectedWorkCenter(null);
deleteModal.onClose();
+ activateModal.onClose();
};
const customColumns = useCustomColumns<WorkCenter>("workCenter");
@@ -125,6 +139,22 @@ const WorkCentersTable = memo(
},
},
},
+ {
+ accessorKey: "active",
+ header: "Active",
+ cell: (item) => <Checkbox isChecked={item.getValue<boolean>()} />,
+ meta: {
+ filter: {
+ type: "static",
+ options: [
+ { value: "true", label: "Active" },
+ { value: "false", label: "Inactive" },
+ ],
+ },
+ pluralHeader: "Active Statuses",
+ icon: <LuCheck />,
+ },
+ },
{
accessorKey: "description",
header: "Description",
@@ -217,14 +247,24 @@ const WorkCentersTable = memo(
<MenuIcon icon={<LuPencil />} />
Edit Work Center
</MenuItem>
- <MenuItem
- destructive
- disabled={!permissions.can("delete", "resources")}
- onClick={() => onDelete(row)}
- >
- <MenuIcon icon={<LuTrash />} />
- Delete Work Center
- </MenuItem>
+ {row.active ? (
+ <MenuItem
+ destructive
+ disabled={!permissions.can("delete", "resources")}
+ onClick={() => onDelete(row)}
+ >
+ <MenuIcon icon={<LuTrash />} />
+ Deactivate Work Center
+ </MenuItem>
+ ) : (
+ <MenuItem
+ disabled={!permissions.can("delete", "resources")}
+ onClick={() => onActivate(row)}
+ >
+ <MenuIcon icon={<LuCheck />} />
+ Activate Work Center
+ </MenuItem>
+ )}
</>
),
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -255,8 +295,20 @@ const WorkCentersTable = memo(
name={selectedWorkCenter?.name ?? ""}
text={`Are you sure you want to deactivate the ${selectedWorkCenter?.name} work center?`}
isOpen={deleteModal.isOpen}
- onCancel={onDeleteCancel}
- onSubmit={onDeleteCancel}
+ onCancel={onCancel}
+ onSubmit={onCancel}
+ />
+ )}
+
+ {selectedWorkCenter && selectedWorkCenter.id && (
+ <Confirm
+ action={path.to.workCenterActivate(selectedWorkCenter.id)}
+ title={`Activate ${selectedWorkCenter?.name} Work Center`}
+ text={`Are you sure you want to activate the ${selectedWorkCenter?.name} work center?`}
+ confirmText="Activate"
+ isOpen={activateModal.isOpen}
+ onCancel={onCancel}
+ onSubmit={onCancel}
/>
)}
</>
diff --git a/apps/erp/app/modules/resources/ui/useResourcesSubmodules.tsx b/apps/erp/app/modules/resources/ui/useResourcesSubmodules.tsx
index ae3ec20223..1a81ae861a 100644
--- a/apps/erp/app/modules/resources/ui/useResourcesSubmodules.tsx
+++ b/apps/erp/app/modules/resources/ui/useResourcesSubmodules.tsx
@@ -1,5 +1,4 @@
-import { LuMapPin } from "react-icons/lu";
-import { TbRoute } from "react-icons/tb";
+import { LuMapPin, LuWrench , LuCog } from "react-icons/lu";
import { useSavedViews } from "~/hooks/useSavedViews";
import type { RouteGroup } from "~/types";
import { path } from "~/utils/path";
@@ -17,13 +16,13 @@ const resourcesRoutes: RouteGroup[] = [
{
name: "Processes",
to: path.to.processes,
- icon: <TbRoute />,
+ icon: <LuCog />,
table: "process",
},
{
name: "Work Centers",
to: path.to.workCenters,
- icon: <LuMapPin />,
+ icon: <LuWrench />,
table: "workCenter",
},
],
diff --git a/apps/erp/app/routes/x+/resources+/work-centers.$id.tsx b/apps/erp/app/routes/x+/resources+/work-centers.$id.tsx
index b15546b38a..2d06c51ad1 100644
--- a/apps/erp/app/routes/x+/resources+/work-centers.$id.tsx
+++ b/apps/erp/app/routes/x+/resources+/work-centers.$id.tsx
@@ -55,19 +55,19 @@ export async function action({ request }: ActionFunctionArgs) {
const { id, ...data } = validation.data;
if (!id) throw new Error("ID is was not found");
- const updateCategory = await upsertWorkCenter(client, {
+ const updateWorkCenter = await upsertWorkCenter(client, {
id,
...data,
companyId,
updatedBy: userId,
customFields: setCustomFields(formData),
});
- if (updateCategory.error) {
+ if (updateWorkCenter.error) {
throw redirect(
path.to.workCenters,
await flash(
request,
- error(updateCategory.error, "Failed to update work center")
+ error(updateWorkCenter.error, "Failed to update work center")
)
);
}
diff --git a/apps/erp/app/routes/x+/resources+/work-centers.activate.$id.tsx b/apps/erp/app/routes/x+/resources+/work-centers.activate.$id.tsx
new file mode 100644
index 0000000000..675ef5292c
--- /dev/null
+++ b/apps/erp/app/routes/x+/resources+/work-centers.activate.$id.tsx
@@ -0,0 +1,47 @@
+import { error, success } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import type { ClientActionFunctionArgs } from "@remix-run/react";
+import type { LoaderFunctionArgs } from "@vercel/remix";
+import { redirect } from "@vercel/remix";
+import { activateWorkCenter } from "~/modules/resources";
+import { path } from "~/utils/path";
+import { getCompanyId, workCentersQuery } from "~/utils/react-query";
+
+export async function action({ request, params }: LoaderFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ delete: "resources",
+ });
+
+ const { id } = params;
+ if (!id) {
+ throw redirect(
+ path.to.workCenters,
+ await flash(request, error(params, "Failed to get a work center id"))
+ );
+ }
+
+ const activate = await activateWorkCenter(client, id);
+ if (activate.error) {
+ throw redirect(
+ path.to.workCenters,
+ await flash(
+ request,
+ error(activate.error, "Failed to activate work center")
+ )
+ );
+ }
+
+ throw redirect(
+ path.to.workCenters,
+ await flash(request, success("Successfully activate work center"))
+ );
+}
+
+export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
+ window.clientCache?.setQueryData(
+ workCentersQuery(getCompanyId()).queryKey,
+ null
+ );
+ return await serverAction();
+}
diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.ts
index 6cb69adf5b..e2d7832265 100644
--- a/apps/erp/app/utils/path.ts
+++ b/apps/erp/app/utils/path.ts
@@ -975,6 +975,8 @@ export const path = {
workCenters: `${x}/resources/work-centers`,
workCenter: (id: string) =>
generatePath(`${x}/resources/work-centers/${id}`),
+ workCenterActivate: (id: string) =>
+ generatePath(`${x}/resources/work-centers/activate/${id}`),
},
} as const;