diff --git a/src/pages/Remittances.tsx b/src/pages/Remittances.tsx index 3a3f48b..38e4274 100644 --- a/src/pages/Remittances.tsx +++ b/src/pages/Remittances.tsx @@ -1,3 +1,4 @@ +import { useState } from "react"; import { Table, TableBody, @@ -7,13 +8,37 @@ import { TableRow, } from "@/components/ui/table"; import { RemitStatusBadge } from "@/components/StatusBadge"; -import { useAppStore } from "@/store"; +import { Skeleton } from "@/components/ui/skeleton"; +import { EmptyState } from "@/components/ui/empty-state"; +import { ErrorState } from "@/components/ui/error-state"; +import { FilterChips, type FilterChipOption } from "@/components/ui/filter-chips"; +import { Pagination } from "@/components/ui/pagination"; +import { useRemittances } from "@/hooks/useRemittances"; import { fmt } from "@/lib/format"; +import { cn } from "@/lib/utils"; +import type { RemittanceStatus } from "@/types"; + +const PAGE_SIZE = 25; + +const STATUS_OPTIONS: FilterChipOption[] = [ + { value: "received", label: "Received" }, + { value: "posted", label: "Posted" }, + { value: "reconciled", label: "Reconciled" }, +]; export function Remittances() { - const remits = useAppStore((s) => s.remittances); + const [page, setPage] = useState(1); + const [status, setStatus] = useState(null); - const total = remits.reduce( + const { data, isLoading, isError, error, refetch } = useRemittances({ + sort: "receivedDate", + order: "desc", + limit: PAGE_SIZE, + offset: (page - 1) * PAGE_SIZE, + }); + const items = data?.items ?? []; + + const total = items.reduce( (acc, r) => ({ paid: acc.paid + r.paidAmount, adjustments: acc.adjustments + r.adjustmentAmount, @@ -34,12 +59,20 @@ export function Remittances() {

+ {isError ? ( + refetch()} + /> + ) : null} +
Remits
-
{fmt.num(remits.length)}
+
{fmt.num(data?.total ?? 0)}
@@ -55,51 +88,78 @@ export function Remittances() {
+
+ { + setStatus((v as RemittanceStatus | null) ?? null); + setPage(1); + }} + eyebrow="Status" + /> +
+
- - - - Remit - Claim - Payer - Paid - Adjustment - Status - Received - - - - {remits.length === 0 ? ( - - - No remittances yet. - - - ) : ( - remits.map((r) => ( - - {r.id} - - {r.claimId} - - {r.payerName} - - {fmt.usdPrecise(r.paidAmount)} - - - {fmt.usdPrecise(r.adjustmentAmount)} - - - - - - {fmt.dateShort(r.receivedDate)} - + {isLoading ? ( +
+ {Array.from({ length: 5 }).map((_, i) => ( + + ))} +
+ ) : items.length === 0 ? ( + + ) : ( + <> +
+ + + Remit + Claim + Payer + Paid + Adjustment + Status + Received - )) - )} - -
+ + + {items.map((r) => ( + + {r.id} + + {r.claimId} + + {r.payerName} + + {fmt.usdPrecise(r.paidAmount)} + + + {fmt.usdPrecise(r.adjustmentAmount)} + + + + + + {fmt.dateShort(r.receivedDate)} + + + ))} + + +
+ +
+ + )}
);