diff --git a/src/pages/DashboardPage.jsx b/src/pages/DashboardPage.jsx index e233ec7..8a12f39 100644 --- a/src/pages/DashboardPage.jsx +++ b/src/pages/DashboardPage.jsx @@ -1,5 +1,5 @@ import React from "react"; -import { Navigate, useNavigate } from "react-router-dom"; +import { Navigate, useNavigate, useSearchParams } from "react-router-dom"; import { DriverDeliveryPlanner } from "../components/driver/DriverDeliveryPlanner"; import { LogisticsReadinessBoard } from "../components/logistics/LogisticsReadinessBoard"; import { OrdersTable } from "../components/orders/OrdersTable"; @@ -33,11 +33,21 @@ const ROLE_SECTION = { export const DashboardPage = () => { const { user, signOut } = useAuth(); const navigate = useNavigate(); + const [searchParams, setSearchParams] = useSearchParams(); const userRole = user?.role; const isMegaAdmin = userRole === "mega_admin"; const isAdmin = userRole === "admin" || isMegaAdmin; const section = ROLE_SECTION[userRole] || ROLE_SECTION.manager; - const [activeSection, setActiveSection] = React.useState(section.key); + + // Active section from URL, fallback to role default + const activeSection = searchParams.get("tab") || section.key; + const setActiveSection = (key) => { + if (key === section.key) { + setSearchParams({}, { replace: true }); // default tab → clean URL + } else { + setSearchParams({ tab: key }, { replace: true }); + } + }; const { notifications, @@ -70,10 +80,6 @@ export const DashboardPage = () => { loadError, } = useOrderGroups(); - React.useEffect(() => { - setActiveSection(section.key); - }, [section.key]); - const openGroupPage = React.useCallback((groupId) => { navigate("/dashboard/group/" + groupId); }, [navigate]); @@ -132,7 +138,7 @@ export const DashboardPage = () => { onInstallApp={onInstallApp} isInstalled={isInstalled} isInstallAvailable={isInstallAvailable} - onOpenGuide={() => setActiveSection((current) => (current === "guide" ? section.key : "guide"))} + onOpenGuide={() => setActiveSection("guide")} isGuideOpen={isGuideOpen} navItems={navItems} activeSection={activeSection} @@ -156,4 +162,4 @@ export const DashboardPage = () => { {renderActiveSection()} ); -}; \ No newline at end of file +};