"use client"; import { useRouter } from "next/navigation"; import { useEffect } from "react"; import { clearAuth, getStoredUser } from "@/src/lib/auth"; import { Spinner, Alert } from "@/src/Components/UI"; import { useDashboardOverview } from "@/src/hooks/useDashboardOverview"; import { KpiSection, AlertsSection, RecentActivityPanel, TrendChartsPanel, QuickAccessFooter, } from "@/src/Components/Dashboard"; export default function DashboardPage() { const router = useRouter(); const { data, error, loading } = useDashboardOverview(); useEffect(() => { const storedUser = getStoredUser(); const role = typeof storedUser?.role === "string" ? storedUser.role : ""; if (!role || ["driver", "سائق"].includes(role)) { clearAuth(); router.replace("/login"); } }, [router]); const activeTrips = data?.activeTrips || []; return (
{/* ── Header ── */}

لوحة العمليات

ذكاء الأسطول في لمحة سريعة

عرض واضح لكل وحدة من وحدات المنصة، مع تنبيهات فورية واتجاهات الأداء.

{/* ── Loading ── */} {loading && !data && (
جارٍ تحميل البيانات…
)} {/* ── Error ── */} {error && ( )} {/* ── KPI Section: total / active / pending per entity (9 cards) ── */} {/* ── Alerts Section: urgent cross-entity issues ── */} {/* ── Insights Row: recent activity log + trend charts ── */}
{/* ── Quick access to every entity page (minimizes navigation clicks) ── */} {/* ── Active trips (kept from the previous layout — live operational detail) ── */}

الرحلات النشطة

تقدم الرحلات

مباشر
{activeTrips.length ? activeTrips.map((trip) => (

{trip.tripNumber}

{trip.title}

{trip.progress}%
)) : (

لا توجد رحلات نشطة حالياً.

)}
{/* ── Security + endpoints ── */}

الأمان

لمحة الحساب

آخر تسجيل دخول: {data?.accountSecurity?.lastLogin || "—"}
بيانات الجهاز: {data?.accountSecurity?.requestMeta ? JSON.stringify(data.accountSecurity.requestMeta) : "—"}

خريطة الخلفية

النقاط النهائية

    {[ "/v1/dashboard/overview — نظرة عامة تشغيلية", "/v1/client — إدارة العملاء", "/v1/orders — دورة شحن الطلبات", "/v1/trip — تنظيم الرحلات", ].map((ep) => (
  • {ep.split(" — ")[0]} {" — "} {ep.split(" — ")[1]}
  • ))}
); }