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
// SPDX-License-Identifier: AGPL-3.0-only
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.
import { error } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { storage } from "@carbon/files";
import type { JSONContent } from "@carbon/react";
import { RecordOutlet, VStack } from "@carbon/react";
import { redirect } from "@carbon/utils";
import { msg } from "@lingui/core/macro";
import { useLingui } from "@lingui/react/macro";
import type { LoaderFunctionArgs } from "react-router";
import { useLoaderData, useParams } from "react-router";
import { PanelProvider, ResizablePanels } from "~/components/Layout/Panels";
import RiskRegisterCard from "~/modules/quality/ui/RiskRegister/RiskRegisterCard";
import {
getFailureModesList,
getMaintenanceDispatch,
getMaintenanceDispatchComments,
getMaintenanceDispatchEvents,
getMaintenanceDispatchItems
} from "~/modules/resources/resources.service";
import { MaintenanceDispatchExplorer } from "~/modules/resources/ui/Maintenance/MaintenanceDispatchExplorer";
import MaintenanceDispatchHeader from "~/modules/resources/ui/Maintenance/MaintenanceDispatchHeader";
import {
MaintenanceDispatchFiles,
MaintenanceDispatchNotes
} from "~/modules/resources/ui/Maintenance/MaintenanceDispatchNotes";
import MaintenanceDispatchProperties from "~/modules/resources/ui/Maintenance/MaintenanceDispatchProperties";
import { detailBreadcrumb, type Handle } from "~/utils/handle";
import { path } from "~/utils/path";
export const handle: Handle = {
realtime: [
{ table: "maintenanceDispatch", column: "id", param: "dispatchId" }
],
breadcrumb: detailBreadcrumb(
{ breadcrumb: msg`Maintenance`, to: path.to.maintenanceDispatches },
(data) => data?.dispatch?.maintenanceDispatchId
),
module: "resources"
};
async function getMaintenanceDispatchFiles(
client: Parameters<typeof getMaintenanceDispatch>[0],
companyId: string,
dispatchId: string
) {
const result = await storage(client)
.company(companyId)
.list(`${companyId}/maintenance/${dispatchId}`);
return result.data ?? [];
}
export async function loader({ request, params }: LoaderFunctionArgs) {
const { client, companyId } = await requirePermissions(request, {
view: "resources"
});
const { dispatchId } = params;
if (!dispatchId) throw new Error("Could not find dispatchId");
const [dispatch, events, items, comments, failureModes] = await Promise.all([
getMaintenanceDispatch(client, dispatchId),
getMaintenanceDispatchEvents(client, dispatchId),
getMaintenanceDispatchItems(client, dispatchId),
getMaintenanceDispatchComments(client, dispatchId),
getFailureModesList(client, companyId)
]);
if (dispatch.error) {
throw redirect(
path.to.maintenanceDispatches,
await flash(
request,
error(dispatch.error, "Failed to load maintenance dispatch")
)
);
}
return {
dispatch: dispatch.data,
events: events.data ?? [],
items: items.data ?? [],
comments: comments.data ?? [],
failureModes: failureModes.data ?? [],
files: getMaintenanceDispatchFiles(client, companyId, dispatchId)
};
}
export default function MaintenanceDispatchRoute() {
const { t } = useLingui();
const { dispatchId } = useParams();
const { dispatch, events, items, files } = useLoaderData<typeof loader>();
if (!dispatchId) throw new Error("Could not find dispatchId");
const isCompleted = dispatch?.status === "Completed";
return (
<PanelProvider>
<div className="flex flex-col h-[calc(100dvh-var(--topbar-height)-var(--content-inset))] overflow-hidden w-full">
<MaintenanceDispatchHeader />
<div className="flex h-[calc(100dvh-var(--topbar-height)-var(--header-height)-var(--content-inset))] overflow-hidden w-full">
<div className="flex flex-grow overflow-hidden">
<ResizablePanels
explorerLabel={t`Items`}
explorer={
<MaintenanceDispatchExplorer items={items} events={events} />
}
content={
<div className="bg-card h-[calc(100dvh-var(--topbar-height)-var(--header-height)-var(--content-inset))] overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent w-full">
<VStack spacing={4} className="p-4">
<MaintenanceDispatchNotes
id={dispatchId}
content={(dispatch?.content ?? {}) as JSONContent}
isDisabled={isCompleted}
/>
<MaintenanceDispatchFiles
dispatchId={dispatchId}
files={files}
isDisabled={isCompleted}
/>
{dispatch?.workCenterId && (
<RiskRegisterCard
sourceId={dispatch.workCenterId}
source="Work Center"
/>
)}
<RecordOutlet />
</VStack>
</div>
}
properties={<MaintenanceDispatchProperties key={dispatchId} />}
/>
</div>
</div>
</div>
</PanelProvider>
);
}