changed dashboard
This commit is contained in:
1 parent
1ebc133d1c
commit
cbd17608c1
13 files changed
+1125
-547
No files matched your search
@@ -1,4 +1,13 @@
|
|||||||
VITE_API_BASE_URL=https://test.webulgam.com/online-backend/api/admin
|
VITE_API_BASE_URL=https://test.webulgam.com/online-backend/api/admin
|
||||||
VITE_API_URL=/api
|
VITE_API_URL=/api
|
||||||
VITE_ENABLE_MOCKS=false
|
VITE_ENABLE_MOCKS=false
|
||||||
|
server_user = 'ubuntu'
|
||||||
|
server_ip = '216.250.10.141'
|
||||||
|
server_password = 'TazePassword'
|
||||||
|
|
||||||
|
|
||||||
|
# Public path the app is served under (router basename follows it)
|
||||||
|
VITE_BASE_PATH=/online/
|
||||||
|
# Dev server: backend origin for the /api proxy, and allowed hosts (comma-separated)
|
||||||
|
VITE_PROXY_TARGET=https://test.webulgam.com/online-backend
|
||||||
|
VITE_ALLOWED_HOSTS=test.webulgam.com
|
||||||
@@ -2,3 +2,9 @@ VITE_API_BASE_URL=https://test.webulgam.com/online-backend/api/admin
|
|||||||
VITE_API_URL=/api
|
VITE_API_URL=/api
|
||||||
VITE_ENABLE_MOCKS=false
|
VITE_ENABLE_MOCKS=false
|
||||||
|
|
||||||
|
|
||||||
|
# Public path the app is served under (router basename follows it)
|
||||||
|
VITE_BASE_PATH=/online/
|
||||||
|
# Dev server: backend origin for the /api proxy, and allowed hosts (comma-separated)
|
||||||
|
VITE_PROXY_TARGET=https://test.webulgam.com/online-backend
|
||||||
|
VITE_ALLOWED_HOSTS=test.webulgam.com
|
||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link rel="icon" type="image/svg+xml" href="./src/assets/icon.svg" />
|
<link rel="icon" type="image/svg+xml" href="./src/assets/icon.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>tbbank-admin</title>
|
<title>TÜRKMENBAŞY PTB — Admin</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
|
|||||||
@@ -0,0 +1,213 @@
|
|||||||
|
import apiClient from "@/lib/api/client";
|
||||||
|
|
||||||
|
// ─── Shared ───────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export interface AnalyticsParams {
|
||||||
|
/** YYYY-MM-DD, inclusive */
|
||||||
|
from: string;
|
||||||
|
/** YYYY-MM-DD, inclusive */
|
||||||
|
to: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CountItem {
|
||||||
|
key: string;
|
||||||
|
count: number;
|
||||||
|
percent: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Localized name stored as JSON on the backend, e.g. { tm, ru, en }. */
|
||||||
|
export type LocalizedName = Partial<Record<"tm" | "ru" | "en", string>>;
|
||||||
|
|
||||||
|
export type OrderType = "loan" | "loan_paid_off_letter" | "card" | "card_pin" | "card_rekwizit" | "visa_master";
|
||||||
|
|
||||||
|
// ─── /finance ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export interface PaymentTotals {
|
||||||
|
count: number;
|
||||||
|
amountTmt: number;
|
||||||
|
bankFeeTmt: number;
|
||||||
|
gbusFeeTmt: number;
|
||||||
|
tvebFeeTmt: number;
|
||||||
|
totalTmt: number;
|
||||||
|
avgTotalTmt: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FinanceMonth {
|
||||||
|
month: string; // YYYY-MM
|
||||||
|
count: number;
|
||||||
|
totalTmt: number;
|
||||||
|
bankFeeTmt: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LoanRequested {
|
||||||
|
count: number;
|
||||||
|
totalTmt: number;
|
||||||
|
avgTmt: number;
|
||||||
|
unparsed: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FinanceData {
|
||||||
|
payments: PaymentTotals;
|
||||||
|
gateway: CountItem[];
|
||||||
|
gatewaySuccessRate: number | null;
|
||||||
|
monthly: FinanceMonth[];
|
||||||
|
loanRequested: LoanRequested;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── /backlog ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export interface BacklogItem {
|
||||||
|
type: OrderType;
|
||||||
|
open: number;
|
||||||
|
under1Day: number;
|
||||||
|
from1To3Days: number;
|
||||||
|
over3Days: number;
|
||||||
|
oldestOpenAt: string | null;
|
||||||
|
oldestOpenDays: number | null;
|
||||||
|
finished: number;
|
||||||
|
avgProcessHours: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface VisaMasterTiming {
|
||||||
|
orders: number;
|
||||||
|
avgMinutes: number | null;
|
||||||
|
p90Minutes: number | null;
|
||||||
|
maxMinutes: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BacklogData {
|
||||||
|
items: BacklogItem[];
|
||||||
|
visaMasterTiming: VisaMasterTiming;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── /branches ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export interface BranchStat {
|
||||||
|
branchId: number;
|
||||||
|
name: LocalizedName;
|
||||||
|
region: string;
|
||||||
|
orders: Partial<Record<OrderType, number>>;
|
||||||
|
total: number;
|
||||||
|
open: number;
|
||||||
|
approved: number;
|
||||||
|
rejected: number;
|
||||||
|
approvalRate: number | null;
|
||||||
|
avgProcessHours: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BranchesData {
|
||||||
|
branches: BranchStat[];
|
||||||
|
regions: CountItem[];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── /products ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export interface NamedCount {
|
||||||
|
id: number;
|
||||||
|
name: LocalizedName;
|
||||||
|
count: number;
|
||||||
|
percent: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProductsData {
|
||||||
|
loanSources: CountItem[];
|
||||||
|
loanTypes: NamedCount[];
|
||||||
|
cardTypes: NamedCount[];
|
||||||
|
cardOrderPay: CountItem[];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── /customers ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export interface ApprovalCount {
|
||||||
|
key: string;
|
||||||
|
count: number;
|
||||||
|
percent: number;
|
||||||
|
approved: number;
|
||||||
|
rejected: number;
|
||||||
|
/** Not decided yet (new / in review). */
|
||||||
|
open: number;
|
||||||
|
approvalRate: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CustomersData {
|
||||||
|
total: number;
|
||||||
|
approved: number;
|
||||||
|
rejected: number;
|
||||||
|
open: number;
|
||||||
|
approvalRate: number | null;
|
||||||
|
ageGroups: ApprovalCount[];
|
||||||
|
education: ApprovalCount[];
|
||||||
|
marriageStatus: ApprovalCount[];
|
||||||
|
guarantors: ApprovalCount[];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── /system ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export interface RegistrationFunnel {
|
||||||
|
started: number;
|
||||||
|
completed: number;
|
||||||
|
abandoned: number;
|
||||||
|
waitingCode: number;
|
||||||
|
wrongCodeTries: number;
|
||||||
|
conversionPct: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OperatorActivity {
|
||||||
|
userId: number;
|
||||||
|
name: string;
|
||||||
|
actions: number;
|
||||||
|
errors: number;
|
||||||
|
lastSeen: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ModuleError {
|
||||||
|
module: string;
|
||||||
|
requests: number;
|
||||||
|
errors: number;
|
||||||
|
errorRate: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** weekday: Monday=1 .. Sunday=7; hour 0..23 (Asia/Ashgabat). */
|
||||||
|
export interface HeatmapCell {
|
||||||
|
weekday: number;
|
||||||
|
hour: number;
|
||||||
|
count: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CardBalanceStats {
|
||||||
|
statuses: CountItem[];
|
||||||
|
failureRate: number | null;
|
||||||
|
expiringIn30d: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SystemData {
|
||||||
|
registration: RegistrationFunnel | null;
|
||||||
|
operators: OperatorActivity[];
|
||||||
|
moduleErrors: ModuleError[];
|
||||||
|
peakHours: HeatmapCell[];
|
||||||
|
cardBalances: CardBalanceStats | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── API Functions ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const BASE = "/dashboard/analytics";
|
||||||
|
|
||||||
|
async function getAnalytics<T>(path: string, params: AnalyticsParams, signal?: AbortSignal): Promise<T> {
|
||||||
|
const { data } = await apiClient.get<T>(`${BASE}/${path}`, { params, signal });
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getAnalyticsFinance = (params: AnalyticsParams, signal?: AbortSignal) => getAnalytics<FinanceData>("finance", params, signal);
|
||||||
|
|
||||||
|
export const getAnalyticsBacklog = (params: AnalyticsParams, signal?: AbortSignal) => getAnalytics<BacklogData>("backlog", params, signal);
|
||||||
|
|
||||||
|
export const getAnalyticsBranches = (params: AnalyticsParams, signal?: AbortSignal) =>
|
||||||
|
getAnalytics<BranchesData>("branches", params, signal);
|
||||||
|
|
||||||
|
export const getAnalyticsProducts = (params: AnalyticsParams, signal?: AbortSignal) =>
|
||||||
|
getAnalytics<ProductsData>("products", params, signal);
|
||||||
|
|
||||||
|
export const getAnalyticsCustomers = (params: AnalyticsParams, signal?: AbortSignal) =>
|
||||||
|
getAnalytics<CustomersData>("customers", params, signal);
|
||||||
|
|
||||||
|
export const getAnalyticsSystem = (params: AnalyticsParams, signal?: AbortSignal) => getAnalytics<SystemData>("system", params, signal);
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import { useCallback } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import type { TFunction } from "i18next";
|
||||||
|
import { REGION_LABELS } from "@/constants/regionCodes";
|
||||||
|
import type { LocalizedName, OrderType } from "@/features/dashboard/api/analyticsApi";
|
||||||
|
|
||||||
|
// ─── Formatting ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function formatNumber(value: number | null | undefined, digits = 0): string {
|
||||||
|
if (value === null || value === undefined || !Number.isFinite(value)) return "—";
|
||||||
|
return value.toLocaleString(undefined, { maximumFractionDigits: digits, minimumFractionDigits: 0 });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatTmt(value: number | null | undefined): string {
|
||||||
|
if (value === null || value === undefined) return "—";
|
||||||
|
return `${formatNumber(value, 2)} TMT`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatPercent(value: number | null | undefined): string {
|
||||||
|
if (value === null || value === undefined) return "—";
|
||||||
|
return `${formatNumber(value, 1)}%`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Hours → "45 min", "5.5 sag", "2.1 gün" style. */
|
||||||
|
export function formatDuration(hours: number | null | undefined, t: TFunction): string {
|
||||||
|
if (hours === null || hours === undefined || !Number.isFinite(hours)) return "—";
|
||||||
|
const minutes = Math.round(hours * 60);
|
||||||
|
if (minutes < 60) return `${minutes} ${t("analytics.unit.min", "min")}`;
|
||||||
|
if (hours < 48) return `${formatNumber(hours, 1)} ${t("analytics.unit.hours", "sag")}`;
|
||||||
|
return `${formatNumber(hours / 24, 1)} ${t("analytics.unit.days", "gün")}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Picks the current UI language from a backend { tm, ru, en } name. */
|
||||||
|
export function useLocalizedName() {
|
||||||
|
const { i18n } = useTranslation();
|
||||||
|
const short = i18n.language?.slice(0, 2);
|
||||||
|
const lang = (short === "tk" ? "tm" : short) as keyof LocalizedName;
|
||||||
|
return useCallback((name: LocalizedName | null | undefined): string => name?.[lang] || name?.tm || name?.ru || name?.en || "—", [lang]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function orderTypeLabel(type: OrderType | string, t: TFunction): string {
|
||||||
|
const fallback: Record<string, string> = {
|
||||||
|
loan: "Karz sargytlary",
|
||||||
|
loan_paid_off_letter: "Karzyň ýapylandygy",
|
||||||
|
card: "Täze kart",
|
||||||
|
card_pin: "Kart pin",
|
||||||
|
card_rekwizit: "Kart rekwizit",
|
||||||
|
visa_master: "Visa/Master",
|
||||||
|
};
|
||||||
|
return t(`analytics.orderType.${type}`, fallback[type] ?? type);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function regionLabel(code: string, t: TFunction): string {
|
||||||
|
if (code === "unknown") return t("analytics.unknown", "Näbelli");
|
||||||
|
return t(`loanOrders.regions.${code}`, REGION_LABELS[code] ?? code);
|
||||||
|
}
|
||||||
@@ -0,0 +1,191 @@
|
|||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { AlertCircle, RefreshCw } from "lucide-react";
|
||||||
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
|
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 ─────────────────────────
|
||||||
|
|
||||||
|
interface SectionCardProps {
|
||||||
|
title: string;
|
||||||
|
description?: string;
|
||||||
|
isLoading?: boolean;
|
||||||
|
isError?: boolean;
|
||||||
|
onRetry?: () => void;
|
||||||
|
className?: string;
|
||||||
|
contentClassName?: string;
|
||||||
|
action?: ReactNode;
|
||||||
|
skeletonHeight?: number;
|
||||||
|
children?: ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SectionCard({
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
isLoading,
|
||||||
|
isError,
|
||||||
|
onRetry,
|
||||||
|
className,
|
||||||
|
contentClassName,
|
||||||
|
action,
|
||||||
|
skeletonHeight = 200,
|
||||||
|
children,
|
||||||
|
}: 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>
|
||||||
|
{action}
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className={contentClassName}>
|
||||||
|
{isLoading ? (
|
||||||
|
<Skeleton className="w-full rounded-lg" 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>
|
||||||
|
<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" />
|
||||||
|
{t("common.retry", "Täzeden synanyş")}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
children
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 }}>
|
||||||
|
{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) ───────────────────────────────
|
||||||
|
|
||||||
|
export interface BarListRow {
|
||||||
|
key: string;
|
||||||
|
label: string;
|
||||||
|
value: number;
|
||||||
|
/** Text on the right; defaults to the formatted value. */
|
||||||
|
valueText?: ReactNode;
|
||||||
|
/** Secondary text under the label, e.g. approval rate. */
|
||||||
|
sub?: ReactNode;
|
||||||
|
/** Bar width as a share of the whole (0–100). Without it, bars are scaled to the largest row. */
|
||||||
|
share?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface BarListProps {
|
||||||
|
rows: BarListRow[];
|
||||||
|
color?: string;
|
||||||
|
/** Collapse rows with value 0 into one muted line instead of listing them. */
|
||||||
|
hideEmpty?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function BarList({ rows, color = "var(--chart-1)", hideEmpty }: BarListProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const visible = hideEmpty ? rows.filter((r) => r.value > 0) : rows;
|
||||||
|
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">
|
||||||
|
{visible.map((row) => (
|
||||||
|
<div key={row.key} className="space-y-1">
|
||||||
|
<div className="flex items-baseline justify-between gap-3 text-sm">
|
||||||
|
<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="h-full rounded-full 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>}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
{hidden > 0 && (
|
||||||
|
<p
|
||||||
|
className="border-t pt-2 text-xs text-muted-foreground"
|
||||||
|
title={rows
|
||||||
|
.filter((r) => r.value === 0)
|
||||||
|
.map((r) => r.label)
|
||||||
|
.join(", ")}
|
||||||
|
>
|
||||||
|
{t("analytics.emptyRows", "+{{count}} görnüşde sargyt ýok", { count: hidden })}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,338 @@
|
|||||||
|
import type { ReactNode } from "react";
|
||||||
|
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 { Skeleton } from "@/components/ui/skeleton";
|
||||||
|
import { ChartContainer, ChartTooltip, ChartTooltipContent } from "@/components/ui/chart";
|
||||||
|
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||||
|
import type { ApprovalCount, CountItem, CustomersData, ProductsData } from "../api/analyticsApi";
|
||||||
|
import { BarList, EmptyState, SectionCard, type BarListRow } from "./analyticsShared";
|
||||||
|
import { formatNumber, formatPercent, useLocalizedName } from "./analyticsFormat";
|
||||||
|
|
||||||
|
interface QueryProps<T> {
|
||||||
|
data?: T;
|
||||||
|
isLoading: boolean;
|
||||||
|
isError: boolean;
|
||||||
|
onRetry: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
// One meaning per color across the dashboard: blue = loans, green = cards / good, amber = waiting, red = rejected.
|
||||||
|
const LOAN_COLOR = "var(--chart-1)";
|
||||||
|
const CARD_COLOR = "var(--chart-2)";
|
||||||
|
const GOOD_COLOR = "var(--chart-2)";
|
||||||
|
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;
|
||||||
|
|
||||||
|
/** "3 sargyt · 60%" — count first, share muted. */
|
||||||
|
function CountShare({ count, percent }: { count: number; percent: number }) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<span className="font-semibold">
|
||||||
|
{formatNumber(count)} {t("analytics.kpi.orders", "sargyt")}
|
||||||
|
</span>
|
||||||
|
<span className="text-muted-foreground"> · {formatNumber(percent, 1)}%</span>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function InfoHint({ children }: { children: ReactNode }) {
|
||||||
|
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>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent className="max-w-xs leading-relaxed">{children}</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Donut with the total in the middle ──────────────────────────────────────
|
||||||
|
|
||||||
|
interface DonutRow {
|
||||||
|
key: string;
|
||||||
|
label: string;
|
||||||
|
color: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
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".
|
||||||
|
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) => ({
|
||||||
|
...r,
|
||||||
|
count: byKey.get(r.key)?.count ?? 0,
|
||||||
|
percent: byKey.get(r.key)?.percent ?? 0,
|
||||||
|
}));
|
||||||
|
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 }]));
|
||||||
|
|
||||||
|
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">
|
||||||
|
<PieChart>
|
||||||
|
<Pie data={rows} dataKey="count" nameKey="label" innerRadius={44} outerRadius={64} strokeWidth={2} stroke="var(--card)">
|
||||||
|
{rows.map((r) => (
|
||||||
|
<Cell key={r.key} fill={r.color} />
|
||||||
|
))}
|
||||||
|
</Pie>
|
||||||
|
<ChartTooltip content={<ChartTooltipContent nameKey="label" hideLabel />} />
|
||||||
|
</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="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">
|
||||||
|
{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>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Products ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function ProductsSection({ data, isLoading, isError, onRetry }: QueryProps<ProductsData>) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const localized = useLocalizedName();
|
||||||
|
const common = { isLoading, isError, onRetry, skeletonHeight: 150 };
|
||||||
|
|
||||||
|
const toRows = (items: ProductsData["loanTypes"]): BarListRow[] =>
|
||||||
|
items.map((it) => ({
|
||||||
|
key: String(it.id),
|
||||||
|
label: localized(it.name),
|
||||||
|
value: it.count,
|
||||||
|
share: it.percent,
|
||||||
|
valueText: <CountShare count={it.count} percent={it.percent} />,
|
||||||
|
}));
|
||||||
|
|
||||||
|
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>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Customers ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/** Approved / rejected / waiting counts as colored 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") },
|
||||||
|
].filter((p) => p.n > 0);
|
||||||
|
|
||||||
|
const fewData = decided > 0 && decided < MIN_DECIDED;
|
||||||
|
|
||||||
|
// Two fixed columns: counts on the left, approval rate pinned right — so every row lines up the same way.
|
||||||
|
return (
|
||||||
|
<div className="grid grid-cols-[minmax(0,1fr)_auto] items-center gap-3">
|
||||||
|
<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 }} />
|
||||||
|
{formatNumber(p.n)} {p.label}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</span>
|
||||||
|
{decided === 0 ? (
|
||||||
|
<span className="whitespace-nowrap">{t("analytics.outcome.noDecision", "Karar entek ýok")}</span>
|
||||||
|
) : (
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<span className="inline-flex cursor-help items-baseline gap-1 whitespace-nowrap tabular-nums">
|
||||||
|
<span
|
||||||
|
className={
|
||||||
|
fewData
|
||||||
|
? "font-medium text-muted-foreground underline decoration-dotted underline-offset-2"
|
||||||
|
: "font-semibold text-foreground"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{formatPercent(item.approvalRate)}
|
||||||
|
</span>
|
||||||
|
<span className="text-muted-foreground">
|
||||||
|
{formatNumber(item.approved)}/{formatNumber(decided)}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent className="max-w-xs leading-relaxed">
|
||||||
|
{fewData
|
||||||
|
? t("analytics.outcome.fewDataHint", "Az maglumat: diňe {{count}} karar bar, göterim takyk däl", { count: decided })
|
||||||
|
: t("analytics.outcome.rateHint", "Tassyklama derejesi: tassyklanan / karar berlen")}
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function approvalRows(items: ApprovalCount[], labelFor: (key: string) => string, t: TFunction): BarListRow[] {
|
||||||
|
return items.map((it) => ({
|
||||||
|
key: it.key,
|
||||||
|
label: labelFor(it.key),
|
||||||
|
value: it.count,
|
||||||
|
share: it.percent,
|
||||||
|
valueText: <CountShare count={it.count} percent={it.percent} />,
|
||||||
|
sub: <Outcome item={it} t={t} />,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
function SummaryStat({ label, value, color, hint }: { label: string; value: string; color?: string; hint?: ReactNode }) {
|
||||||
|
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 }} />}
|
||||||
|
<span className="truncate">{label}</span>
|
||||||
|
{hint && <InfoHint>{hint}</InfoHint>}
|
||||||
|
</p>
|
||||||
|
<p className="text-2xl font-semibold tabular-nums tracking-tight">{value}</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function CustomersSummary({ data, isLoading }: { data?: CustomersData; isLoading: boolean }) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const rateHint = t(
|
||||||
|
"analytics.customers.approvalHint",
|
||||||
|
"Tassyklama derejesi = tassyklanan ÷ (tassyklanan + 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>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CustomersSection({ data, isLoading, isError, onRetry }: QueryProps<CustomersData>) {
|
||||||
|
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} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const unknown = t("analytics.unknown", "Näbelli");
|
||||||
|
const humanize = (k: string) => k.charAt(0).toUpperCase() + k.slice(1).toLowerCase().replace(/_/g, " ");
|
||||||
|
const ageLabel = (k: string) =>
|
||||||
|
k === "under25" ? t("analytics.age.under25", "25 ýaşdan kiçi") : k === "unknown" ? unknown : `${k} ${t("analytics.age.years", "ýaş")}`;
|
||||||
|
const educationLabel = (k: string) => (k === "unknown" ? unknown : t(`options.education.${k}`, humanize(k)));
|
||||||
|
const marriageLabel = (k: string) => (k === "unknown" ? unknown : t(`options.marriage.${k}`, humanize(k)));
|
||||||
|
const guarantorLabel = (k: string) =>
|
||||||
|
({
|
||||||
|
none: t("analytics.guarantors.none", "Zamunsyz"),
|
||||||
|
one: t("analytics.guarantors.one", "1 zamun"),
|
||||||
|
two: t("analytics.guarantors.two", "2 zamun"),
|
||||||
|
})[k] ?? k;
|
||||||
|
|
||||||
|
const cards: { title: string; items?: ApprovalCount[]; label: (k: string) => string }[] = [
|
||||||
|
{ title: t("analytics.customers.age", "Ýaş toparlary"), items: data?.ageGroups, label: ageLabel },
|
||||||
|
{ title: t("analytics.customers.education", "Bilimi"), items: data?.education, label: educationLabel },
|
||||||
|
{ title: t("analytics.customers.marriage", "Maşgala ýagdaýy"), items: data?.marriageStatus, label: marriageLabel },
|
||||||
|
{ title: t("analytics.customers.guarantors", "Zamunlar"), items: data?.guarantors, label: guarantorLabel },
|
||||||
|
];
|
||||||
|
|
||||||
|
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>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import {
|
||||||
|
getAnalyticsBacklog,
|
||||||
|
getAnalyticsBranches,
|
||||||
|
getAnalyticsCustomers,
|
||||||
|
getAnalyticsFinance,
|
||||||
|
getAnalyticsProducts,
|
||||||
|
getAnalyticsSystem,
|
||||||
|
type AnalyticsParams,
|
||||||
|
} from "../api/analyticsApi";
|
||||||
|
|
||||||
|
export const ANALYTICS_KEY = "dashboard-analytics";
|
||||||
|
|
||||||
|
const STALE_TIME = 60 * 1000;
|
||||||
|
|
||||||
|
function useAnalyticsQuery<T>(
|
||||||
|
name: string,
|
||||||
|
fetcher: (params: AnalyticsParams, signal?: AbortSignal) => Promise<T>,
|
||||||
|
params: AnalyticsParams,
|
||||||
|
) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: [ANALYTICS_KEY, name, params],
|
||||||
|
queryFn: ({ signal }) => fetcher(params, signal),
|
||||||
|
staleTime: STALE_TIME,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useAnalyticsFinance = (params: AnalyticsParams) => useAnalyticsQuery("finance", getAnalyticsFinance, params);
|
||||||
|
export const useAnalyticsBacklog = (params: AnalyticsParams) => useAnalyticsQuery("backlog", getAnalyticsBacklog, params);
|
||||||
|
export const useAnalyticsBranches = (params: AnalyticsParams) => useAnalyticsQuery("branches", getAnalyticsBranches, params);
|
||||||
|
export const useAnalyticsProducts = (params: AnalyticsParams) => useAnalyticsQuery("products", getAnalyticsProducts, params);
|
||||||
|
export const useAnalyticsCustomers = (params: AnalyticsParams) => useAnalyticsQuery("customers", getAnalyticsCustomers, params);
|
||||||
|
export const useAnalyticsSystem = (params: AnalyticsParams) => useAnalyticsQuery("system", getAnalyticsSystem, params);
|
||||||
@@ -1653,5 +1653,51 @@
|
|||||||
"paymentSettings.tvebFeeUsd": "TVEB fee",
|
"paymentSettings.tvebFeeUsd": "TVEB fee",
|
||||||
"paymentSettings.maxAmountUsd": "Maximum amount",
|
"paymentSettings.maxAmountUsd": "Maximum amount",
|
||||||
"paymentSettings.updateSuccess": "Settings updated successfully",
|
"paymentSettings.updateSuccess": "Settings updated successfully",
|
||||||
"paymentSettings.updateError": "An error occurred"
|
"paymentSettings.updateError": "An error occurred",
|
||||||
|
"analytics.unit.min": "min",
|
||||||
|
"analytics.unit.hours": "h",
|
||||||
|
"analytics.unit.days": "d",
|
||||||
|
"analytics.unknown": "Unknown",
|
||||||
|
"analytics.emptyRows": "+{{count}} more with no orders",
|
||||||
|
"analytics.kpi.orders": "orders",
|
||||||
|
"analytics.source.mobile": "Mobile",
|
||||||
|
"analytics.source.web": "Web",
|
||||||
|
"analytics.paid": "Paid",
|
||||||
|
"analytics.unpaid": "Unpaid",
|
||||||
|
"analytics.products.sources": "Loans: Web and mobile",
|
||||||
|
"analytics.products.sourcesDesc": "Where loan orders were submitted from",
|
||||||
|
"analytics.products.cardPaid": "Card orders: payment",
|
||||||
|
"analytics.products.cardPaidDesc": "How many card orders were paid",
|
||||||
|
"analytics.products.loanTypes": "Loan types",
|
||||||
|
"analytics.products.loanTypesDesc": "Share of each type in all loan orders",
|
||||||
|
"analytics.products.cardTypes": "Card types",
|
||||||
|
"analytics.products.cardTypesDesc": "Share of each type in all card orders",
|
||||||
|
"analytics.outcome.approved": "approved",
|
||||||
|
"analytics.outcome.rejected": "rejected",
|
||||||
|
"analytics.outcome.open": "pending",
|
||||||
|
"analytics.outcome.noDecision": "No decision yet",
|
||||||
|
"analytics.outcome.fewDataHint": "Little data: only {{count}} decisions, the percentage is not reliable",
|
||||||
|
"analytics.outcome.rateHint": "Approval rate: approved / decided",
|
||||||
|
"analytics.outcome.approvedTitle": "Approved",
|
||||||
|
"analytics.outcome.rejectedTitle": "Rejected",
|
||||||
|
"analytics.outcome.openTitle": "Pending",
|
||||||
|
"analytics.customers.title": "Customers",
|
||||||
|
"analytics.customers.desc": "Profile of loan applicants in the selected period",
|
||||||
|
"analytics.customers.totalOrders": "Total loan orders",
|
||||||
|
"analytics.customers.approvalRate": "Approval rate",
|
||||||
|
"analytics.customers.approvalHint": "Approval rate = approved ÷ (approved + rejected). Pending orders are not counted.",
|
||||||
|
"analytics.customers.age": "Age groups",
|
||||||
|
"analytics.customers.education": "Education",
|
||||||
|
"analytics.customers.marriage": "Marital status",
|
||||||
|
"analytics.customers.guarantors": "Guarantors",
|
||||||
|
"analytics.age.under25": "Under 25",
|
||||||
|
"analytics.age.years": "years",
|
||||||
|
"analytics.guarantors.none": "No guarantor",
|
||||||
|
"analytics.guarantors.one": "1 guarantor",
|
||||||
|
"analytics.guarantors.two": "2 guarantors",
|
||||||
|
"dashboard.errorTitle": "Failed to load data",
|
||||||
|
"dashboard.errorMessage": "A connection error occurred with the server.",
|
||||||
|
"common.retry": "Try again",
|
||||||
|
"common.refresh": "Refresh",
|
||||||
|
"common.year": "year"
|
||||||
}
|
}
|
||||||
@@ -1654,5 +1654,51 @@
|
|||||||
"paymentSettings.tvebFeeUsd": "Комиссия ТВЭБ",
|
"paymentSettings.tvebFeeUsd": "Комиссия ТВЭБ",
|
||||||
"paymentSettings.maxAmountUsd": "Максимальная сумма",
|
"paymentSettings.maxAmountUsd": "Максимальная сумма",
|
||||||
"paymentSettings.updateSuccess": "Настройки обновлены",
|
"paymentSettings.updateSuccess": "Настройки обновлены",
|
||||||
"paymentSettings.updateError": "Произошла ошибка"
|
"paymentSettings.updateError": "Произошла ошибка",
|
||||||
|
"analytics.unit.min": "мин",
|
||||||
|
"analytics.unit.hours": "ч",
|
||||||
|
"analytics.unit.days": "дн.",
|
||||||
|
"analytics.unknown": "Неизвестно",
|
||||||
|
"analytics.emptyRows": "+{{count}} без заявок",
|
||||||
|
"analytics.kpi.orders": "заявок",
|
||||||
|
"analytics.source.mobile": "Мобильное",
|
||||||
|
"analytics.source.web": "Веб",
|
||||||
|
"analytics.paid": "Оплачено",
|
||||||
|
"analytics.unpaid": "Не оплачено",
|
||||||
|
"analytics.products.sources": "Кредиты: веб и мобильное приложение",
|
||||||
|
"analytics.products.sourcesDesc": "Откуда поступили заявки на кредит",
|
||||||
|
"analytics.products.cardPaid": "Заявки на карты: оплата",
|
||||||
|
"analytics.products.cardPaidDesc": "Сколько заявок на карты оплачено",
|
||||||
|
"analytics.products.loanTypes": "Типы кредитов",
|
||||||
|
"analytics.products.loanTypesDesc": "Доля каждого типа во всех заявках на кредит",
|
||||||
|
"analytics.products.cardTypes": "Типы карт",
|
||||||
|
"analytics.products.cardTypesDesc": "Доля каждого типа во всех заявках на карты",
|
||||||
|
"analytics.outcome.approved": "одобрено",
|
||||||
|
"analytics.outcome.rejected": "отклонено",
|
||||||
|
"analytics.outcome.open": "в ожидании",
|
||||||
|
"analytics.outcome.noDecision": "Решений пока нет",
|
||||||
|
"analytics.outcome.fewDataHint": "Мало данных: принято решений — {{count}}, процент неточен",
|
||||||
|
"analytics.outcome.rateHint": "Уровень одобрения: одобрено / принято решений",
|
||||||
|
"analytics.outcome.approvedTitle": "Одобрено",
|
||||||
|
"analytics.outcome.rejectedTitle": "Отклонено",
|
||||||
|
"analytics.outcome.openTitle": "В ожидании",
|
||||||
|
"analytics.customers.title": "Клиенты",
|
||||||
|
"analytics.customers.desc": "Профиль заявителей на кредит за выбранный период",
|
||||||
|
"analytics.customers.totalOrders": "Всего заявок на кредит",
|
||||||
|
"analytics.customers.approvalRate": "Уровень одобрения",
|
||||||
|
"analytics.customers.approvalHint": "Уровень одобрения = одобрено ÷ (одобрено + отклонено). Заявки в ожидании не учитываются.",
|
||||||
|
"analytics.customers.age": "Возрастные группы",
|
||||||
|
"analytics.customers.education": "Образование",
|
||||||
|
"analytics.customers.marriage": "Семейное положение",
|
||||||
|
"analytics.customers.guarantors": "Поручители",
|
||||||
|
"analytics.age.under25": "Младше 25 лет",
|
||||||
|
"analytics.age.years": "лет",
|
||||||
|
"analytics.guarantors.none": "Без поручителя",
|
||||||
|
"analytics.guarantors.one": "1 поручитель",
|
||||||
|
"analytics.guarantors.two": "2 поручителя",
|
||||||
|
"dashboard.errorTitle": "Не удалось загрузить данные",
|
||||||
|
"dashboard.errorMessage": "Произошла ошибка при подключении к серверу.",
|
||||||
|
"common.retry": "Повторить",
|
||||||
|
"common.refresh": "Обновить",
|
||||||
|
"common.year": "год"
|
||||||
}
|
}
|
||||||
@@ -1652,5 +1652,51 @@
|
|||||||
"paymentSettings.tvebFeeUsd": "TVEB tutumy",
|
"paymentSettings.tvebFeeUsd": "TVEB tutumy",
|
||||||
"paymentSettings.maxAmountUsd": "Iň ýokary möçber",
|
"paymentSettings.maxAmountUsd": "Iň ýokary möçber",
|
||||||
"paymentSettings.updateSuccess": "Sazlamalar üýtgedildi",
|
"paymentSettings.updateSuccess": "Sazlamalar üýtgedildi",
|
||||||
"paymentSettings.updateError": "Ýalňyşlyk ýüze çykdy"
|
"paymentSettings.updateError": "Ýalňyşlyk ýüze çykdy",
|
||||||
|
"analytics.unit.min": "min",
|
||||||
|
"analytics.unit.hours": "sag",
|
||||||
|
"analytics.unit.days": "gün",
|
||||||
|
"analytics.unknown": "Näbelli",
|
||||||
|
"analytics.emptyRows": "+{{count}} görnüşde sargyt ýok",
|
||||||
|
"analytics.kpi.orders": "sargyt",
|
||||||
|
"analytics.source.mobile": "Mobil",
|
||||||
|
"analytics.source.web": "Web",
|
||||||
|
"analytics.paid": "Tölenen",
|
||||||
|
"analytics.unpaid": "Tölenmedik",
|
||||||
|
"analytics.products.sources": "Karz: Web we mobil",
|
||||||
|
"analytics.products.sourcesDesc": "Karz sargytlary nireden iberildi",
|
||||||
|
"analytics.products.cardPaid": "Kart sargytlary: töleg",
|
||||||
|
"analytics.products.cardPaidDesc": "Kart sargytlarynyň näçesi tölendi",
|
||||||
|
"analytics.products.loanTypes": "Karz görnüşleri",
|
||||||
|
"analytics.products.loanTypesDesc": "Her görnüşiň ähli karz sargytlaryndaky paýy",
|
||||||
|
"analytics.products.cardTypes": "Kart görnüşleri",
|
||||||
|
"analytics.products.cardTypesDesc": "Her görnüşiň ähli kart sargytlaryndaky paýy",
|
||||||
|
"analytics.outcome.approved": "tassyklandy",
|
||||||
|
"analytics.outcome.rejected": "ret edildi",
|
||||||
|
"analytics.outcome.open": "garaşýar",
|
||||||
|
"analytics.outcome.noDecision": "Karar entek ýok",
|
||||||
|
"analytics.outcome.fewDataHint": "Az maglumat: diňe {{count}} karar bar, göterim takyk däl",
|
||||||
|
"analytics.outcome.rateHint": "Tassyklama derejesi: tassyklanan / karar berlen",
|
||||||
|
"analytics.outcome.approvedTitle": "Tassyklandy",
|
||||||
|
"analytics.outcome.rejectedTitle": "Ret edildi",
|
||||||
|
"analytics.outcome.openTitle": "Garaşýar",
|
||||||
|
"analytics.customers.title": "Müşderiler",
|
||||||
|
"analytics.customers.desc": "Saýlanan döwürde karz sargydyny berenleriň profili",
|
||||||
|
"analytics.customers.totalOrders": "Jemi karz sargytlary",
|
||||||
|
"analytics.customers.approvalRate": "Tassyklama derejesi",
|
||||||
|
"analytics.customers.approvalHint": "Tassyklama derejesi = tassyklanan ÷ (tassyklanan + ret edilen). Garaşýan sargytlar hasaba alynmaýar.",
|
||||||
|
"analytics.customers.age": "Ýaş toparlary",
|
||||||
|
"analytics.customers.education": "Bilimi",
|
||||||
|
"analytics.customers.marriage": "Maşgala ýagdaýy",
|
||||||
|
"analytics.customers.guarantors": "Zamunlar",
|
||||||
|
"analytics.age.under25": "25 ýaşdan kiçi",
|
||||||
|
"analytics.age.years": "ýaş",
|
||||||
|
"analytics.guarantors.none": "Zamunsyz",
|
||||||
|
"analytics.guarantors.one": "1 zamun",
|
||||||
|
"analytics.guarantors.two": "2 zamun",
|
||||||
|
"dashboard.errorTitle": "Maglumatlary ýükläp bolmady",
|
||||||
|
"dashboard.errorMessage": "Serwer bilen baglanyşykda säwlik ýüze çykdy.",
|
||||||
|
"common.retry": "Täzeden synanyş",
|
||||||
|
"common.refresh": "Täzele",
|
||||||
|
"common.year": "ýyl"
|
||||||
}
|
}
|
||||||
+105
-524
@@ -1,84 +1,46 @@
|
|||||||
import { useState } from "react";
|
"use client";
|
||||||
|
|
||||||
|
import { useMemo, useState, type ElementType } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { ArrowUpRight, ArrowDownRight, FileText, CreditCard, Users, DollarSign, Activity, AlertCircle, RefreshCw } from "lucide-react";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
import { AreaChart, Area, BarChart, Bar, XAxis, YAxis, CartesianGrid, PieChart, Pie, Cell } from "recharts";
|
import { AlertCircle, ArrowDownRight, ArrowUpRight, CreditCard, DollarSign, FileText, RefreshCw, Users } from "lucide-react";
|
||||||
import { ChartContainer, ChartTooltip, ChartTooltipContent, ChartLegend, ChartLegendContent } from "@/components/ui/chart";
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
|
||||||
import { Skeleton } from "@/components/ui/skeleton";
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||||
import { cn, formatFromApiDate } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { StatusCell, getStatusLabel } from "@/constants";
|
import type { StatItem } from "@/features/dashboard/api/dashboardApi";
|
||||||
import { useDashboardOverview } from "@/features/dashboard/hooks/useDashboard";
|
import { DASHBOARD_OVERVIEW_KEY, useDashboardOverview } from "@/features/dashboard/hooks/useDashboard";
|
||||||
|
import { ANALYTICS_KEY, useAnalyticsCustomers } from "@/features/dashboard/hooks/useAnalytics";
|
||||||
// ─── Status Colors for Diagrams ───────────────────────────────────────────────
|
import { CustomersSection } from "@/features/dashboard/components/productsCustomersSection";
|
||||||
|
import { formatNumber } from "@/features/dashboard/components/analyticsFormat";
|
||||||
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)",
|
|
||||||
};
|
|
||||||
|
|
||||||
// ─── Relative time helper ─────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
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 ────────────────────────────────────────────────────────────────
|
// ─── Stat card ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
function StatCard({
|
interface StatCardProps {
|
||||||
title,
|
|
||||||
value,
|
|
||||||
change,
|
|
||||||
icon: Icon,
|
|
||||||
accent,
|
|
||||||
comparedToText,
|
|
||||||
totalActiveText,
|
|
||||||
}: {
|
|
||||||
title: string;
|
title: string;
|
||||||
value: string | number;
|
stat?: StatItem;
|
||||||
change: number | null | undefined;
|
icon: ElementType;
|
||||||
icon: React.ElementType;
|
|
||||||
accent: string;
|
accent: string;
|
||||||
comparedToText: string;
|
footnote: string;
|
||||||
totalActiveText: string;
|
comparedTo: string;
|
||||||
}) {
|
}
|
||||||
|
|
||||||
|
function StatCard({ title, stat, icon: Icon, accent, footnote, comparedTo }: StatCardProps) {
|
||||||
|
const change = stat?.changePercent;
|
||||||
const hasChange = change !== null && change !== undefined;
|
const hasChange = change !== null && change !== undefined;
|
||||||
const positive = (change ?? 0) >= 0;
|
const positive = (change ?? 0) >= 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader className="flex flex-row items-center justify-between pb-2 space-y-0">
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||||
<CardTitle className="text-sm font-medium text-muted-foreground">{title}</CardTitle>
|
<CardTitle className="text-sm font-medium text-muted-foreground">{title}</CardTitle>
|
||||||
<div className={cn("flex h-9 w-9 items-center justify-center rounded-lg", accent)}>
|
<div className={cn("flex h-9 w-9 items-center justify-center rounded-lg", accent)}>
|
||||||
<Icon size={16} />
|
<Icon size={16} />
|
||||||
</div>
|
</div>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<p className="text-3xl font-semibold tracking-tight">{value}</p>
|
<p className="text-3xl font-semibold tracking-tight tabular-nums">{formatNumber(stat?.count ?? 0)}</p>
|
||||||
{hasChange ? (
|
{hasChange ? (
|
||||||
<p
|
<p
|
||||||
className={cn(
|
className={cn(
|
||||||
@@ -87,12 +49,12 @@ function StatCard({
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{positive ? <ArrowUpRight size={13} /> : <ArrowDownRight size={13} />}
|
{positive ? <ArrowUpRight size={13} /> : <ArrowDownRight size={13} />}
|
||||||
{Math.abs(change)}% {comparedToText}
|
{formatNumber(Math.abs(change), 1)}% {comparedTo}
|
||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
<p className="mt-1 flex items-center gap-1.5 text-xs text-muted-foreground">
|
<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" />
|
<span className="inline-block h-1.5 w-1.5 rounded-full bg-muted-foreground/40" />
|
||||||
{totalActiveText}
|
{footnote}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
@@ -103,7 +65,7 @@ function StatCard({
|
|||||||
function StatCardSkeleton() {
|
function StatCardSkeleton() {
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader className="flex flex-row items-center justify-between pb-2 space-y-0">
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||||
<Skeleton className="h-4 w-28" />
|
<Skeleton className="h-4 w-28" />
|
||||||
<Skeleton className="h-9 w-9 rounded-lg" />
|
<Skeleton className="h-9 w-9 rounded-lg" />
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
@@ -119,267 +81,70 @@ function StatCardSkeleton() {
|
|||||||
|
|
||||||
export default function DashboardPage({ isLoading: propLoading = false }: { isLoading?: boolean }) {
|
export default function DashboardPage({ isLoading: propLoading = false }: { isLoading?: boolean }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
const currentYear = new Date().getFullYear();
|
const currentYear = new Date().getFullYear();
|
||||||
const [selectedYear, setSelectedYear] = useState<number>(currentYear);
|
const [selectedYear, setSelectedYear] = useState<number>(currentYear);
|
||||||
|
|
||||||
const {
|
const analyticsParams = useMemo(() => ({ from: `${selectedYear}-01-01`, to: `${selectedYear}-12-31` }), [selectedYear]);
|
||||||
data: overviewData,
|
|
||||||
isLoading: isQueryLoading,
|
|
||||||
isFetching,
|
|
||||||
isError,
|
|
||||||
error,
|
|
||||||
refetch,
|
|
||||||
} = useDashboardOverview({
|
|
||||||
year: selectedYear,
|
|
||||||
recent_limit: 10,
|
|
||||||
});
|
|
||||||
|
|
||||||
const isLoading = propLoading || isQueryLoading;
|
const overview = useDashboardOverview({ year: selectedYear });
|
||||||
|
const customers = useAnalyticsCustomers(analyticsParams);
|
||||||
|
|
||||||
// Chart configs using translations
|
const isFetching = overview.isFetching || customers.isFetching;
|
||||||
const areaConfig = {
|
const showStatSkeleton = propLoading || overview.isLoading;
|
||||||
loans: { label: t("dashboard.loans", "Karzlar"), color: "var(--chart-1)" },
|
|
||||||
cards: { label: t("dashboard.cards", "Kartlar"), color: "var(--chart-2)" },
|
const handleRefresh = () => {
|
||||||
|
void queryClient.invalidateQueries({ queryKey: [DASHBOARD_OVERVIEW_KEY] });
|
||||||
|
void queryClient.invalidateQueries({ queryKey: [ANALYTICS_KEY] });
|
||||||
};
|
};
|
||||||
|
|
||||||
const barConfig = {
|
const yearOptions = [currentYear - 2, currentYear - 1, currentYear];
|
||||||
loans: { label: t("dashboard.loans", "Karzlar"), color: "var(--chart-1)" },
|
const comparedTo = t("dashboard.comparedToLastMonth", "geçen aýa garanyňda");
|
||||||
cards: { label: t("dashboard.cards", "Kartlar"), color: "var(--chart-2)" },
|
const stats = overview.data?.stats;
|
||||||
};
|
|
||||||
|
|
||||||
const pieConfig = {
|
const statCards: Omit<StatCardProps, "comparedTo">[] = [
|
||||||
satisfied: { label: t("status.satisfied", "Kanagatlandyryldy"), color: "var(--chart-2)" },
|
{
|
||||||
approved: { label: t("status.approved", "Tassyklandy"), color: "var(--chart-2)" },
|
title: t("dashboard.loanOrders", "Karz sargytlary"),
|
||||||
pending: { label: t("status.pending", "Garaşylýar"), color: "var(--chart-4)" },
|
stat: stats?.loanOrders,
|
||||||
processing: { label: t("status.processing", "Işlenilýär"), color: "var(--chart-1)" },
|
icon: FileText,
|
||||||
cancelled: { label: t("status.cancelled", "Ýatyrylan"), color: "var(--chart-5)" },
|
accent: "bg-[var(--chart-1)]/12 text-[var(--chart-1)]",
|
||||||
rejected: { label: t("status.rejected", "Ýatyryldy"), color: "var(--chart-5)" },
|
footnote: t("dashboard.totalLoanOrders", "Jemi karz sargytlar"),
|
||||||
registered: { label: t("status.registered", "Bellige alyndy"), color: "var(--chart-3)" },
|
},
|
||||||
completed: { label: t("status.completed", "Tamamlandy"), color: "var(--chart-2)" },
|
{
|
||||||
};
|
title: t("dashboard.activeCards", "Işjeň kartlar"),
|
||||||
|
stat: stats?.activeCards,
|
||||||
// Render Skeleton loading state
|
icon: CreditCard,
|
||||||
if (isLoading) {
|
accent: "bg-[var(--chart-3)]/12 text-[var(--chart-3)]",
|
||||||
return (
|
footnote: t("dashboard.totalActiveCards", "Işjeň kartlaryň sany"),
|
||||||
<div className="w-full space-y-6">
|
},
|
||||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
|
{
|
||||||
<div className="space-y-1.5">
|
title: t("dashboard.activeClients", "Işjeň müşderiler"),
|
||||||
<Skeleton className="h-7 w-40" />
|
stat: stats?.activeCustomers,
|
||||||
<Skeleton className="h-4 w-64" />
|
icon: Users,
|
||||||
</div>
|
accent: "bg-[var(--chart-4)]/12 text-[var(--chart-4)]",
|
||||||
<div className="flex items-center gap-2">
|
footnote: t("dashboard.totalActiveCustomers", "Hasaba alnan müşderiler"),
|
||||||
<Skeleton className="h-9 w-28" />
|
},
|
||||||
<Skeleton className="h-9 w-9" />
|
{
|
||||||
</div>
|
title: t("dashboard.onlinePayments", "Onlaýn tölegler"),
|
||||||
</div>
|
stat: stats?.onlinePayments,
|
||||||
|
icon: DollarSign,
|
||||||
<div className="grid grid-cols-2 lg:grid-cols-4 gap-4">
|
accent: "bg-[var(--chart-2)]/12 text-[var(--chart-2)]",
|
||||||
{[...Array(4)].map((_, i) => (
|
footnote: t("dashboard.totalOnlinePayments", "Amala aşyrylan tölegler"),
|
||||||
<StatCardSkeleton key={i} />
|
},
|
||||||
))}
|
];
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-3 gap-4">
|
|
||||||
{/* Area chart skeleton */}
|
|
||||||
<Card className="lg:col-span-2">
|
|
||||||
<CardHeader>
|
|
||||||
<Skeleton className="h-5 w-48" />
|
|
||||||
<Skeleton className="h-3 w-32 mt-1" />
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent>
|
|
||||||
<div className="h-[220px] w-full flex flex-col justify-end relative">
|
|
||||||
<div className="absolute left-0 top-0 h-full flex flex-col justify-between pb-6">
|
|
||||||
{[...Array(5)].map((_, i) => (
|
|
||||||
<Skeleton key={i} className="h-2.5 w-6" />
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
<div className="ml-8 flex-1 relative overflow-hidden rounded-md">
|
|
||||||
<Skeleton className="absolute inset-0" />
|
|
||||||
</div>
|
|
||||||
<div className="ml-8 mt-2 flex justify-between">
|
|
||||||
{[...Array(12)].map((_, i) => (
|
|
||||||
<Skeleton key={i} className="h-2.5 w-6" />
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="mt-3 flex items-center gap-4">
|
|
||||||
{[...Array(2)].map((_, i) => (
|
|
||||||
<div key={i} className="flex items-center gap-1.5">
|
|
||||||
<Skeleton className="h-3 w-3 rounded-full" />
|
|
||||||
<Skeleton className="h-3 w-12" />
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
{/* Pie chart skeleton */}
|
|
||||||
<Card>
|
|
||||||
<CardHeader>
|
|
||||||
<Skeleton className="h-5 w-32" />
|
|
||||||
<Skeleton className="h-3 w-24 mt-1" />
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent>
|
|
||||||
<div className="h-[160px] w-full flex items-center justify-center">
|
|
||||||
<div className="relative h-[144px] w-[144px]">
|
|
||||||
<Skeleton className="h-full w-full rounded-full" />
|
|
||||||
<div className="absolute inset-0 m-auto h-[96px] w-[96px] rounded-full bg-card" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="mt-3 space-y-2">
|
|
||||||
{[...Array(5)].map((_, i) => (
|
|
||||||
<div key={i} className="flex items-center justify-between">
|
|
||||||
<div className="flex items-center gap-1.5">
|
|
||||||
<Skeleton className="h-1.5 w-1.5 rounded-full" />
|
|
||||||
<Skeleton className="h-3 w-24" />
|
|
||||||
</div>
|
|
||||||
<Skeleton className="h-3 w-8" />
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-3 gap-4">
|
|
||||||
{/* Bar chart skeleton */}
|
|
||||||
<Card>
|
|
||||||
<CardHeader>
|
|
||||||
<Skeleton className="h-5 w-36" />
|
|
||||||
<Skeleton className="h-3 w-24 mt-1" />
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent>
|
|
||||||
<div className="h-[180px] w-full flex flex-col justify-end relative">
|
|
||||||
<div className="absolute left-0 top-0 h-full flex flex-col justify-between pb-6">
|
|
||||||
{[...Array(4)].map((_, i) => (
|
|
||||||
<Skeleton key={i} className="h-2.5 w-6" />
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
<div className="ml-8 flex items-end justify-between gap-1.5 h-[148px]">
|
|
||||||
{[65, 85, 50, 95, 75, 40, 30].map((h, i) => (
|
|
||||||
<div key={i} className="flex-1 flex items-end gap-0.5">
|
|
||||||
<Skeleton className="flex-1 rounded-t-sm" style={{ height: `${h}%` }} />
|
|
||||||
<Skeleton className="flex-1 rounded-t-sm" style={{ height: `${h * 0.15}%` }} />
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
<div className="ml-8 mt-2 flex justify-between">
|
|
||||||
{[...Array(7)].map((_, i) => (
|
|
||||||
<Skeleton key={i} className="h-2.5 w-4" />
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="mt-3 flex items-center gap-4">
|
|
||||||
{[12, 14].map((w, i) => (
|
|
||||||
<div key={i} className="flex items-center gap-1.5">
|
|
||||||
<Skeleton className="h-3 w-3 rounded-full" />
|
|
||||||
<Skeleton className={`h-3 w-${w}`} />
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
{/* Recent activity skeleton */}
|
|
||||||
<Card className="lg:col-span-2">
|
|
||||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-3">
|
|
||||||
<div className="space-y-1.5">
|
|
||||||
<Skeleton className="h-5 w-36" />
|
|
||||||
<Skeleton className="h-3 w-44" />
|
|
||||||
</div>
|
|
||||||
<Skeleton className="h-4 w-12" />
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent className="p-0">
|
|
||||||
<div className="divide-y divide-border">
|
|
||||||
{[...Array(5)].map((_, i) => (
|
|
||||||
<div key={i} className="flex items-center gap-3 px-6 py-3">
|
|
||||||
<Skeleton className="h-8 w-8 rounded-full shrink-0" />
|
|
||||||
<div className="flex-1 space-y-1.5">
|
|
||||||
<Skeleton className="h-3.5 w-36" />
|
|
||||||
<Skeleton className="h-3 w-28" />
|
|
||||||
</div>
|
|
||||||
<div className="text-right space-y-1.5 shrink-0">
|
|
||||||
<Skeleton className="h-3.5 w-20 ml-auto" />
|
|
||||||
<Skeleton className="h-4 w-16 ml-auto rounded-full" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 (
|
return (
|
||||||
<div className="w-full space-y-6">
|
<div className="w-full space-y-6">
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
|
<div className="flex flex-col justify-between gap-4 sm:flex-row sm:items-center">
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-2xl font-semibold tracking-tight">{t("dashboard.title", "Baş sahypa")}</h1>
|
<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>
|
<p className="mt-0.5 text-sm text-muted-foreground">{t("dashboard.overviewSubtitle", "Ähli amallaryň gysgaça görünüşi")}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center gap-2 self-start sm:self-auto">
|
<div className="flex items-center gap-2 self-start sm:self-auto">
|
||||||
<Select value={String(selectedYear)} onValueChange={(val) => setSelectedYear(Number(val))}>
|
<Select value={String(selectedYear)} onValueChange={(val) => setSelectedYear(Number(val))}>
|
||||||
<SelectTrigger className="w-[120px] h-9 cursor-pointer">
|
<SelectTrigger className="h-9 w-[120px] cursor-pointer">
|
||||||
<SelectValue placeholder={String(selectedYear)} />
|
<SelectValue placeholder={String(selectedYear)} />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@@ -394,7 +159,7 @@ export default function DashboardPage({ isLoading: propLoading = false }: { isLo
|
|||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="icon"
|
size="icon"
|
||||||
onClick={() => refetch()}
|
onClick={handleRefresh}
|
||||||
disabled={isFetching}
|
disabled={isFetching}
|
||||||
title={t("common.refresh", "Täzele")}
|
title={t("common.refresh", "Täzele")}
|
||||||
className="h-9 w-9 cursor-pointer"
|
className="h-9 w-9 cursor-pointer"
|
||||||
@@ -405,223 +170,39 @@ export default function DashboardPage({ isLoading: propLoading = false }: { isLo
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Stat cards */}
|
{/* Stat cards */}
|
||||||
<div className="grid grid-cols-2 lg:grid-cols-4 gap-4">
|
{overview.isError && !showStatSkeleton ? (
|
||||||
<StatCard
|
<div className="flex w-full flex-col items-center justify-center space-y-4 rounded-xl border bg-card p-12 text-center">
|
||||||
title={t("dashboard.loanOrders", "Karz sargytlary")}
|
<div className="flex h-12 w-12 items-center justify-center rounded-full bg-destructive/10 text-destructive">
|
||||||
value={stats?.loanOrders?.count?.toLocaleString() ?? "0"}
|
<AlertCircle className="h-6 w-6" />
|
||||||
change={stats?.loanOrders?.changePercent}
|
</div>
|
||||||
icon={FileText}
|
<div>
|
||||||
accent="bg-[var(--chart-1)]/12 text-[var(--chart-1)]"
|
<h3 className="text-lg font-semibold">{t("dashboard.errorTitle", "Maglumatlary ýükläp bolmady")}</h3>
|
||||||
comparedToText={t("dashboard.comparedToLastMonth", "geçen aýa garanyňda")}
|
<p className="mt-1 max-w-md text-sm text-muted-foreground">
|
||||||
totalActiveText={t("dashboard.totalLoanOrders", "Jemi karz sargytlar")}
|
{overview.error instanceof Error && overview.error.message
|
||||||
/>
|
? overview.error.message
|
||||||
<StatCard
|
: t("dashboard.errorMessage", "Serwer bilen baglanyşykda säwlik ýüze çykdy.")}
|
||||||
title={t("dashboard.activeCards", "Işjeň kartlar")}
|
</p>
|
||||||
value={stats?.activeCards?.count?.toLocaleString() ?? "0"}
|
</div>
|
||||||
change={stats?.activeCards?.changePercent}
|
<Button onClick={() => overview.refetch()} variant="outline" className="gap-2">
|
||||||
icon={CreditCard}
|
<RefreshCw className="h-4 w-4" />
|
||||||
accent="bg-[var(--chart-3)]/12 text-[var(--chart-3)]"
|
{t("common.retry", "Täzeden synanyş")}
|
||||||
comparedToText={t("dashboard.comparedToLastMonth", "geçen aýa garanyňda")}
|
</Button>
|
||||||
totalActiveText={t("dashboard.totalActiveCards", "Işjeň kartlaryň sany")}
|
</div>
|
||||||
/>
|
) : (
|
||||||
<StatCard
|
<div className="grid grid-cols-2 gap-4 lg:grid-cols-4">
|
||||||
title={t("dashboard.activeClients", "Işjeň müşderiler")}
|
{showStatSkeleton
|
||||||
value={stats?.activeCustomers?.count?.toLocaleString() ?? "0"}
|
? Array.from({ length: 4 }, (_, i) => <StatCardSkeleton key={i} />)
|
||||||
change={stats?.activeCustomers?.changePercent}
|
: statCards.map((card) => <StatCard key={card.title} {...card} comparedTo={comparedTo} />)}
|
||||||
icon={Users}
|
</div>
|
||||||
accent="bg-[var(--chart-4)]/12 text-[var(--chart-4)]"
|
)}
|
||||||
comparedToText={t("dashboard.comparedToLastMonth", "geçen aýa garanyňda")}
|
|
||||||
totalActiveText={t("dashboard.totalActiveCustomers", "Hasaba alnan müşderiler")}
|
|
||||||
/>
|
|
||||||
<StatCard
|
|
||||||
title={t("dashboard.onlinePayments", "Onlaýn tölegler")}
|
|
||||||
value={stats?.onlinePayments?.count?.toLocaleString() ?? "0"}
|
|
||||||
change={stats?.onlinePayments?.changePercent}
|
|
||||||
icon={DollarSign}
|
|
||||||
accent="bg-[var(--chart-2)]/12 text-[var(--chart-2)]"
|
|
||||||
comparedToText={t("dashboard.comparedToLastMonth", "geçen aýa garanyňda")}
|
|
||||||
totalActiveText={t("dashboard.totalOnlinePayments", "Amala aşyrylan tölegler")}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Area chart + Pie chart */}
|
{/* Customers analytics */}
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-3 gap-4">
|
<CustomersSection
|
||||||
{/* Loan & Card Trend Area Chart */}
|
data={customers.data}
|
||||||
<Card className="lg:col-span-2">
|
isLoading={customers.isLoading}
|
||||||
<CardHeader>
|
isError={customers.isError}
|
||||||
<CardTitle>{t("dashboard.trendTitle", "Karz we kart tendensiýasy")}</CardTitle>
|
onRetry={() => customers.refetch()}
|
||||||
<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: 8, right: 12, left: -20, bottom: 0 }}>
|
|
||||||
<defs>
|
|
||||||
<linearGradient id="fillLoans" x1="0" y1="0" x2="0" y2="1">
|
|
||||||
<stop offset="5%" stopColor="var(--chart-1)" stopOpacity={0.3} />
|
|
||||||
<stop offset="95%" stopColor="var(--chart-1)" stopOpacity={0.02} />
|
|
||||||
</linearGradient>
|
|
||||||
<linearGradient id="fillCards" x1="0" y1="0" x2="0" y2="1">
|
|
||||||
<stop offset="5%" stopColor="var(--chart-2)" stopOpacity={0.3} />
|
|
||||||
<stop offset="95%" stopColor="var(--chart-2)" 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)" }} allowDecimals={false} />
|
|
||||||
<ChartTooltip content={<ChartTooltipContent />} />
|
|
||||||
<Area
|
|
||||||
type="monotone"
|
|
||||||
dataKey="loans"
|
|
||||||
stroke="var(--chart-1)"
|
|
||||||
strokeWidth={2.5}
|
|
||||||
fill="url(#fillLoans)"
|
|
||||||
dot={false}
|
|
||||||
activeDot={{ r: 4, strokeWidth: 2 }}
|
|
||||||
/>
|
|
||||||
<Area
|
|
||||||
type="monotone"
|
|
||||||
dataKey="cards"
|
|
||||||
stroke="var(--chart-2)"
|
|
||||||
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("dashboard.loanStatusTitle", "Karz ýagdaýy")}</CardTitle>
|
|
||||||
<CardDescription>
|
|
||||||
{totalLoanStatus.toLocaleString()} {t("dashboard.totalOrders", "jemi sargyt")}
|
|
||||||
</CardDescription>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent>
|
|
||||||
{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={0}
|
|
||||||
strokeWidth={0}
|
|
||||||
dataKey="value"
|
|
||||||
nameKey="name"
|
|
||||||
>
|
|
||||||
{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-2 w-2 rounded-full flex-shrink-0" style={{ background: d.color }} />
|
|
||||||
{d.name}
|
|
||||||
</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>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Bar chart + Recent activity */}
|
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-3 gap-4">
|
|
||||||
{/* Weekly Orders Bar Chart */}
|
|
||||||
<Card>
|
|
||||||
<CardHeader>
|
|
||||||
<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: 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)" }} allowDecimals={false} />
|
|
||||||
<ChartTooltip content={<ChartTooltipContent />} />
|
|
||||||
<Bar dataKey="loans" fill="var(--chart-1)" radius={[4, 4, 0, 0]} maxBarSize={18} />
|
|
||||||
<Bar dataKey="cards" fill="var(--chart-2)" 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("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.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">
|
|
||||||
{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>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
+32
-19
@@ -1,26 +1,39 @@
|
|||||||
import { fileURLToPath, URL } from "node:url";
|
import { fileURLToPath, URL } from "node:url";
|
||||||
import { defineConfig } from "vite";
|
import { defineConfig, loadEnv } from "vite";
|
||||||
import react from "@vitejs/plugin-react";
|
import react from "@vitejs/plugin-react";
|
||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig(({ mode }) => {
|
||||||
base: "/online/",
|
const env = loadEnv(mode, process.cwd(), "");
|
||||||
plugins: [react()],
|
|
||||||
resolve: {
|
// Public path the app is served from; the router basename is derived from it.
|
||||||
alias: {
|
const base = env.VITE_BASE_PATH || "/online/";
|
||||||
"@": fileURLToPath(new URL("./src", import.meta.url)),
|
// Backend origin the dev server proxies /api to.
|
||||||
},
|
const proxyTarget = env.VITE_PROXY_TARGET || "https://test.webulgam.com/online-backend";
|
||||||
},
|
const allowedHosts = (env.VITE_ALLOWED_HOSTS || "test.webulgam.com")
|
||||||
preview: {
|
.split(",")
|
||||||
allowedHosts: ["test.webulgam.com"],
|
.map((h) => h.trim())
|
||||||
},
|
.filter(Boolean);
|
||||||
server: {
|
|
||||||
allowedHosts: ["test.webulgam.com"],
|
return {
|
||||||
proxy: {
|
base,
|
||||||
"/api": {
|
plugins: [react()],
|
||||||
target: "https://test.webulgam.com/online-backend",
|
resolve: {
|
||||||
changeOrigin: true,
|
alias: {
|
||||||
|
"@": fileURLToPath(new URL("./src", import.meta.url)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
preview: {
|
||||||
|
allowedHosts,
|
||||||
|
},
|
||||||
|
server: {
|
||||||
|
allowedHosts,
|
||||||
|
proxy: {
|
||||||
|
"/api": {
|
||||||
|
target: proxyTarget,
|
||||||
|
changeOrigin: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user