/** * DashboardPage Mobile - Tableau de bord simplifié pour mobile */ import { useQuery } from "@tanstack/react-query"; import { useAuthUnified } from "@/hooks/useAuthUnified"; import { useStore } from "@/contexts/StoreContext"; import MobileLayout from "./MobileLayout"; import { Card, CardContent } from "@/components/ui/card"; import { Package, Truck, CheckSquare, AlertTriangle, TrendingUp, Clock, Calendar } from "lucide-react"; import { format } from "date-fns"; import { fr } from "date-fns/locale"; // Stats card component function StatCard({ icon: Icon, label, value, trend, color }: { icon: React.ComponentType<{ className?: string }>; label: string; value: string | number; trend?: string; color: string; }) { return (
{trend && ( {trend} )}

{value}

{label}

); } export default function MobileDashboardPage() { const { user } = useAuthUnified(); const { selectedStoreId } = useStore(); // Fetch stats const { data: stats, isLoading } = useQuery({ queryKey: ["/api/stats/dashboard", selectedStoreId], queryFn: async () => { const params = new URLSearchParams(); if (selectedStoreId) params.append('storeId', selectedStoreId.toString()); const response = await fetch(`/api/stats/dashboard?${params}`, { credentials: 'include' }); if (!response.ok) return null; return response.json(); }, enabled: !!user, }); // Fetch pending tasks count const { data: tasks = [] } = useQuery({ queryKey: ["/api/tasks", selectedStoreId], queryFn: async () => { const params = new URLSearchParams(); if (selectedStoreId) params.append('storeId', selectedStoreId.toString()); const response = await fetch(`/api/tasks?${params}`, { credentials: 'include' }); if (!response.ok) return []; const data = await response.json(); return Array.isArray(data) ? data : []; }, enabled: !!user, }); // Fetch today's orders const { data: orders = [] } = useQuery({ queryKey: ["/api/orders/today", selectedStoreId], queryFn: async () => { const params = new URLSearchParams(); if (selectedStoreId) params.append('storeId', selectedStoreId.toString()); params.append('date', format(new Date(), 'yyyy-MM-dd')); const response = await fetch(`/api/orders?${params}`, { credentials: 'include' }); if (!response.ok) return []; const data = await response.json(); return Array.isArray(data) ? data : []; }, enabled: !!user, }); // Fetch today's deliveries const { data: deliveries = [] } = useQuery({ queryKey: ["/api/deliveries/today", selectedStoreId], queryFn: async () => { const params = new URLSearchParams(); if (selectedStoreId) params.append('storeId', selectedStoreId.toString()); params.append('date', format(new Date(), 'yyyy-MM-dd')); const response = await fetch(`/api/deliveries?${params}`, { credentials: 'include' }); if (!response.ok) return []; const data = await response.json(); return Array.isArray(data) ? data : []; }, enabled: !!user, }); const pendingTasks = tasks.filter((t: any) => t.status !== 'completed').length; const urgentTasks = tasks.filter((t: any) => t.priority === 'high' && t.status !== 'completed').length; const todayDate = format(new Date(), "EEEE d MMMM", { locale: fr }); return (
{/* Welcome */}

Bonjour,

{user?.firstName || user?.username || 'Utilisateur'}

{todayDate}

{/* Stats Grid */}
{/* Quick Actions */}

Accès rapide

{[ { icon: Package, label: "Commande", path: "/orders" }, { icon: Truck, label: "Livraison", path: "/deliveries" }, { icon: CheckSquare, label: "Tâche", path: "/tasks" }, { icon: Calendar, label: "Agenda", path: "/calendar" }, ].map((item) => { const Icon = item.icon; return ( {item.label} ); })}
{/* Recent Tasks */} {pendingTasks > 0 && (

Tâches à faire

{tasks .filter((t: any) => t.status !== 'completed') .slice(0, 3) .map((task: any) => (

{task.title}

{task.dueDate && (

{format(new Date(task.dueDate), 'dd/MM')}

)}
)) }
)}
); }