changed dashboard

This commit is contained in:
Jelaletdin12
2026-10-23 23:21:33 +05:00
parent 6e626482f6
commit cbfb467651
11 changed files with 547 additions and 991 deletions

View File

@@ -1,13 +1,25 @@
import type { ReactNode } from "react";
import { useTranslation } from "react-i18next";
import { AlertCircle, RefreshCw } from "lucide-react";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { AlertCircle, Info, RefreshCw } from "lucide-react";
import { Skeleton } from "@/components/ui/skeleton";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import type { ElementType, ReactNode } from "react";
import { formatNumber } from "./analyticsFormat";
// ─── Section card with its own loading / error state ─────────────────────────
// ─── Register panel ───────────────────────────────────────────────────────────
// One bordered surface whose regions are divided by hairlines instead of being
// separate floating cards. This is the base container for every dashboard block.
interface RegisterPanelProps {
children: ReactNode;
className?: string;
}
export function RegisterPanel({ children, className }: RegisterPanelProps) {
return <div className={cn("overflow-hidden rounded-panel border border-border bg-card", className)}>{children}</div>;
}
// ─── One cell of a register (title + optional description + content) ─────────
interface SectionCardProps {
title: string;
@@ -15,6 +27,7 @@ interface SectionCardProps {
isLoading?: boolean;
isError?: boolean;
onRetry?: () => void;
/** Border classes that draw the cell dividers inside the parent register. */
className?: string;
contentClassName?: string;
action?: ReactNode;
@@ -36,26 +49,26 @@ export function SectionCard({
}: SectionCardProps) {
const { t } = useTranslation();
return (
<Card className={className}>
<CardHeader className="flex flex-row items-start justify-between gap-2 space-y-0">
<div className="space-y-1">
<CardTitle>{title}</CardTitle>
{description && <CardDescription>{description}</CardDescription>}
<div className={cn("px-5 py-4 lg:px-6 lg:py-5", className)}>
<div className="flex items-start justify-between gap-3">
<div className="min-w-0">
<p className="text-[14px] font-semibold tracking-tight">{title}</p>
{description && <p className="mt-1 text-[12.5px] text-muted-foreground">{description}</p>}
</div>
{action}
</CardHeader>
<CardContent className={contentClassName}>
</div>
<div className={cn("mt-5", contentClassName)}>
{isLoading ? (
<Skeleton className="w-full rounded-lg" style={{ height: skeletonHeight }} />
<Skeleton className="w-full rounded-md" style={{ height: skeletonHeight }} />
) : isError ? (
<div className="flex flex-col items-center justify-center gap-3 py-8 text-center" style={{ minHeight: skeletonHeight }}>
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-destructive/10 text-destructive">
<AlertCircle className="h-5 w-5" />
<div className="flex size-10 items-center justify-center rounded-full bg-destructive/10 text-destructive">
<AlertCircle className="size-5" aria-hidden="true" />
</div>
<p className="text-sm text-muted-foreground">{t("dashboard.errorTitle", "Maglumatlary ýükläp bolmady")}</p>
{onRetry && (
<Button variant="outline" size="sm" className="gap-2" onClick={onRetry}>
<RefreshCw className="h-3.5 w-3.5" />
<RefreshCw className="size-3.5" aria-hidden="true" />
{t("common.retry", "Täzeden synanyş")}
</Button>
)}
@@ -63,73 +76,23 @@ export function SectionCard({
) : (
children
)}
</CardContent>
</Card>
</div>
</div>
);
}
export function EmptyState({ height = 160 }: { height?: number }) {
const { t } = useTranslation();
return (
<div className="flex items-center justify-center text-xs text-muted-foreground" style={{ height }}>
<div className="flex items-center justify-center text-[13px] text-muted-foreground" style={{ height }}>
{t("dashboard.noData", "Maglumat ýok")}
</div>
);
}
// ─── KPI tile ─────────────────────────────────────────────────────────────────
interface KpiTileProps {
label: string;
value: string;
hint?: string;
icon: ElementType;
accent: string;
tone?: "default" | "good" | "warn" | "bad";
isLoading?: boolean;
}
export function KpiTile({ label, value, hint, icon: Icon, accent, tone = "default", isLoading }: KpiTileProps) {
return (
<Card>
<CardHeader className="flex flex-row items-center justify-between gap-2 space-y-0 pb-2">
<CardTitle className="min-w-0 text-sm font-medium text-muted-foreground">{label}</CardTitle>
<div className={cn("flex h-9 w-9 shrink-0 items-center justify-center rounded-lg", accent)}>
<Icon size={16} />
</div>
</CardHeader>
<CardContent className="@container/kpi">
{isLoading ? (
<>
<Skeleton className="h-8 w-28" />
<Skeleton className="mt-2 h-3 w-36" />
</>
) : (
<>
<p
className={cn(
"text-xl font-semibold tracking-tight tabular-nums @[14rem]/kpi:text-2xl @[18rem]/kpi:text-3xl",
tone === "good" && "text-emerald-600 dark:text-emerald-400",
tone === "warn" && "text-amber-600 dark:text-amber-400",
tone === "bad" && "text-destructive",
)}
>
{value}
</p>
{hint && (
<p className="mt-1 flex items-center gap-1.5 text-xs text-muted-foreground">
<span className="inline-block h-1.5 w-1.5 rounded-full bg-muted-foreground/40" />
{hint}
</p>
)}
</>
)}
</CardContent>
</Card>
);
}
// ─── Horizontal bar list (label · bar · value) ───────────────────────────────
// ─── Horizontal bar list (label · measured rule · value) ────────────────────
// The unfilled remainder is a 1px rule in the track tone and the value is a 3px
// bar sitting on it, so the chart reads like a measuring line, not a pill.
export interface BarListRow {
key: string;
@@ -156,33 +119,35 @@ export function BarList({ rows, color = "var(--chart-1)", hideEmpty }: BarListPr
const hidden = rows.length - visible.length;
const max = Math.max(1, ...rows.map((r) => r.value));
if (visible.length === 0) return <EmptyState height={120} />;
return (
<div className="space-y-3">
<div className="space-y-4">
{visible.map((row) => (
<div key={row.key} className="space-y-1">
<div className="flex items-baseline justify-between gap-3 text-sm">
<div key={row.key}>
<div className="flex items-baseline justify-between gap-3 text-[13.5px]">
<span className="min-w-0 truncate text-foreground" title={row.label}>
{row.label}
</span>
<span className="shrink-0 tabular-nums">{row.valueText ?? formatNumber(row.value)}</span>
</div>
<div className="h-2 w-full overflow-hidden rounded-full bg-muted">
<div className="relative mt-2.5 h-[2px] bg-track">
<div
className="h-full rounded-full transition-[width] duration-500"
className="absolute -top-[1.5px] left-0 h-[5px] rounded-[2px] transition-[width] duration-500"
style={{ width: `${row.share ?? (row.value / max) * 100}%`, background: color }}
/>
</div>
{row.sub && <div className="text-xs text-muted-foreground">{row.sub}</div>}
{row.sub && <div className="mt-2 text-[11.5px] text-muted-foreground">{row.sub}</div>}
</div>
))}
{hidden > 0 && (
<p
className="border-t pt-2 text-xs text-muted-foreground"
className="flex items-center gap-2 border-t border-border pt-3 text-[11.5px] text-muted-foreground"
title={rows
.filter((r) => r.value === 0)
.map((r) => r.label)
.join(", ")}
>
<Info className="size-3.5 shrink-0" aria-hidden="true" />
{t("analytics.emptyRows", "+{{count}} görnüşde sargyt ýok", { count: hidden })}
</p>
)}

View File

@@ -3,13 +3,12 @@ import { useTranslation } from "react-i18next";
import type { TFunction } from "i18next";
import { Info } from "lucide-react";
import { Cell, Pie, PieChart } from "recharts";
import { Card, CardContent } from "@/components/ui/card";
import { getEducationLabel, getMarriageLabel } from "@/constants/formOptions";
import { Skeleton } from "@/components/ui/skeleton";
import { ChartContainer, ChartTooltip, ChartTooltipContent } from "@/components/ui/chart";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { cn } from "@/lib/utils";
import type { ApprovalCount, CountItem, CustomersData, ProductsData } from "../api/analyticsApi";
import { BarList, EmptyState, SectionCard, type BarListRow } from "./analyticsShared";
import { BarList, EmptyState, RegisterPanel, SectionCard, type BarListRow } from "./analyticsShared";
import { formatNumber, formatPercent, useLocalizedName } from "./analyticsFormat";
interface QueryProps<T> {
@@ -19,16 +18,31 @@ interface QueryProps<T> {
onRetry: () => void;
}
// One meaning per color across the dashboard: blue = loans, green = cards / good, amber = waiting, red = rejected.
// One meaning per colour across the dashboard: teal = loans / approved,
// mid teal = cards, light teal = secondary share, sand = waiting, clay = rejected.
const LOAN_COLOR = "var(--chart-1)";
const CARD_COLOR = "var(--chart-2)";
const GOOD_COLOR = "var(--chart-2)";
const SHARE_COLOR = "var(--chart-3)";
const GOOD_COLOR = "var(--chart-1)";
const WAIT_COLOR = "var(--chart-4)";
const BAD_COLOR = "var(--chart-5)";
/** Below this many decided orders an approval rate is shown but flagged as unreliable. */
const MIN_DECIDED = 5;
/** Shared 2×2 cell dividers: vertical rule + row rule, collapsing to stacked rows on mobile. */
const CELL_BORDERS = [
"border-b border-border md:border-r",
"border-b border-border",
"border-b border-border md:border-b-0 md:border-r",
"border-b-0",
];
/** Donut geometry — the empty remainder is drawn as a static ring behind the chart. */
const DONUT_SIZE = 164;
const DONUT_INNER = 56;
const DONUT_OUTER = 72;
/** "3 sargyt · 60%" — count first, share muted. */
function CountShare({ count, percent }: { count: number; percent: number }) {
const { t } = useTranslation();
@@ -42,12 +56,12 @@ function CountShare({ count, percent }: { count: number; percent: number }) {
);
}
function InfoHint({ children }: { children: ReactNode }) {
function InfoHint({ children, className }: { children: ReactNode; className?: string }) {
return (
<Tooltip>
<TooltipTrigger asChild>
<button type="button" className="inline-flex cursor-help text-muted-foreground hover:text-foreground">
<Info className="h-3.5 w-3.5" />
<button type="button" className={cn("inline-flex cursor-help", className ?? "text-muted-foreground hover:text-foreground")}>
<Info className="size-3.5" aria-hidden="true" />
</button>
</TooltipTrigger>
<TooltipContent className="max-w-xs leading-relaxed">{children}</TooltipContent>
@@ -66,7 +80,7 @@ interface DonutRow {
function TotalDonut({ items, rows: rowDefs }: { items: CountItem[]; rows: DonutRow[] }) {
const { t } = useTranslation();
const byKey = new Map(items.map((it) => [it.key, it]));
// Fixed row order and colors, so "unpaid" is always amber and never swaps with "paid".
// Fixed row order and colors, so "unpaid" is always sand and never swaps with "paid".
const known = new Set(rowDefs.map((r) => r.key));
const extra = items.filter((it) => !known.has(it.key)).map((it) => ({ key: it.key, label: it.key, color: "var(--muted-foreground)" }));
const rows = [...rowDefs, ...extra].map((r) => ({
@@ -77,14 +91,36 @@ function TotalDonut({ items, rows: rowDefs }: { items: CountItem[]; rows: DonutR
const total = rows.reduce((s, r) => s + r.count, 0);
if (total === 0) return <EmptyState height={140} />;
const config = Object.fromEntries(rows.map((r) => [r.label, { label: r.label, color: r.color }]));
// Recharts derives its own slice angles; a pre-computed `percent` on the datum
// would be read as geometry, so the chart rows carry the count only.
const chartRows = rows.map(({ key, label, color, count }) => ({ key, label, color, count }));
const ringRadius = (DONUT_INNER + DONUT_OUTER) / 2;
return (
<div className="flex items-center gap-5">
<div className="relative h-[132px] w-[132px] shrink-0">
<ChartContainer config={config} className="h-full w-full">
<div className="flex flex-col items-start gap-6 sm:flex-row sm:items-center">
<div className="relative shrink-0" style={{ width: DONUT_SIZE, height: DONUT_SIZE }}>
<svg viewBox={`0 0 ${DONUT_SIZE} ${DONUT_SIZE}`} className="absolute inset-0 size-full" aria-hidden="true">
<circle
cx={DONUT_SIZE / 2}
cy={DONUT_SIZE / 2}
r={ringRadius}
fill="none"
stroke="var(--track)"
strokeWidth={DONUT_OUTER - DONUT_INNER}
/>
</svg>
<ChartContainer config={config} className="aspect-square h-full w-full">
<PieChart>
<Pie data={rows} dataKey="count" nameKey="label" innerRadius={44} outerRadius={64} strokeWidth={2} stroke="var(--card)">
{rows.map((r) => (
<Pie
data={chartRows}
dataKey="count"
nameKey="label"
innerRadius={DONUT_INNER}
outerRadius={DONUT_OUTER}
strokeWidth={3}
stroke="var(--card)"
>
{chartRows.map((r) => (
<Cell key={r.key} fill={r.color} />
))}
</Pie>
@@ -92,20 +128,20 @@ function TotalDonut({ items, rows: rowDefs }: { items: CountItem[]; rows: DonutR
</PieChart>
</ChartContainer>
<div className="pointer-events-none absolute inset-0 flex flex-col items-center justify-center">
<span className="text-2xl font-semibold tabular-nums leading-none">{formatNumber(total)}</span>
<span className="text-[26px] font-semibold leading-none tabular-nums tracking-tight">{formatNumber(total)}</span>
<span className="mt-1 text-[11px] text-muted-foreground">{t("analytics.kpi.orders", "sargyt")}</span>
</div>
</div>
<div className="min-w-0 flex-1 space-y-3">
<div className="min-w-0 flex-1 space-y-4">
{rows.map((r) => (
<div key={r.key} className="space-y-0.5">
<div className="flex items-center gap-2 text-sm">
<span className="h-2.5 w-2.5 shrink-0 rounded-full" style={{ background: r.color }} />
<span className="truncate">{r.label}</span>
</div>
<div className="pl-[18px] text-sm tabular-nums">
<CountShare count={r.count} percent={r.percent} />
<div key={r.key}>
<div className="flex items-center gap-2">
<span className="size-2.5 shrink-0 rounded-[3px]" style={{ background: r.color }} aria-hidden="true" />
<span className="truncate text-[13.5px]">{r.label}</span>
</div>
<p className="mt-1.5 pl-5 text-[12.5px] tabular-nums text-muted-foreground">
{formatNumber(r.count)} <span className="text-muted-foreground/70">{formatNumber(r.percent, 1)}%</span>
</p>
</div>
))}
</div>
@@ -118,7 +154,7 @@ function TotalDonut({ items, rows: rowDefs }: { items: CountItem[]; rows: DonutR
export function ProductsSection({ data, isLoading, isError, onRetry }: QueryProps<ProductsData>) {
const { t } = useTranslation();
const localized = useLocalizedName();
const common = { isLoading, isError, onRetry, skeletonHeight: 150 };
const common = { isLoading, isError, onRetry, skeletonHeight: 170 };
const toRows = (items: ProductsData["loanTypes"]): BarListRow[] =>
items.map((it) => ({
@@ -130,60 +166,66 @@ export function ProductsSection({ data, isLoading, isError, onRetry }: QueryProp
}));
return (
<div className="grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-4">
<SectionCard
title={t("analytics.products.sources", "Karz: Web we mobil")}
description={t("analytics.products.sourcesDesc", "Karz sargytlary nireden iberildi")}
{...common}
>
<TotalDonut
items={data?.loanSources ?? []}
rows={[
{ key: "mobile", label: t("analytics.source.mobile", "Mobil"), color: LOAN_COLOR },
{ key: "web", label: t("analytics.source.web", "Web"), color: "var(--chart-3)" },
]}
/>
</SectionCard>
<SectionCard
title={t("analytics.products.cardPaid", "Kart sargytlary: töleg")}
description={t("analytics.products.cardPaidDesc", "Kart sargytlarynyň näçesi tölendi")}
{...common}
>
<TotalDonut
items={data?.cardOrderPay ?? []}
rows={[
{ key: "paid", label: t("analytics.paid", "Tölenen"), color: GOOD_COLOR },
{ key: "unpaid", label: t("analytics.unpaid", "Tölenmedik"), color: WAIT_COLOR },
]}
/>
</SectionCard>
<SectionCard
title={t("analytics.products.loanTypes", "Karz görnüşleri")}
description={t("analytics.products.loanTypesDesc", "Her görnüşiň ähli karz sargytlaryndaky paýy")}
{...common}
>
<BarList rows={toRows(data?.loanTypes ?? [])} color={LOAN_COLOR} hideEmpty />
</SectionCard>
<SectionCard
title={t("analytics.products.cardTypes", "Kart görnüşleri")}
description={t("analytics.products.cardTypesDesc", "Her görnüşiň ähli kart sargytlaryndaky paýy")}
{...common}
>
<BarList rows={toRows(data?.cardTypes ?? [])} color={CARD_COLOR} hideEmpty />
</SectionCard>
</div>
<RegisterPanel>
<div className="grid grid-cols-1 md:grid-cols-2">
<SectionCard
className={CELL_BORDERS[0]}
title={t("analytics.products.sources", "Karz: Web we mobil")}
description={t("analytics.products.sourcesDesc", "Karz sargytlary nireden iberildi")}
{...common}
>
<TotalDonut
items={data?.loanSources ?? []}
rows={[
{ key: "mobile", label: t("analytics.source.mobile", "Mobil"), color: LOAN_COLOR },
{ key: "web", label: t("analytics.source.web", "Web"), color: SHARE_COLOR },
]}
/>
</SectionCard>
<SectionCard
className={CELL_BORDERS[1]}
title={t("analytics.products.cardPaid", "Kart sargytlary: töleg")}
description={t("analytics.products.cardPaidDesc", "Kart sargytlarynyň näçesi tölendi")}
{...common}
>
<TotalDonut
items={data?.cardOrderPay ?? []}
rows={[
{ key: "paid", label: t("analytics.paid", "Tölenen"), color: GOOD_COLOR },
{ key: "unpaid", label: t("analytics.unpaid", "Tölenmedik"), color: WAIT_COLOR },
]}
/>
</SectionCard>
<SectionCard
className={CELL_BORDERS[2]}
title={t("analytics.products.loanTypes", "Karz görnüşleri")}
description={t("analytics.products.loanTypesDesc", "Her görnüşiň ähli karz sargytlaryndaky paýy")}
{...common}
>
<BarList rows={toRows(data?.loanTypes ?? [])} color={LOAN_COLOR} hideEmpty />
</SectionCard>
<SectionCard
className={CELL_BORDERS[3]}
title={t("analytics.products.cardTypes", "Kart görnüşleri")}
description={t("analytics.products.cardTypesDesc", "Her görnüşiň ähli kart sargytlaryndaky paýy")}
{...common}
>
<BarList rows={toRows(data?.cardTypes ?? [])} color={CARD_COLOR} hideEmpty />
</SectionCard>
</div>
</RegisterPanel>
);
}
// ─── Customers ────────────────────────────────────────────────────────────────
/** Approved / rejected / waiting counts as colored dots, then the approval rate. */
/** Approved / rejected / waiting counts as marked dots, then the approval rate. */
function Outcome({ item, t }: { item: ApprovalCount; t: TFunction }) {
const decided = item.approved + item.rejected;
const parts = [
{ n: item.approved, color: GOOD_COLOR, label: t("analytics.outcome.approved", "tassyklandy") },
{ n: item.rejected, color: BAD_COLOR, label: t("analytics.outcome.rejected", "ret edildi") },
{ n: item.open, color: WAIT_COLOR, label: t("analytics.outcome.open", "garaşýar") },
{ n: item.open, color: WAIT_COLOR, label: t("analytics.outcome.open", "garaşýar"), pending: true },
].filter((p) => p.n > 0);
const fewData = decided > 0 && decided < MIN_DECIDED;
@@ -194,7 +236,11 @@ function Outcome({ item, t }: { item: ApprovalCount; t: TFunction }) {
<span className="flex min-w-0 flex-wrap items-center gap-x-2.5 gap-y-0.5">
{parts.map((p) => (
<span key={p.label} className="inline-flex items-center gap-1 whitespace-nowrap">
<span className="h-1.5 w-1.5 rounded-full" style={{ background: p.color }} />
<span
className={cn("size-2 shrink-0 rounded-full", p.pending && "border border-dashed bg-transparent")}
style={p.pending ? { borderColor: p.color } : { background: p.color }}
aria-hidden="true"
/>
{formatNumber(p.n)} {p.label}
</span>
))}
@@ -214,7 +260,7 @@ function Outcome({ item, t }: { item: ApprovalCount; t: TFunction }) {
>
{formatPercent(item.approvalRate)}
</span>
<span className="text-muted-foreground">
<span className="text-muted-foreground/80">
{formatNumber(item.approved)}/{formatNumber(decided)}
</span>
</span>
@@ -241,62 +287,103 @@ function approvalRows(items: ApprovalCount[], labelFor: (key: string) => string,
}));
}
function SummaryStat({ label, value, color, hint }: { label: string; value: string; color?: string; hint?: ReactNode }) {
// ─── Anchor band: the five headline customer metrics on one dark surface ────
function BandStat({ label, value, color, pending }: { label: string; value: string; color?: string; pending?: boolean }) {
return (
<div className="min-w-0 space-y-1">
<p className="flex items-center gap-1.5 text-xs text-muted-foreground">
{color && <span className="h-2 w-2 shrink-0 rounded-full" style={{ background: color }} />}
<div className="min-w-0">
<p className="flex items-center gap-1.5 text-[11.5px] font-medium uppercase tracking-[0.07em] text-surface-strong-muted">
{color && (
<span
className={cn("size-2 shrink-0 rounded-full", pending && "border border-dashed bg-transparent")}
style={pending ? { borderColor: color } : { background: color }}
aria-hidden="true"
/>
)}
<span className="truncate">{label}</span>
{hint && <InfoHint>{hint}</InfoHint>}
</p>
<p className="text-2xl font-semibold tabular-nums tracking-tight">{value}</p>
<p className="mt-2.5 text-[28px] font-semibold leading-none tracking-tight tabular-nums text-surface-strong-foreground">{value}</p>
</div>
);
}
function CustomersSummary({ data, isLoading }: { data?: CustomersData; isLoading: boolean }) {
const { t } = useTranslation();
// The endpoint reports totals per dimension but may omit the headline counts.
// When they are absent, ages are the one dimension that covers every applicant,
// so they are the honest source for the band.
const fromGroups = data?.ageGroups?.length
? data.ageGroups.reduce(
(acc, g) => ({
approved: acc.approved + (g.approved ?? 0),
rejected: acc.rejected + (g.rejected ?? 0),
open: acc.open + (g.open ?? 0),
}),
{ approved: 0, rejected: 0, open: 0 },
)
: undefined;
const approved = data?.approved ?? fromGroups?.approved;
const rejected = data?.rejected ?? fromGroups?.rejected;
const open = data?.open ?? fromGroups?.open;
const decided = (approved ?? 0) + (rejected ?? 0);
const approvalRate = data?.approvalRate ?? (decided > 0 ? ((approved ?? 0) / decided) * 100 : null);
const rateValue = formatPercent(approvalRate);
const width = typeof approvalRate === "number" ? `${Math.min(100, Math.max(0, approvalRate))}%` : "0%";
const rateHint = t(
"analytics.customers.approvalHint",
"Tassyklama derejesi = tassyklanan ÷ (tassyklanan + ret edilen). Garaşýan sargytlar hasaba alynmaýar.",
"Tassyklama derejesi = tassyklanan ÷ (tasyklanan + ret edilen). Garaşýan sargytlar hasaba alynmaýar.",
);
return (
<Card>
<CardContent className="grid grid-cols-2 gap-x-6 gap-y-4 sm:grid-cols-3 lg:grid-cols-5">
{isLoading ? (
Array.from({ length: 5 }, (_, i) => <Skeleton key={i} className="h-12 w-full" />)
) : (
<>
<SummaryStat label={t("analytics.customers.totalOrders", "Jemi karz sargytlary")} value={formatNumber(data?.total)} />
<SummaryStat
label={t("analytics.outcome.approvedTitle", "Tassyklandy")}
value={formatNumber(data?.approved)}
color={GOOD_COLOR}
/>
<SummaryStat
label={t("analytics.outcome.rejectedTitle", "Ret edildi")}
value={formatNumber(data?.rejected)}
color={BAD_COLOR}
/>
<SummaryStat label={t("analytics.outcome.openTitle", "Garaşýar")} value={formatNumber(data?.open)} color={WAIT_COLOR} />
<SummaryStat
label={t("analytics.customers.approvalRate", "Tassyklama derejesi")}
value={formatPercent(data?.approvalRate)}
hint={rateHint}
/>
</>
)}
</CardContent>
</Card>
<div className="rounded-panel bg-surface-strong px-5 py-[18px] lg:px-7">
{isLoading ? (
<div className="grid grid-cols-2 gap-x-6 gap-y-4 sm:grid-cols-3 lg:grid-cols-5">
{Array.from({ length: 5 }, (_, i) => (
<div key={i} className="h-10 animate-pulse rounded-md bg-surface-strong-foreground/10" />
))}
</div>
) : (
<div className="grid grid-cols-2 gap-x-6 gap-y-4 sm:grid-cols-3 lg:grid-cols-5 lg:items-end">
<BandStat label={t("analytics.customers.totalOrders", "Jemi karz sargytlary")} value={formatNumber(data?.total)} />
<BandStat label={t("analytics.outcome.approvedTitle", "Tassyklandy")} value={formatNumber(approved)} color="var(--chart-3)" />
<BandStat label={t("analytics.outcome.rejectedTitle", "Ret edildi")} value={formatNumber(rejected)} color="var(--chart-5)" />
<BandStat label={t("analytics.outcome.openTitle", "Garaşýar")} value={formatNumber(open)} color="var(--chart-4)" pending />
<div className="min-w-0">
<p className="flex items-center gap-1.5 text-[11.5px] font-medium uppercase tracking-[0.07em] text-surface-strong-muted">
<span className="truncate">{t("analytics.customers.approvalRate", "Tassyklama derejesi")}</span>
<InfoHint className="text-surface-strong-muted hover:text-surface-strong-foreground">{rateHint}</InfoHint>
</p>
<p className="mt-2.5 text-[28px] font-semibold leading-none tracking-tight tabular-nums text-surface-strong-foreground">
{rateValue}
</p>
<span className="mt-3 block h-1 w-full overflow-hidden rounded-full bg-surface-strong-foreground/15">
<span className="block h-full rounded-full bg-surface-strong-foreground/70" style={{ width }} />
</span>
</div>
</div>
)}
</div>
);
}
export function CustomersSection({ data, isLoading, isError, onRetry }: QueryProps<CustomersData>) {
interface CustomersSectionProps extends QueryProps<CustomersData> {
/** Product breakdown is a sibling query, passed in so both blocks refresh together. */
products: QueryProps<ProductsData>;
}
export function CustomersSection({ data, isLoading, isError, onRetry, products }: CustomersSectionProps) {
const { t } = useTranslation();
// One error card instead of four identical ones.
if (isError) {
return <SectionCard title={t("analytics.customers.title", "Müşderiler")} isError onRetry={onRetry} skeletonHeight={160} />;
return (
<RegisterPanel>
<SectionCard title={t("analytics.customers.title", "Müşderiler")} isError onRetry={onRetry} skeletonHeight={160} />
</RegisterPanel>
);
}
const unknown = t("analytics.unknown", "Näbelli");
@@ -319,20 +406,34 @@ export function CustomersSection({ data, isLoading, isError, onRetry }: QueryPro
];
return (
<div className="space-y-4">
<div className="space-y-2">
<p className="text-sm text-muted-foreground">
{t("analytics.customers.desc", "Saýlanan döwürde karz sargydyny berenleriň profili")}
</p>
<CustomersSummary data={data} isLoading={isLoading} />
</div>
<div className="grid grid-cols-1 gap-4 md:grid-cols-2 2xl:grid-cols-4">
{cards.map((c) => (
<SectionCard key={c.title} title={c.title} isLoading={isLoading} skeletonHeight={180}>
<BarList rows={approvalRows(c.items ?? [], c.label, t)} color={LOAN_COLOR} />
</SectionCard>
))}
</div>
<div className="space-y-3.5">
<CustomersSummary data={data} isLoading={isLoading} />
<ProductsSection {...products} />
<RegisterPanel>
<div className="flex flex-col gap-1 border-b border-border px-5 py-3.5 sm:flex-row sm:items-baseline sm:justify-between lg:px-6">
<p className="text-[13px] text-muted-foreground">
{t("analytics.customers.desc", "Saýlanan döwürde karz sargydyny berenleriň profili")}
</p>
<span className="flex items-center gap-1.5 text-[11.5px] text-muted-foreground/80">
{t("analytics.customers.approvalRate", "Tassyklama derejesi")}
<InfoHint>
{t(
"analytics.customers.approvalHint",
"Tassyklama derejesi = tassyklanan ÷ (tasyklanan + ret edilen). Garaşýan sargytlar hasaba alynmaýar.",
)}
</InfoHint>
</span>
</div>
<div className="grid grid-cols-1 md:grid-cols-2">
{cards.map((c, i) => (
<SectionCard key={c.title} className={CELL_BORDERS[i]} title={c.title} isLoading={isLoading} skeletonHeight={180}>
<BarList rows={approvalRows(c.items ?? [], c.label, t)} color={LOAN_COLOR} />
</SectionCard>
))}
</div>
</RegisterPanel>
</div>
);
}

View File

@@ -179,6 +179,12 @@ function PayForm({ id, isPaying, onSubmit, onCancel }: PayFormProps) {
<dd>{quote.tvebFeeTmt} TMT</dd>
</div>
)}
{quote.maxAmountTmt != null && (
<div className="flex justify-between gap-4">
<dt className="text-muted-foreground">{t("intlPayment.pay.maxAmount", "Iň ýokary möçberi")}</dt>
<dd>{quote.maxAmountTmt} TMT</dd>
</div>
)}
</dl>
) : null}