{"size": 933, "ext": "js", "max_stars_repo_path": "frontend_web/src/components/menus/Pages.js", "max_stars_repo_name": "ezrankayamba/twiga_sales", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "frontend_web/src/components/menus/Pages.js", "max_issues_repo_name": "ezrankayamba/twiga_sales", "max_issues_repo_issues_event_min_datetime": "2020-03-14T17:29:33.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-12T00:19:30.000Z", "max_forks_repo_path": "frontend_web/src/components/menus/Pages.js", "max_forks_repo_name": "ezrankayamba/twiga_sales", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 33, "max_forks_count": null, "avg_line_length": 23.9230769231, "max_line_length": 60, "alphanum_fraction": 0.5509110397}
import React, { Component } from "react";
import { Route, Switch, Redirect } from "react-router-dom";
import getMenus from "./menus";
import { connect } from "react-redux";
import { getPrivileges } from "../../_services/AuthService";

@connect((state) => {
  return {
    loggedIn: state.auth.loggedIn,
    user: state.auth.user,
  };
})
class Pages extends Component {
  render() {
    const { user } = this.props;
    let privileges = getPrivileges(user);
    let menus = getMenus(this.props.loggedIn, privileges);
    console.log(menus);
    let role = user.profile.role;
    return (
      <Switch>
        {menus.map((item) => {
          return (
            <Route
              key={item.id}
              exact
              path={item.path}
              component={item.component}
            />
          );
        })}
        <Redirect to={role ? role.path : "/"} />
      </Switch>
    );
  }
}

export default Pages;
