import AppBar from '@mui/material/AppBar'; import Box from '@mui/material/Box'; import Toolbar from '@mui/material/Toolbar'; import Typography from '@mui/material/Typography'; import Button from '@mui/material/Button'; import IconButton from '@mui/material/IconButton'; import MenuIcon from '@mui/icons-material/Menu'; import { MyLink } from './MyLink'; import { connect, useSelector } from 'react-redux'; import { useTheme } from '@emotion/react'; import { actionSetSidebar, getCartItemsCount, getIsSideBarOpen } from '../reducers'; import { UserEntity } from '../Entities'; import ShoppingCartIcon from '@mui/icons-material/ShoppingCart'; import { AccountCircle } from '@mui/icons-material'; import LogoutIcon from '@mui/icons-material/Logout'; import LoginIcon from '@mui/icons-material/Login'; import CategoryIcon from '@mui/icons-material/Category'; import SupervisedUserCircleIcon from '@mui/icons-material/SupervisedUserCircle'; import WorkHistoryIcon from '@mui/icons-material/WorkHistory'; import { Badge, Tooltip } from '@mui/material'; const MainAppBar = ({ token, openSidebar }) => { const theme = useTheme(); const cartItemsCount = useSelector(state => getCartItemsCount(state) ?? 0); let currentUser = useSelector(state => new UserEntity(state.auth?.currentUser ?? { _id: null })); let isAdmin = currentUser?.isAdminRole === true; let isLoggedIn = token && true; return ( openSidebar(true)} sx={{ mr: 2 }} > { !isLoggedIn && <> } { isLoggedIn && <> {isAdmin && ( <> )} } { isLoggedIn && <> } ); } export const CMainAppBar = connect(state => ({ token: state.auth?.token, sidebarOpened: getIsSideBarOpen(state) }), { openSidebar: actionSetSidebar })(MainAppBar);