feat: URL-based navigation via ?tab= param for shareable links
This commit is contained in:
parent
15f2ab3cde
commit
0f32d6d73a
|
|
@ -1,5 +1,5 @@
|
||||||
import React from "react";
|
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 { DriverDeliveryPlanner } from "../components/driver/DriverDeliveryPlanner";
|
||||||
import { LogisticsReadinessBoard } from "../components/logistics/LogisticsReadinessBoard";
|
import { LogisticsReadinessBoard } from "../components/logistics/LogisticsReadinessBoard";
|
||||||
import { OrdersTable } from "../components/orders/OrdersTable";
|
import { OrdersTable } from "../components/orders/OrdersTable";
|
||||||
|
|
@ -33,11 +33,21 @@ const ROLE_SECTION = {
|
||||||
export const DashboardPage = () => {
|
export const DashboardPage = () => {
|
||||||
const { user, signOut } = useAuth();
|
const { user, signOut } = useAuth();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const [searchParams, setSearchParams] = useSearchParams();
|
||||||
const userRole = user?.role;
|
const userRole = user?.role;
|
||||||
const isMegaAdmin = userRole === "mega_admin";
|
const isMegaAdmin = userRole === "mega_admin";
|
||||||
const isAdmin = userRole === "admin" || isMegaAdmin;
|
const isAdmin = userRole === "admin" || isMegaAdmin;
|
||||||
const section = ROLE_SECTION[userRole] || ROLE_SECTION.manager;
|
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 {
|
const {
|
||||||
notifications,
|
notifications,
|
||||||
|
|
@ -70,10 +80,6 @@ export const DashboardPage = () => {
|
||||||
loadError,
|
loadError,
|
||||||
} = useOrderGroups();
|
} = useOrderGroups();
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
setActiveSection(section.key);
|
|
||||||
}, [section.key]);
|
|
||||||
|
|
||||||
const openGroupPage = React.useCallback((groupId) => {
|
const openGroupPage = React.useCallback((groupId) => {
|
||||||
navigate("/dashboard/group/" + groupId);
|
navigate("/dashboard/group/" + groupId);
|
||||||
}, [navigate]);
|
}, [navigate]);
|
||||||
|
|
@ -132,7 +138,7 @@ export const DashboardPage = () => {
|
||||||
onInstallApp={onInstallApp}
|
onInstallApp={onInstallApp}
|
||||||
isInstalled={isInstalled}
|
isInstalled={isInstalled}
|
||||||
isInstallAvailable={isInstallAvailable}
|
isInstallAvailable={isInstallAvailable}
|
||||||
onOpenGuide={() => setActiveSection((current) => (current === "guide" ? section.key : "guide"))}
|
onOpenGuide={() => setActiveSection("guide")}
|
||||||
isGuideOpen={isGuideOpen}
|
isGuideOpen={isGuideOpen}
|
||||||
navItems={navItems}
|
navItems={navItems}
|
||||||
activeSection={activeSection}
|
activeSection={activeSection}
|
||||||
|
|
@ -156,4 +162,4 @@ export const DashboardPage = () => {
|
||||||
{renderActiveSection()}
|
{renderActiveSection()}
|
||||||
</AppShell>
|
</AppShell>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue