|
@@ -1,29 +1,66 @@
|
|
import React from "react";
|
|
import React from "react";
|
|
// import Scrollchor from 'react-scrollchor';
|
|
// import Scrollchor from 'react-scrollchor';
|
|
-import {Link} from 'react-router-dom'
|
|
|
|
|
|
+import { Link, withRouter } from "react-router-dom";
|
|
|
|
+import { connect } from "react-redux";
|
|
|
|
|
|
|
|
+import Button from "../button";
|
|
|
|
|
|
|
|
|
|
-const liArr = [
|
|
|
|
- { path: "/", id: 1, text: "Главная" },
|
|
|
|
- { path: "/doctors", id: 2, text: "Специалисты" },
|
|
|
|
- { path: "/services", id: 3, text: "Услуги" },
|
|
|
|
- { path: "/reviews", id: 4, text: "Отзывы" },
|
|
|
|
- { path: "/admin", id: 5, text: "Admin"},
|
|
|
|
- { path: "/auth", id: 6, text: "Войти", hideWhenAuth: true }
|
|
|
|
-];
|
|
|
|
|
|
|
|
-export default ( props ) => (
|
|
|
|
- <nav className=" nav icon-dehaze"
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+const header = props => {
|
|
|
|
+ const liArr = [
|
|
|
|
+ { path: "/", id: 1, text: "Главная", hideWhenAuth:false},
|
|
|
|
+ { path: "/doctors", id: 2, text: "Специалисты", hideWhenAuth:false },
|
|
|
|
+ { path: "/services", id: 3, text: "Услуги", hideWhenAuth:false},
|
|
|
|
+ { path: "/reviews", id: 4, text: "Отзывы", hideWhenAuth:false },
|
|
|
|
+ { path: "/auth", id: 5, text: "Войти", hideWhenAuth:true
|
|
|
|
+ // Object.keys(props.user).length > 0 ?
|
|
|
|
+ // props.user.role === "Admin" ? "Admin"
|
|
|
|
+ // : props.user.role === "Doctor"
|
|
|
|
+ // ? "Doctor"
|
|
|
|
+ // : "Logout"
|
|
|
|
+ // : "Войти"
|
|
|
|
+ }
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ return <nav className=" nav icon-dehaze"
|
|
// onClick = { ( ) => { document.querySelector('.list').style.display = " block" } }
|
|
// onClick = { ( ) => { document.querySelector('.list').style.display = " block" } }
|
|
>
|
|
>
|
|
<ul className=" list ">
|
|
<ul className=" list ">
|
|
- {liArr.map(el => (
|
|
|
|
- <li className="item" key={el.id}>
|
|
|
|
- <Link to={el.path}>{el.text}</Link>
|
|
|
|
|
|
+ {liArr.map(el =>
|
|
|
|
+ el.hideWhenAuth && props.user.role ? null :
|
|
|
|
+ (
|
|
|
|
+ <li className="item" key={el.id}>
|
|
|
|
+ <Link to={el.path}>{el.text}</Link>
|
|
|
|
+ </li>
|
|
|
|
+ )
|
|
|
|
+ )}
|
|
|
|
+ {Object.keys(props.user).length > 0 ?
|
|
|
|
+ props.user.role === "Admin" ? (
|
|
|
|
+ <li className="item" key={6}>
|
|
|
|
+ <Link to={ "/admin"}>{"Admin"}</Link>
|
|
|
|
+ <Button text="Logout" />
|
|
</li>
|
|
</li>
|
|
- ) ) }
|
|
|
|
|
|
+
|
|
|
|
+ ) : props.user.role === "Doctor" ?
|
|
|
|
+ (<li className="item" key={6}>
|
|
|
|
+ <Link to={ "/admin"}>{"Doctor"}</Link>
|
|
|
|
+ <Button text="Logout" />
|
|
|
|
+ </li>) : (<li className="item" key={6}>
|
|
|
|
+ <Link to={ "/user"}>{"User"}</Link>
|
|
|
|
+ <Button text="Logout" />
|
|
|
|
+ </li>)
|
|
|
|
+ : null
|
|
|
|
+ }
|
|
</ul>
|
|
</ul>
|
|
</nav>
|
|
</nav>
|
|
-);
|
|
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+const mapStateToProps = state => ({
|
|
|
|
+ user: state.auth.user
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+export default connect(mapStateToProps)(withRouter(header));
|
|
|
|
|