From b09e2ebc59614a43942b0fb01eb928715c746ffe Mon Sep 17 00:00:00 2001 From: "nabijonovdavronbek619@gmail.com" Date: Tue, 7 Apr 2026 13:11:23 +0500 Subject: [PATCH] dahsboard connected to backend --- src/shared/request/links.ts | 1 + .../cabinet/ui/dashboard/StatsCards.tsx | 72 +++++++++++++------ src/widgets/cabinet/ui/dashboard/index.tsx | 6 +- src/widgets/cabinet/ui/index.tsx | 2 +- 4 files changed, 53 insertions(+), 28 deletions(-) diff --git a/src/shared/request/links.ts b/src/shared/request/links.ts index 8a705bb..d83b629 100644 --- a/src/shared/request/links.ts +++ b/src/shared/request/links.ts @@ -13,4 +13,5 @@ export const links = { si_create: '/shared/ai_document/create/', document_types: '/shared/document_types/', pay_history: '/shared/orders/all/', + statistics: '/shared/statistics/', }; diff --git a/src/widgets/cabinet/ui/dashboard/StatsCards.tsx b/src/widgets/cabinet/ui/dashboard/StatsCards.tsx index a04f6df..68055f2 100644 --- a/src/widgets/cabinet/ui/dashboard/StatsCards.tsx +++ b/src/widgets/cabinet/ui/dashboard/StatsCards.tsx @@ -1,6 +1,16 @@ import React from 'react'; -import { TrendingUp, Calendar, Tag, Wallet } from 'lucide-react'; -import type { CabinetStats } from '../../lib/types'; +import { TrendingUp, Calendar, Wallet, Loader2 } from 'lucide-react'; +import { useQuery } from '@tanstack/react-query'; +import { apiRequest } from '@/shared/request/apiRequest'; +import { links } from '@/shared/request/links'; + +// ─── Types ───────────────────────────────────────────────────────────────────── + +type Stats = { + total_documents: number; + this_month_documents: number; + paid_price: number; +}; // ─── Single stat card ────────────────────────────────────────────────────────── @@ -33,46 +43,62 @@ const StatCard: React.FC = ({ ); +const StatCardSkeleton = () => ( +
+
+
+
+
+); + // ─── Grid ────────────────────────────────────────────────────────────────────── -interface StatsCardsProps { - stats: CabinetStats; -} +export const StatsCards = () => { + const { data, isLoading } = useQuery({ + queryKey: ['statistics'], + queryFn: (): Promise => + apiRequest('GET', links.statistics).then((res) => res.data as Stats), + }); -export const StatsCards: React.FC = ({ stats }) => { - const discountPct = Math.round( - (stats.discountUsed / stats.discountTotal) * 100, - ); + if (isLoading) { + return ( +
+ + + +
+ ); + } + + if (!data) { + return ( +
+ + Ma'lumot topilmadi +
+ ); + } return ( -
+
- diff --git a/src/widgets/cabinet/ui/dashboard/index.tsx b/src/widgets/cabinet/ui/dashboard/index.tsx index 679bac5..6894ae8 100644 --- a/src/widgets/cabinet/ui/dashboard/index.tsx +++ b/src/widgets/cabinet/ui/dashboard/index.tsx @@ -2,14 +2,12 @@ import React from 'react'; import { CtaCards } from './CtaCards'; import { StatsCards } from './StatsCards'; import { ModulesSection } from './ModulesSection'; -import type { CabinetStats } from '../../lib/types'; interface DashboardProps { - stats: CabinetStats; userName: string; } -export const Dashboard: React.FC = ({ stats, userName }) => ( +export const Dashboard: React.FC = ({ userName }) => (

@@ -20,7 +18,7 @@ export const Dashboard: React.FC = ({ stats, userName }) => (

- +

diff --git a/src/widgets/cabinet/ui/index.tsx b/src/widgets/cabinet/ui/index.tsx index c24cd30..b80aa61 100644 --- a/src/widgets/cabinet/ui/index.tsx +++ b/src/widgets/cabinet/ui/index.tsx @@ -45,7 +45,7 @@ const ProfileSection = dynamic( function SectionContent({ section }: { section: CabinetSection }) { switch (section) { case 'dashboard': - return ; + return ; case 'plagiat': return ; case 'si':