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: LicenseRef-Carbon-Commercial
// Carbon Enterprise file, licensed only under the Carbon Commercial License
// (packages/ee/LICENSE). Not AGPL. Running, modifying, or copying it beyond those terms requires a commercial license.
import type { ApprovalDocumentType, ApprovalRule } from "@carbon/ee/approvals";
import { cn, HStack, VStack } from "@carbon/react";
import { Trans, useLingui } from "@lingui/react/macro";
import { memo } from "react";
import {
LuCalendar,
LuCircleCheck,
LuDollarSign,
LuUser,
LuUsers
} from "react-icons/lu";
import { DateTime, EmployeeAvatar } from "~/components";
import { UserSelect } from "~/components/Selectors";
type ApprovalRuleDetailsProps = {
rule: ApprovalRule & { approverGroupNames?: string[] };
documentType: ApprovalDocumentType;
currencyFormatter: Intl.NumberFormat;
};
type FieldItemProps = {
icon: React.ComponentType<{ className?: string }>;
label: string;
children: React.ReactNode;
className?: string;
};
const FieldItem = memo(
({ icon: Icon, label, children, className }: FieldItemProps) => (
<VStack spacing={2} className={cn("w-full justify-start", className)}>
<HStack spacing={2} className="items-center">
<div className="flex items-center justify-center w-6 h-6 rounded-md bg-muted/50 shrink-0">
<Icon className="h-3.5 w-3.5 text-muted-foreground" />
</div>
<p className="text-xs font-medium text-muted-foreground leading-tight">
{label}
</p>
</HStack>
<div className="pl-8 w-full">{children}</div>
</VStack>
)
);
FieldItem.displayName = "FieldItem";
const ApprovalRuleDetails = memo(
({ rule, documentType, currencyFormatter }: ApprovalRuleDetailsProps) => {
const { t } = useLingui();
return (
<VStack spacing={4} className="w-full">
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 w-full">
{documentType === "purchaseOrder" && (
<FieldItem icon={LuDollarSign} label={t`Minimum Amount`}>
<p className="text-sm font-semibold text-foreground leading-relaxed">
{currencyFormatter.format(rule.lowerBoundAmount ?? 0)}
</p>
</FieldItem>
)}
{/* Approver Groups */}
<FieldItem icon={LuUsers} label={t`Who Can Approve`}>
{rule.approverGroupIds && rule.approverGroupIds.length > 0 ? (
<UserSelect
value={rule.approverGroupIds ?? []}
readOnly
isMulti
className="w-full"
/>
) : (
<p className="text-sm text-muted-foreground leading-relaxed">
<Trans>No groups assigned</Trans>
</p>
)}
</FieldItem>
{/* Default Approver */}
<FieldItem icon={LuUser} label={t`Default Approver`}>
{rule.defaultApproverId ? (
<EmployeeAvatar employeeId={rule.defaultApproverId} />
) : (
<p className="text-sm text-muted-foreground leading-relaxed">
<Trans>Not set</Trans>
</p>
)}
</FieldItem>
{/* Escalation Days */}
{rule.escalationDays !== null &&
rule.escalationDays !== undefined && (
<FieldItem icon={LuCircleCheck} label={t`Escalation`}>
<p className="text-sm font-semibold text-foreground leading-relaxed">
{rule.escalationDays === 1 ? (
<Trans>1 day</Trans>
) : (
<Trans>{rule.escalationDays} days</Trans>
)}
</p>
</FieldItem>
)}
</div>
{/* Metadata Section */}
<div className="pt-6 border-t border-border w-full">
<div className="grid grid-cols-1 md:grid-cols-2 gap-6 w-full">
<FieldItem icon={LuUser} label={t`Created By`}>
<EmployeeAvatar employeeId={rule.createdBy} />
</FieldItem>
{rule.createdAt && (
<FieldItem icon={LuCalendar} label={t`Created At`}>
<p className="text-sm text-foreground leading-relaxed">
<DateTime value={rule.createdAt} variant="date" />
</p>
</FieldItem>
)}
</div>
</div>
</VStack>
);
}
);
ApprovalRuleDetails.displayName = "ApprovalRuleDetails";
export default ApprovalRuleDetails;