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
fix(approvals): tab URL state, rule drawer UX, and doc-type handling
Ayush Sonica194333d6b1
diff --git a/apps/erp/app/modules/approvals/ui/ApprovalRuleDrawer.tsx b/apps/erp/app/modules/approvals/ui/ApprovalRuleDrawer.tsxindex 185aac2e2c..11bf32e02a 100644--- a/apps/erp/app/modules/approvals/ui/ApprovalRuleDrawer.tsx+++ b/apps/erp/app/modules/approvals/ui/ApprovalRuleDrawer.tsx@@ -19,12 +19,16 @@ import {} from "@carbon/react";import { User } from "~/components/Form";import { usePermissions } from "~/hooks";-import { type ApprovalRule, approvalRuleValidator } from "~/modules/approvals";+import {+ ApprovalDocumentType,+ type ApprovalRule,+ approvalRuleValidator+} from "~/modules/approvals";import { path } from "~/utils/path";type ApprovalRuleDrawerProps = {rule: ApprovalRule | null;- documentType: "purchaseOrder" | "qualityDocument";+ documentType: ApprovalDocumentType;groups: Array<{ id: string; name: string }>;onClose: () => void;};@@ -91,12 +95,7 @@ const ApprovalRuleDrawer = ({<div className="flex flex-col gap-6">{isEditing && rule?.id && <Hidden name="id" value={rule.id} />}<Hidden name="documentType" value={documentType} />- <Input- name="name"- label="Rule Name"- helperText="A descriptive name for this approval rule (e.g., 'Low Value PO Rule', 'High Value PO Rule')"- required- />+ <Input name="name" label="Rule Name" required /><Switch name="enabled" label="Enabled" /><MultiSelectname="approverGroupIds"@@ -115,13 +114,22 @@ const ApprovalRuleDrawer = ({name="lowerBoundAmount"label="Lower Bound Amount"helperText="Minimum amount (inclusive) for this rule"- step={0.01}+ step={100}+ formatOptions={{+ style: "currency",+ currency: "USD"+ }}/>+<FormNumbername="upperBoundAmount"label="Upper Bound Amount"helperText="Maximum amount (exclusive) for this rule. Leave empty for no upper limit."- step={0.01}+ step={100}+ formatOptions={{+ style: "currency",+ currency: "USD"+ }}/></>)}diff --git a/apps/erp/app/modules/approvals/ui/ApprovalsTable.tsx b/apps/erp/app/modules/approvals/ui/ApprovalsTable.tsxindex 0cb5c1f51c..90805113bb 100644--- a/apps/erp/app/modules/approvals/ui/ApprovalsTable.tsx+++ b/apps/erp/app/modules/approvals/ui/ApprovalsTable.tsx@@ -59,10 +59,20 @@ const ApprovalsTable = memo(({ data, count }: ApprovalsTableProps) => {);}- const link =- docType === "purchaseOrder"- ? path.to.purchaseOrderDetails(docId)- : path.to.qualityDocument(docId);+ let link: string | null = null;+ if (docType === "purchaseOrder") {+ link = path.to.purchaseOrderDetails(docId);+ } else if (docType === "qualityDocument") {+ link = path.to.qualityDocument(docId);+ }++ if (!link) {+ return (+ <HStack>+ <span>{label}</span>+ </HStack>+ );+ }return (<HStack>diff --git a/apps/erp/app/routes/x+/settings+/approvals+/_index.tsx b/apps/erp/app/routes/x+/settings+/approvals+/_index.tsxindex b2f6c6ec40..114c737d19 100644--- a/apps/erp/app/routes/x+/settings+/approvals+/_index.tsx+++ b/apps/erp/app/routes/x+/settings+/approvals+/_index.tsx@@ -11,7 +11,8 @@ import {import { LuInbox } from "react-icons/lu";import type { LoaderFunctionArgs } from "react-router";import { Link, Outlet, redirect, useLoaderData } from "react-router";-import { getApprovalRules } from "~/modules/approvals";+import { useUrlParams } from "~/hooks";+import { ApprovalDocumentType, getApprovalRules } from "~/modules/approvals";import ApprovalRulesTable from "~/modules/approvals/ui/ApprovalRulesTable";import type { Handle } from "~/utils/handle";import { path } from "~/utils/path";@@ -51,12 +52,18 @@ export async function loader({ request }: LoaderFunctionArgs) {export default function ApprovalSettingsRoute() {const { poRules, qdRules } = useLoaderData<typeof loader>();+ const [params, setParams] = useUrlParams();+ const activeTab =+ (params.get("tab") as ApprovalDocumentType) || "purchaseOrder";return (<><div className="h-full w-full flex flex-col"><Tabs- defaultValue="purchaseOrder"+ value={activeTab}+ onValueChange={(value) => {+ setParams({ tab: value });+ }}className="h-full w-full flex flex-col"><div className="border-b border-border bg-card">diff --git a/apps/erp/app/routes/x+/settings+/approvals+/rules.$id.tsx b/apps/erp/app/routes/x+/settings+/approvals+/rules.$id.tsxindex 81fa1fef49..b2b95e2ce7 100644--- a/apps/erp/app/routes/x+/settings+/approvals+/rules.$id.tsx+++ b/apps/erp/app/routes/x+/settings+/approvals+/rules.$id.tsx@@ -133,7 +133,7 @@ export default function EditApprovalRuleRoute() {return (<ApprovalRuleDrawerrule={rule}- documentType={rule.documentType as "purchaseOrder" | "qualityDocument"}+ documentType={rule.documentType}groups={groups}onClose={onClose}/>diff --git a/apps/erp/app/routes/x+/settings+/approvals+/rules.new.tsx b/apps/erp/app/routes/x+/settings+/approvals+/rules.new.tsxindex b801e4946b..7f09716099 100644--- a/apps/erp/app/routes/x+/settings+/approvals+/rules.new.tsx+++ b/apps/erp/app/routes/x+/settings+/approvals+/rules.new.tsx@@ -5,7 +5,12 @@ import { validationError, validator } from "@carbon/form";import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";import { redirect, useLoaderData, useNavigate } from "react-router";import { useUrlParams } from "~/hooks";-import { approvalRuleValidator, upsertApprovalRule } from "~/modules/approvals";+import {+ type ApprovalDocumentType,+ approvalDocumentType,+ approvalRuleValidator,+ upsertApprovalRule+} from "~/modules/approvals";import ApprovalRuleDrawer from "~/modules/approvals/ui/ApprovalRuleDrawer";import { getParams, path } from "~/utils/path";@@ -16,18 +21,12 @@ export async function loader({ request }: LoaderFunctionArgs) {});const url = new URL(request.url);- const documentType = url.searchParams.get("documentType") as- | "purchaseOrder"- | "qualityDocument"- | null;+ const tab = url.searchParams.get("tab") as ApprovalDocumentType | null;- if (- !documentType ||- !["purchaseOrder", "qualityDocument"].includes(documentType)- ) {+ if (!tab || !approvalDocumentType.includes(tab)) {throw redirect(path.to.approvalSettings,- await flash(request, error(null, "Invalid document type"))+ await flash(request, error(null, "Invalid tab")));}@@ -40,7 +39,7 @@ export async function loader({ request }: LoaderFunctionArgs) {return {rule: null,- documentType,+ documentType: tab,groups: groupsResult.data ?? []};}@@ -74,14 +73,27 @@ export async function action({ request }: ActionFunctionArgs) {});if (result.error) {+ const tab =+ validation.data.documentType === "qualityDocument"+ ? "qualityDocument"+ : "purchaseOrder";throw redirect(- `${path.to.newApprovalRule(validation.data.documentType)}?${getParams(request)}`,+ `${path.to.newApprovalRule(tab)}?${getParams(request)}`,await flash(request, error(result.error, result.error.message)));}+ // Redirect to the appropriate tab based on document type+ const tab =+ validation.data.documentType === "qualityDocument"+ ? "qualityDocument"+ : "purchaseOrder";+ const existingParams = getParams(request);+ const params = new URLSearchParams(existingParams || "");+ params.set("tab", tab);+throw redirect(- `${path.to.approvalSettings}?${getParams(request)}`,+ `${path.to.approvalSettings}?${params.toString()}`,await flash(request, success("Approval rule created")));}diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.tsindex fae18887c5..97e9bd165b 100644--- a/apps/erp/app/utils/path.ts+++ b/apps/erp/app/utils/path.ts@@ -372,10 +372,8 @@ export const path = {approvalSettings: `${x}/settings/approvals`,approvalRule: (id: string) =>generatePath(`${x}/settings/approvals/rules/${id}`),- newApprovalRule: (documentType: string) =>- generatePath(- `${x}/settings/approvals/rules/new?documentType=${documentType}`- ),+ newApprovalRule: (tab: string) =>+ generatePath(`${x}/settings/approvals/rules/new?tab=${tab}`),deleteApprovalRule: (id: string) =>generatePath(`${x}/settings/approvals/rules/${id}/delete`),abilities: `${x}/resources/abilities`,