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 { assertIsPost, error, notFound, success } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { requireFeature } from "@carbon/ee/plan.server";
import { deleteEnforcementRule } from "@carbon/ee/rules.server";
import { redirect } from "@carbon/utils";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";
import { useLoaderData, useNavigate } from "react-router";
import { ConfirmDelete } from "~/components/Modals";
import { getEnforcementRule } from "~/modules/shared/shared.service";
import { getParams, path } from "~/utils/path";
export async function loader({ request, params }: LoaderFunctionArgs) {
const { client, companyId } = await requirePermissions(request, {
delete: "inventory"
});
const { id } = params;
if (!id) throw notFound("id required");
const rule = await getEnforcementRule(client, "storage", id, companyId);
if (rule.error || !rule.data) {
throw redirect(
path.to.storageRules,
await flash(request, error(rule.error, "Rule not found"))
);
}
return { rule: rule.data };
}
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
const { client, companyId } = await requirePermissions(request, {
delete: "inventory"
});
await requireFeature({
request,
client,
companyId,
feature: "STORAGE_RULES",
redirectTo: path.to.storageRules
});
const { id } = params;
if (!id) throw new Error("id required");
const result = await deleteEnforcementRule(client, "storage", id, companyId);
if (result.error) {
throw redirect(
`${path.to.storageRules}?${getParams(request)}`,
await flash(request, error(result.error, "Failed to delete rule"))
);
}
throw redirect(
`${path.to.storageRules}?${getParams(request)}`,
await flash(request, success("Rule deleted"))
);
}
export default function DeleteStorageRuleRoute() {
const { rule } = useLoaderData<typeof loader>();
const id = rule?.id ?? "";
const navigate = useNavigate();
return (
<ConfirmDelete
action={path.to.deleteStorageRule(id)}
name={rule?.name ?? "this rule"}
text="Are you sure you want to delete this rule? Assignments will also be removed."
onCancel={() => navigate(path.to.storageRules)}
/>
);
}