diff --git a/src/constant/routes.ts b/src/constant/routes.ts index 4db9a25..1b5429d 100644 --- a/src/constant/routes.ts +++ b/src/constant/routes.ts @@ -92,7 +92,7 @@ export const API_ROUTES = { // Orders APIs GET_ORDERS: "checkout/orders", GET_ORDER: (id: string) => `checkout/orders/${id}`, - GET_ORDER_STATS: "checkout/orders/stats", + GET_ORDER_STATS: "checkout/orders/statistics", UPDATE_ORDER_STATUS: (id: string) => `checkout/orders/${id}/status`, // Shipping Methods APIs diff --git a/src/pages/Dashboard.tsx b/src/pages/Dashboard.tsx index 144aed8..1719ae7 100644 --- a/src/pages/Dashboard.tsx +++ b/src/pages/Dashboard.tsx @@ -1,7 +1,8 @@ -import { Users, ShoppingBag, DollarSign, TrendingUp, BarChart3, Plus } from 'lucide-react'; +import { Users, ShoppingBag, DollarSign, TrendingUp, BarChart3, Plus, Clock } from 'lucide-react'; import { StatsCard } from '../components/dashboard/StatsCard'; import { BarChart } from '../components/charts/BarChart'; import { lazy, Suspense } from 'react'; +import { useOrderStats } from './orders/core/_hooks'; const LineChart = lazy(() => import('../components/charts/LineChart').then(module => ({ default: module.LineChart }))); import { PieChart } from '../components/charts/PieChart'; @@ -11,36 +12,36 @@ import { PermissionWrapper } from '../components/common/PermissionWrapper'; import { PageContainer, PageTitle, CardTitle } from '../components/ui/Typography'; import { ChartData, TableColumn } from '../types'; -const statsData = [ - { - title: 'کل کاربران', - value: 1247, - change: 12, - icon: Users, - color: 'blue', - }, - { - title: 'فروش ماهانه', - value: '۲۴,۵۶۷,۰۰۰', - change: 8.5, - icon: DollarSign, - color: 'green', - }, - { - title: 'کل سفارشات', - value: 356, - change: -2.3, - icon: ShoppingBag, - color: 'yellow', - }, - { - title: 'رشد فروش', - value: '۲۳.۵%', - change: 15.2, - icon: TrendingUp, - color: 'purple', - }, -]; +const useDashboardStats = () => { + const { data, isLoading, error } = useOrderStats(true); + const items = [ + { + title: 'کل سفارشات', + value: data?.total_orders_count ?? 0, + icon: ShoppingBag, + color: 'yellow' as const, + }, + { + title: 'مجموع فروش', + value: data?.total_amount_of_sale ?? 0, + icon: DollarSign, + color: 'green' as const, + }, + { + title: 'سفارش‌های در انتظار', + value: data?.total_order_pending ?? 0, + icon: Clock, + color: 'blue' as const, + }, + { + title: 'میانگین سفارش', + value: data?.order_avg ?? 0, + icon: TrendingUp, + color: 'purple' as const, + }, + ]; + return { items, isLoading, error }; +}; const chartData: ChartData[] = [ { name: 'فروردین', value: 4000 }, @@ -100,6 +101,7 @@ const userColumns: TableColumn[] = [ ]; export const Dashboard = () => { + const { items: statsData, isLoading: statsLoading, error: statsError } = useDashboardStats(); return ( {/* Header with mobile-responsive layout */} @@ -125,10 +127,23 @@ export const Dashboard = () => { {/* Stats Cards - Mobile responsive grid */}
- {statsData.map((stat, index) => ( - - ))} + {statsLoading ? ( + <> + {[...Array(4)].map((_, idx) => ( +
+ ))} + + ) : ( + statsData.map((stat, index) => ( + + )) + )}
+ {statsError && ( +
+ خطا در دریافت آمار سفارشات +
+ )} {/* Charts - Better mobile layout */}
diff --git a/src/pages/orders/core/_models.ts b/src/pages/orders/core/_models.ts index 984437e..c5c24c4 100644 --- a/src/pages/orders/core/_models.ts +++ b/src/pages/orders/core/_models.ts @@ -183,10 +183,10 @@ export interface UpdateOrderStatusRequest { } export interface OrderStats { - total_orders: number; - total_revenue: number; - orders_by_status: Record; - avg_order_value: number; + total_orders_count: number; + total_amount_of_sale: number; + total_order_pending: number; + order_avg: number; } export type Response = {