diff --git a/src/views/Dashboard/layouts/SidebarMenu/index.js b/src/views/Dashboard/layouts/SidebarMenu/index.js index fd2926a..16e4ccf 100644 --- a/src/views/Dashboard/layouts/SidebarMenu/index.js +++ b/src/views/Dashboard/layouts/SidebarMenu/index.js @@ -2,7 +2,7 @@ import React, { useState, useEffect } from "react"; import Avatar from "../../../../components/Avatar"; import { connect } from "react-redux"; import { useNavigate } from "react-router-dom"; -import { user, dialog } from "../../../../redux/actions"; +import { user, dialog, publicApi } from "../../../../redux/actions"; const SidebarMenu = ({ page, @@ -11,6 +11,8 @@ const SidebarMenu = ({ setDialog, user, sidebar, + changeDarkMode, + isDark, }) => { const navigate = useNavigate(); const [activeDropdown, setActiveDropdown] = useState(null); @@ -25,87 +27,95 @@ const SidebarMenu = ({ accept: () => logout(), open: true, }), + dark: () => changeDarkMode(!isDark), }; - }, [user]); + }, [user, isDark]); - const Dropdown = React.useCallback(({item}) => { - return ( -
-
{ - if (item?.menu?.length <= 1) { - if (item?.name === "logout") { - actions['logout'](); - return; - } - if (item?.name === "dark") { - return false; + const Dropdown = React.useCallback( + ({ item }) => { + return ( +
+
{ + if (item?.menu?.length <= 1) { + if (item?.name === "logout") { + actions["logout"](); + return; + } + if (item?.name === "dark") { + actions["dark"](); + return; + } + actions["page"](item?.name); + } else { + setActiveDropdown(item?.name); } - actions['page'](item?.name); - } else { - setActiveDropdown(item?.name); - } - }} - > -
- - - {item?.title} - + }} + > +
+ + + {item?.title} + +
+ {item?.menu?.length > 1 ? ( + + ) : null}
{item?.menu?.length > 1 ? ( - + > + {item?.menu.map((menuItem, index) => ( +
  • + page !== menuItem.value ? setPage(menuItem.value) : {} + } + > + + {menuItem?.title} + +
  • + ))} + ) : null}
    - {item?.menu?.length > 1 ? ( -
      - {item?.menu.map((menuItem, index) => ( -
    • - page !== menuItem.value ? setPage(menuItem.value) : {} - } - > - - {menuItem?.title} - -
    • - ))} -
    - ) : null} -
    - ); - },[page, activeDropdown]); + ); + }, + [page, activeDropdown, isDark] + ); useEffect(() => { if (!user) { @@ -123,7 +133,15 @@ const SidebarMenu = ({ > {sidebar?.userInfo ? (
    - +

    {user.firstName === null ? "" @@ -141,11 +159,13 @@ const SidebarMenu = ({ const mapStateToProps = (state) => ({ user: state.user.status, sidebar: state.dashboard.sidebar, + isDark: state.publicApi.isDark, }); const mapDispatchToProps = { logout: user.logout, setDialog: dialog.set, + changeDarkMode: publicApi.setIsDark, }; export default connect(mapStateToProps, mapDispatchToProps)(SidebarMenu);