import { Badge, Button, Card, Group, Stack, Text } from "@mantine/core"; import type { UseMutationResult } from "@tanstack/react-query"; import { CheckCircle2, XCircle } from "lucide-react"; import type { PriorityRuleChangeRequest } from "@/services/ruleEngine/ruleEngine.service"; const ACTION_COLOR: Record = { CREATE: "teal", UPDATE: "blue", DELETE: "red", }; const fmtDateTime = (iso: string) => new Date(iso).toLocaleString("en-GB", { day: "numeric", month: "short", hour: "2-digit", minute: "2-digit", hour12: false, }); /** "WAGON 1–5 · 30 pts" from a change payload / target rule. */ const ruleSummary = ( r: PriorityRuleChangeRequest, ): string => { const source = (r.payload ?? r.priorityConfig ?? {}) as Record; const base = (r.priorityConfig ?? {}) as Record; const pick = (key: string) => source[key] ?? base[key]; const type = pick("type"); const currency = pick("currency"); const min = pick("minWagonCount"); const max = pick("maxWagonCount"); const pts = pick("scorePoints"); const parts = [ type ? String(type) : null, currency ? String(currency) : null, min != null && max != null ? `${min}–${max} wagons` : null, pts != null ? `${pts} pts` : null, ].filter(Boolean); return parts.join(" · ") || "—"; }; type Decide = UseMutationResult< PriorityRuleChangeRequest, unknown, { id: string; decisionNote?: string } >; interface PriorityRuleApprovalsSectionProps { requests: PriorityRuleChangeRequest[]; canDecide: boolean; approve: Decide; reject: Decide; } /** * Pending priority-rule change requests awaiting approval. Rendered above the * rules table on the priority-configs page; every rule change lands here first * and only an approval applies it. */ const PriorityRuleApprovalsSection = ({ requests, canDecide, approve, reject, }: PriorityRuleApprovalsSectionProps) => { if (requests.length === 0) return null; return ( Pending approvals {requests.length} {requests.map((r) => ( {r.action.toLowerCase()} {ruleSummary(r)} Submitted {fmtDateTime(r.createdAt)} {canDecide ? ( ) : null} ))} ); }; export default PriorityRuleApprovalsSection;