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'; import { Table } from '../components/ui/Table'; import { Button } from '../components/ui/Button'; import { PermissionWrapper } from '../components/common/PermissionWrapper'; import { PageContainer, PageTitle, CardTitle } from '../components/ui/Typography'; import { ChartData, TableColumn } from '../types'; 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 }, { name: 'اردیبهشت', value: 3000 }, { name: 'خرداد', value: 5000 }, { name: 'تیر', value: 4500 }, { name: 'مرداد', value: 6000 }, { name: 'شهریور', value: 5500 }, ]; const pieData: ChartData[] = [ { name: 'دسکتاپ', value: 45 }, { name: 'موبایل', value: 35 }, { name: 'تبلت', value: 20 }, ]; const recentUsers = [ { id: 1, name: 'علی احمدی', email: 'ali@example.com', role: 'کاربر', status: 'فعال', createdAt: '۱۴۰۲/۰۸/۱۵' }, { id: 2, name: 'فاطمه حسینی', email: 'fateme@example.com', role: 'مدیر', status: 'فعال', createdAt: '۱۴۰۲/۰۸/۱۴' }, { id: 3, name: 'محمد رضایی', email: 'mohammad@example.com', role: 'کاربر', status: 'غیرفعال', createdAt: '۱۴۰۲/۰۸/۱۳' }, { id: 4, name: 'زهرا کریمی', email: 'zahra@example.com', role: 'کاربر', status: 'فعال', createdAt: '۱۴۰۲/۰۸/۱۲' }, ]; const userColumns: TableColumn[] = [ { key: 'name', label: 'نام', sortable: true }, { key: 'email', label: 'ایمیل' }, { key: 'role', label: 'نقش' }, { key: 'status', label: 'وضعیت', render: (value) => ( {value} ) }, { key: 'createdAt', label: 'تاریخ عضویت' }, { key: 'actions', label: 'عملیات', render: () => (
) } ]; export const Dashboard = () => { const { items: statsData, isLoading: statsLoading, error: statsError } = useDashboardStats(); return ( {/* Header with mobile-responsive layout */}
داشبورد
{/* Stats Cards - Mobile responsive grid */}
{statsLoading ? ( <> {[...Array(4)].map((_, idx) => (
))} ) : ( statsData.map((stat, index) => ( )) )}
{statsError && (
خطا در دریافت آمار سفارشات
)} {/* Charts - Better mobile layout */}
}>
{/* Table and Pie Chart - Mobile responsive */}
کاربران اخیر
); };