update src/views/Dashboard/layouts/SidebarMenu/index.js

master
Reza_ashrafi 2 years ago
parent fab86aa933
commit f763cef073
  1. 38
      src/views/Dashboard/layouts/SidebarMenu/index.js

@ -2,7 +2,7 @@ import React, { useState, useEffect } from "react";
import Avatar from "../../../../components/Avatar"; import Avatar from "../../../../components/Avatar";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { user, dialog } from "../../../../redux/actions"; import { user, dialog, publicApi } from "../../../../redux/actions";
const SidebarMenu = ({ const SidebarMenu = ({
page, page,
@ -11,6 +11,8 @@ const SidebarMenu = ({
setDialog, setDialog,
user, user,
sidebar, sidebar,
changeDarkMode,
isDark,
}) => { }) => {
const navigate = useNavigate(); const navigate = useNavigate();
const [activeDropdown, setActiveDropdown] = useState(null); const [activeDropdown, setActiveDropdown] = useState(null);
@ -25,10 +27,12 @@ const SidebarMenu = ({
accept: () => logout(), accept: () => logout(),
open: true, open: true,
}), }),
dark: () => changeDarkMode(!isDark),
}; };
}, [user]); }, [user, isDark]);
const Dropdown = React.useCallback(({item}) => { const Dropdown = React.useCallback(
({ item }) => {
return ( return (
<div className="flex flex-col"> <div className="flex flex-col">
<div <div
@ -40,13 +44,14 @@ const SidebarMenu = ({
onClick={() => { onClick={() => {
if (item?.menu?.length <= 1) { if (item?.menu?.length <= 1) {
if (item?.name === "logout") { if (item?.name === "logout") {
actions['logout'](); actions["logout"]();
return; return;
} }
if (item?.name === "dark") { if (item?.name === "dark") {
return false; actions["dark"]();
return;
} }
actions['page'](item?.name); actions["page"](item?.name);
} else { } else {
setActiveDropdown(item?.name); setActiveDropdown(item?.name);
} }
@ -54,7 +59,10 @@ const SidebarMenu = ({
> >
<div className="flex items-center"> <div className="flex items-center">
<img <img
src={item?.icon + (item?.name === page ? "-white.svg" : "-primary.svg")} src={
item?.icon +
(item?.name === page ? "-white.svg" : "-primary.svg")
}
alt="" alt=""
className="ml-2 w-6 mb-1" className="ml-2 w-6 mb-1"
/> />
@ -105,7 +113,9 @@ const SidebarMenu = ({
) : null} ) : null}
</div> </div>
); );
},[page, activeDropdown]); },
[page, activeDropdown, isDark]
);
useEffect(() => { useEffect(() => {
if (!user) { if (!user) {
@ -123,7 +133,15 @@ const SidebarMenu = ({
> >
{sidebar?.userInfo ? ( {sidebar?.userInfo ? (
<div className="flex items-center mb-10"> <div className="flex items-center mb-10">
<Avatar size={60} rounded={true} /> <Avatar
source={
user?.picFileId
? `https://dnvn.ir/api/v1/file/${user?.picFileId}`
: null
}
size={60}
rounded={'rounded-full'}
/>
<p className="text-green7B font-bold text-base flex-1 mx-2"> <p className="text-green7B font-bold text-base flex-1 mx-2">
{user.firstName === null {user.firstName === null
? "" ? ""
@ -141,11 +159,13 @@ const SidebarMenu = ({
const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
user: state.user.status, user: state.user.status,
sidebar: state.dashboard.sidebar, sidebar: state.dashboard.sidebar,
isDark: state.publicApi.isDark,
}); });
const mapDispatchToProps = { const mapDispatchToProps = {
logout: user.logout, logout: user.logout,
setDialog: dialog.set, setDialog: dialog.set,
changeDarkMode: publicApi.setIsDark,
}; };
export default connect(mapStateToProps, mapDispatchToProps)(SidebarMenu); export default connect(mapStateToProps, mapDispatchToProps)(SidebarMenu);

Loading…
Cancel
Save