navigation.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import React from "react";
  2. // import Scrollchor from 'react-scrollchor';
  3. import { Link, withRouter } from "react-router-dom";
  4. import { connect } from "react-redux";
  5. import Button from "../button";
  6. const header = props => {
  7. const liArr = [
  8. { path: "/", id: 1, text: "Главная", hideWhenAuth:false},
  9. { path: "/doctors", id: 2, text: "Специалисты", hideWhenAuth:false },
  10. { path: "/services", id: 3, text: "Услуги", hideWhenAuth:false},
  11. { path: "/reviews", id: 4, text: "Отзывы", hideWhenAuth:false },
  12. { path: "/auth", id: 5, text: "Войти", hideWhenAuth:true
  13. // Object.keys(props.user).length > 0 ?
  14. // props.user.role === "Admin" ? "Admin"
  15. // : props.user.role === "Doctor"
  16. // ? "Doctor"
  17. // : "Logout"
  18. // : "Войти"
  19. }
  20. ];
  21. return <nav className=" nav icon-dehaze"
  22. // onClick = { ( ) => { document.querySelector('.list').style.display = " block" } }
  23. >
  24. <ul className=" list ">
  25. {liArr.map(el =>
  26. el.hideWhenAuth && props.user.role ? null :
  27. (
  28. <li className="item" key={el.id}>
  29. <Link to={el.path}>{el.text}</Link>
  30. </li>
  31. )
  32. )}
  33. {Object.keys(props.user).length > 0 ?
  34. props.user.role === "Admin" ? (
  35. <li className="item" key={6}>
  36. <Link to={ "/admin"}>{"Admin"}</Link>
  37. <Button text="Logout" />
  38. </li>
  39. ) : props.user.role === "Doctor" ?
  40. (<li className="item" key={6}>
  41. <Link to={ "/admin"}>{"Doctor"}</Link>
  42. <Button text="Logout" />
  43. </li>) : (<li className="item" key={6}>
  44. <Link to={ "/user"}>{"User"}</Link>
  45. <Button text="Logout" />
  46. </li>)
  47. : null
  48. }
  49. </ul>
  50. </nav>
  51. };
  52. const mapStateToProps = state => ({
  53. user: state.auth.user
  54. });
  55. export default connect(mapStateToProps)(withRouter(header));