Spaces:
Running
Running
Download web/src/components/commerce/cod-view.tsx from Aynkhn/WorkPilot-AI: direct link, hf CLI and curl.
- Browser
- Download file 3.4 kB
-
https://huggingface.co/spaces/Aynkhn/WorkPilot-AI/resolve/main/web/src/components/commerce/cod-view.tsx
- Command line
-
hf download hf://spaces/Aynkhn/WorkPilot-AI/web/src/components/commerce/cod-view.tsx
-
curl -L -o cod-view.tsx https://huggingface.co/spaces/Aynkhn/WorkPilot-AI/resolve/main/web/src/components/commerce/cod-view.tsx
3.4 kB
| "use client"; | |
| import { BanknoteIcon } from "lucide-react"; | |
| import { isPackMissing, OrdersTable } from "@/components/commerce/orders-view"; | |
| import { EmptyState, ErrorState, PageHeader, StatTile } from "@/components/shell/page"; | |
| import { Skeleton } from "@/components/ui/skeleton"; | |
| import { formatMoney, formatNumber, formatPct } from "@/lib/format"; | |
| import { useI18n } from "@/lib/i18n"; | |
| import type { CodSummary, RiskBand } from "@/lib/types"; | |
| import { useApi } from "@/lib/use-api"; | |
| import { cn } from "@/lib/utils"; | |
| const BAND_BAR: Record<RiskBand, string> = { | |
| low: "bg-success", | |
| medium: "bg-warning", | |
| high: "bg-destructive", | |
| }; | |
| export function CodView() { | |
| const { t, m, locale } = useI18n(); | |
| const s = useApi<CodSummary>("/packs/ecommerce/cod/summary", { pollMs: 30_000 }); | |
| let body; | |
| if (s.error && isPackMissing(s.error)) { | |
| body = <EmptyState icon={BanknoteIcon} title={t("common.notAvailable")} hint={t("cod.unavailable")} />; | |
| } else if (s.error && !s.data) { | |
| body = <ErrorState error={s.error} onRetry={s.reload} />; | |
| } else if (!s.data) { | |
| body = <Skeleton className="h-40 w-full" />; | |
| } else { | |
| const d = s.data; | |
| const bandTotal = d.by_band.low + d.by_band.medium + d.by_band.high; | |
| body = ( | |
| <div className="space-y-5"> | |
| <div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-4" data-testid="cod-summary"> | |
| <StatTile label={t("cod.pending")} value={formatNumber(d.pending_confirmation)} /> | |
| <StatTile label={t("cod.confirmed")} value={formatNumber(d.confirmed)} /> | |
| <StatTile label={t("cod.rto")} value={formatPct(d.rto_rate, 1)} /> | |
| <StatTile label={t("cod.outstanding")} value={formatMoney(d.cod_outstanding, locale)} /> | |
| </div> | |
| <section className="rounded-lg border bg-card p-4"> | |
| <h2 className="mb-3 text-sm font-semibold">{t("cod.byBand")}</h2> | |
| <div className="flex h-3 overflow-hidden rounded-full bg-muted" role="img" aria-label={t("cod.byBand")}> | |
| {(["low", "medium", "high"] as const).map((b) => | |
| d.by_band[b] ? ( | |
| <div | |
| key={b} | |
| className={cn("h-full", BAND_BAR[b])} | |
| style={{ width: `${(d.by_band[b] / Math.max(1, bandTotal)) * 100}%` }} | |
| /> | |
| ) : null, | |
| )} | |
| </div> | |
| <dl className="mt-3 flex flex-wrap gap-6 text-sm"> | |
| {(["low", "medium", "high"] as const).map((b) => ( | |
| <div key={b} className="flex items-center gap-2"> | |
| <span className={cn("size-2 rounded-full", BAND_BAR[b])} aria-hidden /> | |
| <dt className="text-muted-foreground">{m.orders.bands[b]}</dt> | |
| <dd className="tabular font-medium">{formatNumber(d.by_band[b])}</dd> | |
| </div> | |
| ))} | |
| </dl> | |
| </section> | |
| <section className="space-y-2"> | |
| <h2 className="text-sm font-semibold">{t("cod.queue")}</h2> | |
| <OrdersTable | |
| testId="cod-queue" | |
| query={{ payment_method: "cod", status: "pending", limit: 50, offset: 0 }} | |
| /> | |
| </section> | |
| </div> | |
| ); | |
| } | |
| return ( | |
| <div className="space-y-5"> | |
| <PageHeader title={t("cod.title")} subtitle={t("cod.subtitle")} /> | |
| {body} | |
| </div> | |
| ); | |
| } | |