From 35ffe314479f3336985c8c446d588649bb4c4e48 Mon Sep 17 00:00:00 2001 From: Tyler Date: Sat, 20 Jun 2026 00:03:23 -0600 Subject: [PATCH] refactor(frontend): StatusBadge delegates to ClaimStateBadge; Claims uses API state --- src/components/StatusBadge.tsx | 47 +++++++++++++++++++++++++++++++++- src/pages/Claims.tsx | 4 +-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/components/StatusBadge.tsx b/src/components/StatusBadge.tsx index 0571546..9229ae0 100644 --- a/src/components/StatusBadge.tsx +++ b/src/components/StatusBadge.tsx @@ -1,5 +1,7 @@ import { Badge } from "@/components/ui/badge"; -import type { ClaimStatus, RemittanceStatus } from "@/types"; +import { ClaimStateBadge } from "@/components/ui/claim-state-badge"; +import type { ClaimState, ClaimStatus, RemittanceStatus } from "@/types"; +import { CLAIM_STATES } from "@/types"; import { cn } from "@/lib/utils"; const claimStyles: Record = { @@ -17,7 +19,47 @@ const remitStyles: Record = { reconciled: { dot: "bg-[hsl(var(--success))]", label: "Reconciled" }, }; +/** + * Generic status badge: delegates to `ClaimStateBadge` when the value is one + * of the seven canonical `ClaimState` values from the reconciliation model, + * otherwise falls back to a plain Badge with the legacy color. This is the + * single entry point that pages should use; it lets the live API's 7-state + * `state` field drive the visual while still tolerating legacy `status` + * strings like "draft" / "pending" that aren't part of the new model. + */ +export function StatusBadge({ + status, + className, +}: { + status: string; + className?: string; +}) { + if (CLAIM_STATES.includes(status as ClaimState)) { + return ( + + ); + } + return ( + + {status} + + ); +} + export function ClaimStatusBadge({ status }: { status: ClaimStatus }) { + // Forward to the canonical 7-state primitive when possible; fall back to + // the legacy dot+label for the three non-ClaimState values (draft, + // accepted, pending). + if (CLAIM_STATES.includes(status as ClaimState)) { + return ; + } const s = claimStyles[status]; return ( @@ -28,6 +70,9 @@ export function ClaimStatusBadge({ status }: { status: ClaimStatus }) { } export function RemitStatusBadge({ status }: { status: RemittanceStatus }) { + if (CLAIM_STATES.includes(status as ClaimState)) { + return ; + } const s = remitStyles[status]; return ( diff --git a/src/pages/Claims.tsx b/src/pages/Claims.tsx index 0055406..171b37b 100644 --- a/src/pages/Claims.tsx +++ b/src/pages/Claims.tsx @@ -16,7 +16,7 @@ import { TableHeader, TableRow, } from "@/components/ui/table"; -import { ClaimStatusBadge } from "@/components/StatusBadge"; +import { StatusBadge } from "@/components/StatusBadge"; import { NewClaimDialog } from "@/components/NewClaimDialog"; import { Skeleton } from "@/components/ui/skeleton"; import { EmptyState } from "@/components/ui/empty-state"; @@ -255,7 +255,7 @@ export function Claims() { {c.receivedAmount > 0 ? fmt.usd(c.receivedAmount) : "—"} - + {fmt.dateShort(c.submissionDate)}