connected with dashboard api
This commit is contained in:
@@ -1,85 +1,51 @@
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
ArrowUpRight,
|
||||
ArrowDownRight,
|
||||
FileText,
|
||||
CreditCard,
|
||||
Users,
|
||||
DollarSign,
|
||||
Activity,
|
||||
AlertCircle,
|
||||
CheckCircle2,
|
||||
XCircle,
|
||||
} from "lucide-react";
|
||||
import { ArrowUpRight, ArrowDownRight, FileText, CreditCard, Users, DollarSign, Activity, AlertCircle, RefreshCw } from "lucide-react";
|
||||
import { AreaChart, Area, BarChart, Bar, XAxis, YAxis, CartesianGrid, PieChart, Pie, Cell } from "recharts";
|
||||
import { ChartContainer, ChartTooltip, ChartTooltipContent, ChartLegend, ChartLegendContent } from "@/components/ui/chart";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { cn, formatFromApiDate } from "@/lib/utils";
|
||||
import { StatusCell, getStatusLabel } from "@/constants";
|
||||
import { useDashboardOverview } from "@/features/dashboard/hooks/useDashboard";
|
||||
|
||||
// ─── Mock data ────────────────────────────────────────────────────────────────
|
||||
// ─── Status Colors for Diagrams ───────────────────────────────────────────────
|
||||
|
||||
const areaData = [
|
||||
{ month: "Ýan", loans: 420, cards: 240 },
|
||||
{ month: "Few", loans: 380, cards: 290 },
|
||||
{ month: "Mar", loans: 510, cards: 310 },
|
||||
{ month: "Apr", loans: 470, cards: 280 },
|
||||
{ month: "Maý", loans: 630, cards: 390 },
|
||||
{ month: "Iýun", loans: 580, cards: 420 },
|
||||
{ month: "Iýul", loans: 720, cards: 460 },
|
||||
{ month: "Awg", loans: 690, cards: 500 },
|
||||
{ month: "Sen", loans: 810, cards: 530 },
|
||||
{ month: "Okt", loans: 760, cards: 480 },
|
||||
{ month: "Noý", loans: 890, cards: 560 },
|
||||
{ month: "Dek", loans: 950, cards: 610 },
|
||||
];
|
||||
const STATUS_CHART_COLORS: Record<string, string> = {
|
||||
satisfied: "var(--chart-2)",
|
||||
approved: "var(--chart-2)",
|
||||
pending: "var(--chart-4)",
|
||||
processing: "var(--chart-1)",
|
||||
cancelled: "var(--chart-5)",
|
||||
rejected: "var(--chart-5)",
|
||||
registered: "var(--chart-3)",
|
||||
completed: "var(--chart-2)",
|
||||
};
|
||||
|
||||
const barData = [
|
||||
{ day: "Du", approved: 28, rejected: 4 },
|
||||
{ day: "Si", approved: 35, rejected: 6 },
|
||||
{ day: "Ça", approved: 22, rejected: 3 },
|
||||
{ day: "Pe", approved: 41, rejected: 8 },
|
||||
{ day: "An", approved: 33, rejected: 5 },
|
||||
{ day: "Şe", approved: 18, rejected: 2 },
|
||||
{ day: "Ýe", approved: 12, rejected: 1 },
|
||||
];
|
||||
// ─── Relative time helper ─────────────────────────────────────────────────────
|
||||
|
||||
const pieData = [
|
||||
{ name: "Kanagatlandyrylan", value: 6746, key: "approved" },
|
||||
{ name: "Garaşylýar", value: 208, key: "pending" },
|
||||
{ name: "Işlenilýär", value: 157, key: "processing" },
|
||||
{ name: "Ýatyrylan", value: 245, key: "rejected" },
|
||||
{ name: "Bellige alyndy", value: 450, key: "registered" },
|
||||
];
|
||||
|
||||
const recentActivity = [
|
||||
{ id: "#KS-2841", name: "Serdar Annagurban", amount: "12 500 TMT", status: "approved", time: "2 min öň" },
|
||||
{ id: "#KS-2840", name: "Aýgül Myradowa", amount: "8 000 TMT", status: "pending", time: "14 min öň" },
|
||||
{ id: "#KS-2839", name: "Kakajan Durdyýew", amount: "25 000 TMT", status: "approved", time: "31 min öň" },
|
||||
{ id: "#KS-2838", name: "Ogulgerek Sähedowa", amount: "5 500 TMT", status: "rejected", time: "1 sa öň" },
|
||||
{ id: "#KS-2837", name: "Merdan Hojamyradow", amount: "18 000 TMT", status: "approved", time: "2 sa öň" },
|
||||
];
|
||||
|
||||
// ─── Chart configs ────────────────────────────────────────────────────────────
|
||||
|
||||
const areaConfig = {
|
||||
loans: { label: "Karzlar", color: "var(--chart-1)" },
|
||||
cards: { label: "Kartlar", color: "var(--chart-2)" },
|
||||
} satisfies Record<string, { label: string; color: string }>;
|
||||
|
||||
const barConfig = {
|
||||
approved: { label: "Tassyklanan", color: "var(--chart-1)" },
|
||||
rejected: { label: "Ýatyryldy", color: "var(--chart-5)" },
|
||||
} satisfies Record<string, { label: string; color: string }>;
|
||||
|
||||
const pieConfig = {
|
||||
approved: { label: "Kanagatlandyrylan", color: "var(--chart-2)" },
|
||||
pending: { label: "Garaşylýar", color: "var(--chart-4)" },
|
||||
processing: { label: "Işlenilýär", color: "var(--chart-1)" },
|
||||
rejected: { label: "Ýatyrylan", color: "var(--chart-5)" },
|
||||
registered: { label: "Bellige alyndy", color: "var(--chart-3)" },
|
||||
} satisfies Record<string, { label: string; color: string }>;
|
||||
function formatRelativeTime(dateStr?: string | null): string {
|
||||
if (!dateStr) return "—";
|
||||
try {
|
||||
const d = new Date(dateStr);
|
||||
if (isNaN(d.getTime())) return dateStr;
|
||||
const now = new Date();
|
||||
const diffMs = now.getTime() - d.getTime();
|
||||
const diffSec = Math.floor(diffMs / 1000);
|
||||
if (diffSec < 60) return "Ýaňyja";
|
||||
const diffMin = Math.floor(diffSec / 60);
|
||||
if (diffMin < 60) return `${diffMin} min öň`;
|
||||
const diffHours = Math.floor(diffMin / 60);
|
||||
if (diffHours < 24) return `${diffHours} sag öň`;
|
||||
const diffDays = Math.floor(diffHours / 24);
|
||||
if (diffDays < 7) return `${diffDays} gün öň`;
|
||||
return formatFromApiDate(dateStr);
|
||||
} catch {
|
||||
return dateStr;
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Stat card ────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -89,14 +55,20 @@ function StatCard({
|
||||
change,
|
||||
icon: Icon,
|
||||
accent,
|
||||
comparedToText,
|
||||
totalActiveText,
|
||||
}: {
|
||||
title: string;
|
||||
value: string;
|
||||
change: number;
|
||||
value: string | number;
|
||||
change: number | null | undefined;
|
||||
icon: React.ElementType;
|
||||
accent: string;
|
||||
comparedToText: string;
|
||||
totalActiveText: string;
|
||||
}) {
|
||||
const positive = change >= 0;
|
||||
const hasChange = change !== null && change !== undefined;
|
||||
const positive = (change ?? 0) >= 0;
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between pb-2 space-y-0">
|
||||
@@ -107,15 +79,22 @@ function StatCard({
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-3xl font-semibold tracking-tight">{value}</p>
|
||||
<p
|
||||
className={cn(
|
||||
"mt-1 flex items-center gap-1 text-xs font-medium",
|
||||
positive ? "text-emerald-600 dark:text-emerald-400" : "text-destructive",
|
||||
)}
|
||||
>
|
||||
{positive ? <ArrowUpRight size={13} /> : <ArrowDownRight size={13} />}
|
||||
{Math.abs(change)}% geçen aýa garanyňda
|
||||
</p>
|
||||
{hasChange ? (
|
||||
<p
|
||||
className={cn(
|
||||
"mt-1 flex items-center gap-1 text-xs font-medium",
|
||||
positive ? "text-emerald-600 dark:text-emerald-400" : "text-destructive",
|
||||
)}
|
||||
>
|
||||
{positive ? <ArrowUpRight size={13} /> : <ArrowDownRight size={13} />}
|
||||
{Math.abs(change)}% {comparedToText}
|
||||
</p>
|
||||
) : (
|
||||
<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" />
|
||||
{totalActiveText}
|
||||
</p>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
@@ -136,32 +115,62 @@ function StatCardSkeleton() {
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Status badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_CONFIG: Record<string, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }> = {
|
||||
approved: { label: "Tassyklandy", variant: "success", icon: CheckCircle2 },
|
||||
pending: { label: "Garaşylýar", variant: "warning", icon: AlertCircle },
|
||||
rejected: { label: "Ýatyryldy", variant: "error", icon: XCircle },
|
||||
};
|
||||
|
||||
function DashboardStatusBadge({ status }: { status: string }) {
|
||||
const cfg = STATUS_CONFIG[status];
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{status}</span>;
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />;
|
||||
}
|
||||
|
||||
// ─── Page ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
export default function DashboardPage({ isLoading = false }: { isLoading?: boolean }) {
|
||||
export default function DashboardPage({ isLoading: propLoading = false }: { isLoading?: boolean }) {
|
||||
const { t } = useTranslation();
|
||||
const total = pieData.reduce((s, d) => s + d.value, 0);
|
||||
const currentYear = new Date().getFullYear();
|
||||
const [selectedYear, setSelectedYear] = useState<number>(currentYear);
|
||||
|
||||
const {
|
||||
data: overviewData,
|
||||
isLoading: isQueryLoading,
|
||||
isFetching,
|
||||
isError,
|
||||
error,
|
||||
refetch,
|
||||
} = useDashboardOverview({
|
||||
year: selectedYear,
|
||||
recent_limit: 10,
|
||||
});
|
||||
|
||||
const isLoading = propLoading || isQueryLoading;
|
||||
|
||||
// Chart configs using translations
|
||||
const areaConfig = {
|
||||
loans: { label: t("dashboard.loans", "Karzlar"), color: "var(--chart-1)" },
|
||||
cards: { label: t("dashboard.cards", "Kartlar"), color: "var(--chart-2)" },
|
||||
};
|
||||
|
||||
const barConfig = {
|
||||
loans: { label: t("dashboard.loans", "Karzlar"), color: "var(--chart-1)" },
|
||||
cards: { label: t("dashboard.cards", "Kartlar"), color: "var(--chart-2)" },
|
||||
};
|
||||
|
||||
const pieConfig = {
|
||||
satisfied: { label: t("status.satisfied", "Kanagatlandyryldy"), color: "var(--chart-2)" },
|
||||
approved: { label: t("status.approved", "Tassyklandy"), color: "var(--chart-2)" },
|
||||
pending: { label: t("status.pending", "Garaşylýar"), color: "var(--chart-4)" },
|
||||
processing: { label: t("status.processing", "Işlenilýär"), color: "var(--chart-1)" },
|
||||
cancelled: { label: t("status.cancelled", "Ýatyrylan"), color: "var(--chart-5)" },
|
||||
rejected: { label: t("status.rejected", "Ýatyryldy"), color: "var(--chart-5)" },
|
||||
registered: { label: t("status.registered", "Bellige alyndy"), color: "var(--chart-3)" },
|
||||
completed: { label: t("status.completed", "Tamamlandy"), color: "var(--chart-2)" },
|
||||
};
|
||||
|
||||
// Render Skeleton loading state
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="w-full space-y-6">
|
||||
<div className="space-y-1.5">
|
||||
<Skeleton className="h-7 w-40" />
|
||||
<Skeleton className="h-4 w-64" />
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
|
||||
<div className="space-y-1.5">
|
||||
<Skeleton className="h-7 w-40" />
|
||||
<Skeleton className="h-4 w-64" />
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Skeleton className="h-9 w-28" />
|
||||
<Skeleton className="h-9 w-9" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 lg:grid-cols-4 gap-4">
|
||||
@@ -303,112 +312,240 @@ export default function DashboardPage({ isLoading = false }: { isLoading?: boole
|
||||
);
|
||||
}
|
||||
|
||||
// Error State
|
||||
if (isError) {
|
||||
return (
|
||||
<div className="w-full flex flex-col items-center justify-center p-12 text-center border rounded-xl bg-card space-y-4">
|
||||
<div className="h-12 w-12 rounded-full bg-destructive/10 text-destructive flex items-center justify-center">
|
||||
<AlertCircle className="h-6 w-6" />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-lg font-semibold">{t("dashboard.errorTitle", "Maglumatlary ýükläp bolmady")}</h3>
|
||||
<p className="text-sm text-muted-foreground mt-1 max-w-md">
|
||||
{(error as Error)?.message || t("dashboard.errorMessage", "Serwer bilen baglanyşykda säwlik ýüze çykdy.")}
|
||||
</p>
|
||||
</div>
|
||||
<Button onClick={() => refetch()} variant="outline" className="gap-2">
|
||||
<RefreshCw className="h-4 w-4" />
|
||||
{t("common.retry", "Täzeden synanyş")}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Prepared data
|
||||
const stats = overviewData?.stats;
|
||||
const trendPoints = overviewData?.trend?.points || [];
|
||||
const areaData = trendPoints.map((pt) => ({
|
||||
month: t(`dashboard.months.${pt.month}`, `${pt.month}`),
|
||||
loans: pt.loans,
|
||||
cards: pt.cards,
|
||||
}));
|
||||
|
||||
const loanStatusItems = overviewData?.loanStatus || [];
|
||||
const pieData = loanStatusItems.map((item) => {
|
||||
const label = getStatusLabel(item.status, t, "status");
|
||||
const color = STATUS_CHART_COLORS[item.status] || "var(--chart-1)";
|
||||
return {
|
||||
name: label,
|
||||
value: item.count,
|
||||
percent: item.percent,
|
||||
key: item.status,
|
||||
color,
|
||||
};
|
||||
});
|
||||
const totalLoanStatus = pieData.reduce((s, d) => s + d.value, 0);
|
||||
|
||||
const weeklyOrders = overviewData?.weeklyOrders || [];
|
||||
const barData = weeklyOrders.map((item) => ({
|
||||
day: t(`dashboard.weekdays.${item.weekday}`, `${item.weekday}`),
|
||||
date: item.date,
|
||||
loans: item.loans,
|
||||
cards: item.cards,
|
||||
}));
|
||||
|
||||
const recentActivity = overviewData?.recentActivity || [];
|
||||
|
||||
const yearOptions = [currentYear - 2, currentYear - 1, currentYear, currentYear + 1];
|
||||
|
||||
return (
|
||||
<div className="w-full space-y-6">
|
||||
{/* Header */}
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold tracking-tight">{t("Dashboard", "Baş sahypa")}</h1>
|
||||
<p className="text-sm text-muted-foreground mt-0.5">{t("Overview of all operations", "Ähli amallaryň gysgaça görünüşi")}</p>
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold tracking-tight">{t("dashboard.title", "Baş sahypa")}</h1>
|
||||
<p className="text-sm text-muted-foreground mt-0.5">{t("dashboard.overviewSubtitle", "Ähli amallaryň gysgaça görünüşi")}</p>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2 self-start sm:self-auto">
|
||||
<Select value={String(selectedYear)} onValueChange={(val) => setSelectedYear(Number(val))}>
|
||||
<SelectTrigger className="w-[120px] h-9">
|
||||
<SelectValue placeholder={String(selectedYear)} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{yearOptions.map((y) => (
|
||||
<SelectItem key={y} value={String(y)}>
|
||||
{y} {t("common.year", "ýyl")}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => refetch()}
|
||||
disabled={isFetching}
|
||||
title={t("common.refresh", "Täzele")}
|
||||
className="h-9 w-9"
|
||||
>
|
||||
<RefreshCw className={cn("h-4 w-4", isFetching && "animate-spin")} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Stat cards */}
|
||||
<div className="grid grid-cols-2 lg:grid-cols-4 gap-4">
|
||||
<StatCard
|
||||
title={t("Loan orders", "Karz sargytlary")}
|
||||
value="2 841"
|
||||
change={12.4}
|
||||
title={t("dashboard.loanOrders", "Karz sargytlary")}
|
||||
value={stats?.loanOrders?.count?.toLocaleString() ?? "0"}
|
||||
change={stats?.loanOrders?.changePercent}
|
||||
icon={FileText}
|
||||
accent="bg-blue-100 text-blue-600 dark:bg-blue-950 dark:text-blue-400"
|
||||
comparedToText={t("dashboard.comparedToLastMonth", "geçen aýa garanyňda")}
|
||||
totalActiveText={t("dashboard.totalLoanOrders", "Jemi karz sargytlar")}
|
||||
/>
|
||||
<StatCard
|
||||
title={t("Active cards", "Işjeň kartlar")}
|
||||
value="6 968"
|
||||
change={5.1}
|
||||
title={t("dashboard.activeCards", "Işjeň kartlar")}
|
||||
value={stats?.activeCards?.count?.toLocaleString() ?? "0"}
|
||||
change={stats?.activeCards?.changePercent}
|
||||
icon={CreditCard}
|
||||
accent="bg-violet-100 text-violet-600 dark:bg-violet-950 dark:text-violet-400"
|
||||
comparedToText={t("dashboard.comparedToLastMonth", "geçen aýa garanyňda")}
|
||||
totalActiveText={t("dashboard.totalActiveCards", "Işjeň kartlaryň sany")}
|
||||
/>
|
||||
<StatCard
|
||||
title={t("Active clients", "Işjeň müşderiler")}
|
||||
value="1 204"
|
||||
change={-3.2}
|
||||
title={t("dashboard.activeClients", "Işjeň müşderiler")}
|
||||
value={stats?.activeCustomers?.count?.toLocaleString() ?? "0"}
|
||||
change={stats?.activeCustomers?.changePercent}
|
||||
icon={Users}
|
||||
accent="bg-amber-100 text-amber-600 dark:bg-amber-950 dark:text-amber-400"
|
||||
comparedToText={t("dashboard.comparedToLastMonth", "geçen aýa garanyňda")}
|
||||
totalActiveText={t("dashboard.totalActiveCustomers", "Hasaba alnan müşderiler")}
|
||||
/>
|
||||
<StatCard
|
||||
title={t("Online payments", "Onlaýn tölegler")}
|
||||
value="438"
|
||||
change={18.7}
|
||||
title={t("dashboard.onlinePayments", "Onlaýn tölegler")}
|
||||
value={stats?.onlinePayments?.count?.toLocaleString() ?? "0"}
|
||||
change={stats?.onlinePayments?.changePercent}
|
||||
icon={DollarSign}
|
||||
accent="bg-emerald-100 text-emerald-600 dark:bg-emerald-950 dark:text-emerald-400"
|
||||
comparedToText={t("dashboard.comparedToLastMonth", "geçen aýa garanyňda")}
|
||||
totalActiveText={t("dashboard.totalOnlinePayments", "Amala aşyrylan tölegler")}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Area chart + Pie chart */}
|
||||
<div className="grid grid-cols-1 lg:grid-cols-3 gap-4">
|
||||
{/* Loan & Card Trend Area Chart */}
|
||||
<Card className="lg:col-span-2">
|
||||
<CardHeader>
|
||||
<CardTitle>{t("Loan & card trend", "Karz we kart tendensiýasy")}</CardTitle>
|
||||
<CardDescription>2024 — ýyllyk görünüş</CardDescription>
|
||||
<CardTitle>{t("dashboard.trendTitle", "Karz we kart tendensiýasy")}</CardTitle>
|
||||
<CardDescription>
|
||||
{selectedYear} — {t("dashboard.yearlyOverview", "ýyllyk görünüş")}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<ChartContainer config={areaConfig} className="h-[220px] w-full">
|
||||
<AreaChart data={areaData} margin={{ top: 4, right: 4, left: -24, bottom: 0 }}>
|
||||
<AreaChart data={areaData} margin={{ top: 8, right: 12, left: -20, bottom: 0 }}>
|
||||
<defs>
|
||||
<linearGradient id="fillLoans" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="5%" stopColor="var(--color-loans)" stopOpacity={0.2} />
|
||||
<stop offset="95%" stopColor="var(--color-loans)" stopOpacity={0} />
|
||||
<stop offset="5%" stopColor="#2563eb" stopOpacity={0.3} />
|
||||
<stop offset="95%" stopColor="#2563eb" stopOpacity={0.02} />
|
||||
</linearGradient>
|
||||
<linearGradient id="fillCards" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="5%" stopColor="var(--color-cards)" stopOpacity={0.2} />
|
||||
<stop offset="95%" stopColor="var(--color-cards)" stopOpacity={0} />
|
||||
<stop offset="5%" stopColor="#10b981" stopOpacity={0.3} />
|
||||
<stop offset="95%" stopColor="#10b981" stopOpacity={0.02} />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<CartesianGrid strokeDasharray="3 3" vertical={false} stroke="var(--border)" />
|
||||
<XAxis dataKey="month" tickLine={false} axisLine={false} tick={{ fontSize: 11, fill: "var(--muted-foreground)" }} />
|
||||
<YAxis tickLine={false} axisLine={false} tick={{ fontSize: 11, fill: "var(--muted-foreground)" }} />
|
||||
<YAxis tickLine={false} axisLine={false} tick={{ fontSize: 11, fill: "var(--muted-foreground)" }} allowDecimals={false} />
|
||||
<ChartTooltip content={<ChartTooltipContent />} />
|
||||
<Area type="monotone" dataKey="loans" stroke="var(--color-loans)" strokeWidth={2} fill="url(#fillLoans)" dot={false} />
|
||||
<Area type="monotone" dataKey="cards" stroke="var(--color-cards)" strokeWidth={2} fill="url(#fillCards)" dot={false} />
|
||||
<Area
|
||||
type="monotone"
|
||||
dataKey="loans"
|
||||
stroke="#2563eb"
|
||||
strokeWidth={2.5}
|
||||
fill="url(#fillLoans)"
|
||||
dot={false}
|
||||
activeDot={{ r: 4, strokeWidth: 2 }}
|
||||
/>
|
||||
<Area
|
||||
type="monotone"
|
||||
dataKey="cards"
|
||||
stroke="#10b981"
|
||||
strokeWidth={2.5}
|
||||
fill="url(#fillCards)"
|
||||
dot={false}
|
||||
activeDot={{ r: 4, strokeWidth: 2 }}
|
||||
/>
|
||||
<ChartLegend content={<ChartLegendContent />} />
|
||||
</AreaChart>
|
||||
</ChartContainer>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Loan Status Pie Chart */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{t("Loan status", "Karz ýagdaýy")}</CardTitle>
|
||||
<CardDescription>{total.toLocaleString()} jemi sargyt</CardDescription>
|
||||
<CardTitle>{t("dashboard.loanStatusTitle", "Karz ýagdaýy")}</CardTitle>
|
||||
<CardDescription>
|
||||
{totalLoanStatus.toLocaleString()} {t("dashboard.totalOrders", "jemi sargyt")}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<ChartContainer config={pieConfig} className="h-[160px] w-full">
|
||||
<PieChart>
|
||||
<Pie
|
||||
data={pieData}
|
||||
cx="50%"
|
||||
cy="50%"
|
||||
innerRadius={48}
|
||||
outerRadius={72}
|
||||
paddingAngle={2}
|
||||
dataKey="value"
|
||||
nameKey="name"
|
||||
strokeWidth={0}
|
||||
>
|
||||
{pieData.map((entry, i) => (
|
||||
<Cell key={i} fill={`var(--color-${entry.key})`} />
|
||||
))}
|
||||
</Pie>
|
||||
<ChartTooltip content={<ChartTooltipContent nameKey="name" hideLabel />} />
|
||||
</PieChart>
|
||||
</ChartContainer>
|
||||
{totalLoanStatus === 0 ? (
|
||||
<div className="h-[160px] flex items-center justify-center text-xs text-muted-foreground">
|
||||
{t("dashboard.noData", "Maglumat ýok")}
|
||||
</div>
|
||||
) : (
|
||||
<ChartContainer config={pieConfig} className="h-[160px] w-full">
|
||||
<PieChart>
|
||||
<Pie
|
||||
data={pieData}
|
||||
cx="50%"
|
||||
cy="50%"
|
||||
innerRadius={48}
|
||||
outerRadius={72}
|
||||
paddingAngle={3}
|
||||
dataKey="value"
|
||||
nameKey="name"
|
||||
strokeWidth={0}
|
||||
>
|
||||
{pieData.map((entry, i) => (
|
||||
<Cell key={i} fill={entry.color} />
|
||||
))}
|
||||
</Pie>
|
||||
<ChartTooltip content={<ChartTooltipContent nameKey="name" hideLabel />} />
|
||||
</PieChart>
|
||||
</ChartContainer>
|
||||
)}
|
||||
|
||||
<div className="mt-3 space-y-1.5">
|
||||
{pieData.map((d) => (
|
||||
<div key={d.key} className="flex items-center justify-between text-xs">
|
||||
<span className="flex items-center gap-1.5 text-muted-foreground">
|
||||
<span className="h-1.5 w-1.5 rounded-full flex-shrink-0" style={{ background: `var(--color-${d.key})` }} />
|
||||
<span className="h-2 w-2 rounded-full flex-shrink-0" style={{ background: d.color }} />
|
||||
{d.name}
|
||||
</span>
|
||||
<span className="font-medium tabular-nums">{((d.value / total) * 100).toFixed(0)}%</span>
|
||||
<span className="font-medium tabular-nums">
|
||||
{d.percent != null
|
||||
? `${d.percent}%`
|
||||
: totalLoanStatus > 0
|
||||
? `${((d.value / totalLoanStatus) * 100).toFixed(0)}%`
|
||||
: "0%"}{" "}
|
||||
({d.value})
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
@@ -418,57 +555,70 @@ export default function DashboardPage({ isLoading = false }: { isLoading?: boole
|
||||
|
||||
{/* Bar chart + Recent activity */}
|
||||
<div className="grid grid-cols-1 lg:grid-cols-3 gap-4">
|
||||
{/* Weekly Orders Bar Chart */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{t("Weekly orders", "Hepdelik sargytlar")}</CardTitle>
|
||||
<CardDescription>{t("Last 7 days", "Soňky 7 gün")}</CardDescription>
|
||||
<CardTitle>{t("dashboard.weeklyOrdersTitle", "Hepdelik sargytlar")}</CardTitle>
|
||||
<CardDescription>{t("dashboard.last7Days", "Soňky 7 gün")}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<ChartContainer config={barConfig} className="h-[180px] w-full">
|
||||
<BarChart data={barData} margin={{ top: 4, right: 4, left: -24, bottom: 0 }} barGap={3}>
|
||||
<BarChart data={barData} margin={{ top: 8, right: 8, left: -20, bottom: 0 }} barGap={4}>
|
||||
<CartesianGrid strokeDasharray="3 3" vertical={false} stroke="var(--border)" />
|
||||
<XAxis dataKey="day" tickLine={false} axisLine={false} tick={{ fontSize: 11, fill: "var(--muted-foreground)" }} />
|
||||
<YAxis tickLine={false} axisLine={false} tick={{ fontSize: 11, fill: "var(--muted-foreground)" }} />
|
||||
<YAxis tickLine={false} axisLine={false} tick={{ fontSize: 11, fill: "var(--muted-foreground)" }} allowDecimals={false} />
|
||||
<ChartTooltip content={<ChartTooltipContent />} />
|
||||
<Bar dataKey="approved" fill="var(--color-approved)" radius={[4, 4, 0, 0]} maxBarSize={20} />
|
||||
<Bar dataKey="rejected" fill="var(--color-rejected)" radius={[4, 4, 0, 0]} maxBarSize={20} />
|
||||
<Bar dataKey="loans" fill="#2563eb" radius={[4, 4, 0, 0]} maxBarSize={18} />
|
||||
<Bar dataKey="cards" fill="#10b981" radius={[4, 4, 0, 0]} maxBarSize={18} />
|
||||
<ChartLegend content={<ChartLegendContent />} />
|
||||
</BarChart>
|
||||
</ChartContainer>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Recent Activity Card */}
|
||||
<Card className="lg:col-span-2">
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-3">
|
||||
<div>
|
||||
<CardTitle>{t("Recent activity", "Soňky hereketler")}</CardTitle>
|
||||
<CardDescription className="mt-0.5">{t("Latest loan orders", "Iň soňky karz sargytlary")}</CardDescription>
|
||||
<CardTitle>{t("dashboard.recentActivityTitle", "Soňky hereketler")}</CardTitle>
|
||||
<CardDescription className="mt-0.5">{t("dashboard.latestLoanOrders", "Iň soňky karz sargytlary")}</CardDescription>
|
||||
</div>
|
||||
<div className="flex items-center gap-1 text-xs text-muted-foreground">
|
||||
<Activity size={12} />
|
||||
<span>Janly</span>
|
||||
<div className="flex items-center gap-1.5 text-xs text-muted-foreground">
|
||||
<Activity size={12} className="text-emerald-500 animate-pulse" />
|
||||
<span>{t("common.live", "Janly")}</span>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="p-0">
|
||||
<div className="divide-y divide-border">
|
||||
{recentActivity.map((item) => (
|
||||
<div key={item.id} className="flex items-center gap-3 px-6 py-3">
|
||||
<div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-muted text-xs font-semibold text-muted-foreground">
|
||||
{item.name.charAt(0)}
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-sm font-medium truncate">{item.name}</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{item.id} · {item.time}
|
||||
</p>
|
||||
</div>
|
||||
<div className="text-right shrink-0 space-y-0.5">
|
||||
<p className="text-sm font-medium tabular-nums">{item.amount}</p>
|
||||
<DashboardStatusBadge status={item.status} />
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
{recentActivity.length === 0 ? (
|
||||
<div className="py-12 text-center text-sm text-muted-foreground">{t("dashboard.noRecentActivity", "Hereket tapylmady")}</div>
|
||||
) : (
|
||||
<div className="divide-y divide-border">
|
||||
{recentActivity.map((item) => {
|
||||
const displayId = item.uniqueId ? `#${item.uniqueId}` : `#${item.id}`;
|
||||
const initial = (item.customerName || "M").charAt(0).toUpperCase();
|
||||
const formattedAmount = item.amount ? `${Number(item.amount).toLocaleString()} TMT` : "—";
|
||||
const timeText = formatRelativeTime(item.createdAt);
|
||||
|
||||
return (
|
||||
<div key={item.id} className="flex items-center gap-3 px-6 py-3">
|
||||
<div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-primary/10 text-primary text-xs font-semibold">
|
||||
{initial}
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-sm font-medium truncate">{item.customerName || t("common.customer", "Müşderi")}</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{displayId} · {timeText}
|
||||
</p>
|
||||
</div>
|
||||
<div className="text-right shrink-0 space-y-0.5">
|
||||
<p className="text-sm font-medium tabular-nums">{formattedAmount}</p>
|
||||
<StatusCell status={item.status} prefix="status" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user