text: import React, { Fragment, useEffect } from "react";
  // Styles
  import 'bootstrap/dist/css/bootstrap.css';
  // routes
  import routes from '../../../routes';
  // header and footer
  import Header from '../../Helpers/Header'
  import { FetchAllLeads } from "../../../actions/leads";
  import Sidebar from '../../Helpers/Sidebar'
  import { connect } from 'react-redux'
  import { CheckAndSaveLoggedInData } from "../../../actions/users";
  import { Wrap } from "../../../StyledComponents";
  // import { allPages } from "../../Helpers/Sidebar/totalButtons";
  
  
  const Deshboard = (props) => {
    const { toggle, history, fetchAllLeads, checkAndSaveLoggedInData } = props
    // const router = useSelector((state) => state.router)
    // const role = useSelector((state) => state.users.User.Login)
  
    // const pathName = router.location.pathname
    // const obj = allPages.find((item) => { return item.url === pathName || pathName.indexOf(item.url) >= 0 })
  
  
    useEffect(() => {
      checkAndSaveLoggedInData();
    }, [checkAndSaveLoggedInData, fetchAllLeads])
    fetchAllLeads('pending').then((res) => { if (res.type === "FETCH_ALL_LEADS_FAILED" && res.data && res.data.status === 401) { localStorage.clear(); window.location.href = '/' } })
  
    if (localStorage.length > 0) {
      return (
        <Fragment>
          <header>
            <Header />
          </header>
          <section className="secMainSidebarGrid">
            <Sidebar history={history} />
            <Wrap className={`rightContentWrap ${toggle === true ? 'toggleLeftSide' : ''}`}>
              {routes}
              {/* {obj && !obj.roles.includes(role && role.role) ? window.location.href = '/' : routes} */}
            </Wrap>
          </section>
        </Fragment>
  
      );
    } else {
      history.push('/')
      return null;
    }
  }
  
  const mapStateToProps = (state) => {
    return {
      toggle: state.sidebarToggle.sidebarToggle.active
    }
  }
  
  const mapDispatchToProps = (dispatch) => {
    return {
      checkAndSaveLoggedInData: () => dispatch(CheckAndSaveLoggedInData()),
      fetchAllLeads: (status) => dispatch(FetchAllLeads(status)),
    }
  };
  
  export default connect(mapStateToProps, mapDispatchToProps)(Deshboard)
  