diff --git a/Client/src/Components/Sidebar/index.jsx b/Client/src/Components/Sidebar/index.jsx index be7689235..0019a282a 100644 --- a/Client/src/Components/Sidebar/index.jsx +++ b/Client/src/Components/Sidebar/index.jsx @@ -43,6 +43,7 @@ import ArrowLeft from "../../assets/icons/left-arrow.svg?react"; import DotsVertical from "../../assets/icons/dots-vertical.svg?react"; import ChangeLog from "../../assets/icons/changeLog.svg?react"; import Docs from "../../assets/icons/docs.svg?react"; +import Folder from "../../assets/icons/folder.svg?react"; import "./index.css"; @@ -68,13 +69,16 @@ const menu = [ { name: "Team", path: "account/team", icon: }, ], }, -]; - -const other = [ - { name: "Settings", path: "settings", icon: }, - { name: "Support", path: "support", icon: }, - { name: "Docs", path: "docs", icon: }, - { name: "Changelog", path: "changelog", icon: }, + { + name: "Other", + icon: , + nested: [ + { name: "Settings", path: "settings", icon: }, + { name: "Support", path: "support", icon: }, + { name: "Docs", path: "docs", icon: }, + { name: "Changelog", path: "changelog", icon: }, + ], + }, ]; const URL_MAP = { @@ -83,6 +87,13 @@ const URL_MAP = { changelog: "https://github.com/bluewave-labs/bluewave-uptime/releases", }; +const PATH_MAP = { + monitors: "Dashboard", + pagespeed: "Dashboard", + account: "Account", + settings: "Other", +}; + /** * @component * Sidebar component serves as a sidebar containing a menu. @@ -97,7 +108,7 @@ function Sidebar() { const dispatch = useDispatch(); const authState = useSelector((state) => state.auth); const collapsed = useSelector((state) => state.ui.sidebar.collapsed); - const [open, setOpen] = useState({ Dashboard: false, Account: false }); + const [open, setOpen] = useState({ Dashboard: false, Account: false, Other: false }); const [anchorEl, setAnchorEl] = useState(null); const [popup, setPopup] = useState(); const { user } = useSelector((state) => state.auth); @@ -130,13 +141,13 @@ function Sidebar() { }; useEffect(() => { - if ( - location.pathname.includes("monitors") || - location.pathname.includes("pagespeed") - ) - setOpen((prev) => ({ ...prev, Dashboard: true })); - else if (location.pathname.includes("/account")) - setOpen((prev) => ({ ...prev, Account: true })); + const matchedKey = Object.keys(PATH_MAP).find((key) => + location.pathname.includes(key) + ); + + if (matchedKey) { + setOpen((prev) => ({ ...prev, [PATH_MAP[matchedKey]]: true })); + } }, []); return ( @@ -212,7 +223,9 @@ function Sidebar() { }, }} onClick={() => { - setOpen({ Dashboard: false, Account: false }); + setOpen(prev => + Object.fromEntries(Object.keys(prev).map(key => [key, false])) + ) dispatch(toggleSidebar()); }} > @@ -356,7 +369,12 @@ function Sidebar() { } key={child.path} onClick={() => { - navigate(`/${child.path}`); + const url = URL_MAP[child.path]; + if (url) { + window.open(url, "_blank", "noreferrer"); + } else { + navigate(`/${child.path}`); + } closePopup(); }} sx={{ @@ -382,8 +400,8 @@ function Sidebar() { setOpen((prev) => ({ - ...prev, - [`${item.name}`]: !prev[`${item.name}`], + ...Object.fromEntries(Object.keys(prev).map(key => [key, false])), + [item.name]: !prev[item.name] })) } sx={{ @@ -419,7 +437,14 @@ function Sidebar() { : "" } key={child.path} - onClick={() => navigate(`/${child.path}`)} + onClick={() => { + const url = URL_MAP[child.path]; + if (url) { + window.open(url, "_blank", "noreferrer"); + } else { + navigate(`/${child.path}`); + } + }} sx={{ gap: theme.spacing(4), borderRadius: theme.shape.borderRadius, @@ -465,69 +490,6 @@ function Sidebar() { ) )} - - {/* other */} - - Other - - } - sx={{ px: theme.spacing(6) }} - > - {other.map((item) => ( - - { - const url = URL_MAP[item.path]; - if (url) { - window.open(url, "_blank", "noreferrer"); - } else { - navigate(`/${item.path}`); - } - }} - sx={{ - gap: theme.spacing(4), - borderRadius: theme.shape.borderRadius, - px: theme.spacing(4), - }} - > - {item.icon} - {item.name} - - - ))} - + + + \ No newline at end of file