Merge pull request #114 from MuhammadKhalilzadeh/re-navbar-side-menu
Anding routing fixing bugs
This commit is contained in:
6 files changed
+145
-526
No files matched your search
Generated
+79
-514
File diff suppressed because it is too large.
Load diff
+1
-1
@@ -27,7 +27,7 @@
|
|||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-redux": "9.1.2",
|
"react-redux": "9.1.2",
|
||||||
"react-router": "^6.23.0",
|
"react-router": "^6.23.0",
|
||||||
"react-router-dom": "^6.23.0"
|
"react-router-dom": "^6.23.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/react": "^18.2.66",
|
"@types/react": "^18.2.66",
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ import Incidents from "../../assets/Images/Icon-warning-gray.png";
|
|||||||
import SensorsIcon from "../../assets/Images/Icon-signal-gray.png";
|
import SensorsIcon from "../../assets/Images/Icon-signal-gray.png";
|
||||||
import AllInclusiveIcon from "../../assets/Images/Icon-link-gray.png";
|
import AllInclusiveIcon from "../../assets/Images/Icon-link-gray.png";
|
||||||
import SettingsIcon from "../../assets/Images/Icon-setting-gray.png";
|
import SettingsIcon from "../../assets/Images/Icon-setting-gray.png";
|
||||||
|
import React, { useState, useEffect } from "react";
|
||||||
|
import { useNavigate, useLocation } from "react-router-dom";
|
||||||
|
import pathMap from "../../Utils/PathMap";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @component
|
* @component
|
||||||
@@ -16,13 +19,56 @@ import SettingsIcon from "../../assets/Images/Icon-setting-gray.png";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function DashboardMenu() {
|
function DashboardMenu() {
|
||||||
|
const [activeButton, setActiveButton] = useState(null);
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setActiveButton(location.pathname);
|
||||||
|
}, [location]);
|
||||||
|
|
||||||
|
const handleClick = (title, path) => {
|
||||||
|
setActiveButton(title);
|
||||||
|
navigate(path);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="dashboard-menu-container">
|
<div className="dashboard-menu-container">
|
||||||
{DashboardMenuButton(Monitors, "Monitors", "/monitors")}
|
{DashboardMenuButton(
|
||||||
{DashboardMenuButton(Incidents, "Incidents", "/incidents")}
|
Monitors,
|
||||||
{DashboardMenuButton(SensorsIcon, "Status Pages", "/status")}
|
"Monitors",
|
||||||
{DashboardMenuButton(AllInclusiveIcon, "Integrations", "/integrations")}
|
"/monitors",
|
||||||
{DashboardMenuButton(SettingsIcon, "Settings", "/settings")}
|
activeButton === "/monitors",
|
||||||
|
() => handleClick(pathMap["/monitors"], "/monitors")
|
||||||
|
)}
|
||||||
|
{DashboardMenuButton(
|
||||||
|
Incidents,
|
||||||
|
"Incidents",
|
||||||
|
"/incidents",
|
||||||
|
activeButton === "/incidents",
|
||||||
|
() => handleClick(pathMap["/incidents"], "/incidents")
|
||||||
|
)}
|
||||||
|
{DashboardMenuButton(
|
||||||
|
SensorsIcon,
|
||||||
|
"Status Pages",
|
||||||
|
"/status",
|
||||||
|
activeButton === "/status",
|
||||||
|
() => handleClick(pathMap["/status"], "/status")
|
||||||
|
)}
|
||||||
|
{DashboardMenuButton(
|
||||||
|
AllInclusiveIcon,
|
||||||
|
"Integrations",
|
||||||
|
"/integrations",
|
||||||
|
activeButton === "/integrations",
|
||||||
|
() => handleClick(pathMap["/integrations"], "/integrations")
|
||||||
|
)}
|
||||||
|
{DashboardMenuButton(
|
||||||
|
SettingsIcon,
|
||||||
|
"Settings",
|
||||||
|
"/settings",
|
||||||
|
activeButton === "/settings",
|
||||||
|
() => handleClick(pathMap["/settings"], "/settings")
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,9 @@ import { useNavigate } from "react-router-dom";
|
|||||||
* @returns {React.ReactElement} The rendered menu button component.
|
* @returns {React.ReactElement} The rendered menu button component.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const DashboardMenuButton = (icon, title, to) => {
|
const DashboardMenuButton = (icon, title, to, isActive, onClick) => {
|
||||||
const [isActive, setIsActive] = useState(false);
|
|
||||||
const navigate = useNavigate();
|
|
||||||
|
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
setIsActive(!isActive);
|
onClick();
|
||||||
navigate(to);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
const pathMap = {
|
||||||
|
"/monitors": "Monitors",
|
||||||
|
"/incidents": "Incidents",
|
||||||
|
"/status" : "Status Pages",
|
||||||
|
"/integrations": "Integrations",
|
||||||
|
"/settings" : "Settings"
|
||||||
|
}
|
||||||
|
|
||||||
|
export default pathMap;
|
||||||
@@ -4,4 +4,7 @@ import react from '@vitejs/plugin-react'
|
|||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
|
optimizeDeps: {
|
||||||
|
include: ['@mui/material/Tooltip', '@emotion/styled'],
|
||||||
|
},
|
||||||
})
|
})
|
||||||
Reference in new issue
Block a user