|
@@ -1,67 +1,82 @@
|
|
-import React from 'react';
|
|
|
|
-import { Link } from "react-router-dom";
|
|
|
|
|
|
+import React, { PureComponent } from 'react';
|
|
|
|
+import { Link, withRouter, Redirect } from "react-router-dom";
|
|
import { connect } from 'react-redux';
|
|
import { connect } from 'react-redux';
|
|
-import { bindActionCreators } from 'redux';
|
|
|
|
|
|
+import storageKey from './../../utils/storageKey';
|
|
|
|
|
|
-import * as routes from '../../constants/routes'
|
|
|
|
-import logOut from './../../actions/auth/logOut';
|
|
|
|
|
|
+import * as routes from '../../constants/routes';
|
|
|
|
+import logOut from '../../actions/auth/logOut';
|
|
|
|
|
|
-class Header extends React.Component {
|
|
|
|
|
|
+//pure component + make storage check an action -> connect router
|
|
|
|
+class Header extends PureComponent {
|
|
handleLogOut = () => {
|
|
handleLogOut = () => {
|
|
- const { logOut } = this.props;
|
|
|
|
- logOut()
|
|
|
|
- //TODO: REDIRECT
|
|
|
|
|
|
+ const { history: { push } } = this.props;
|
|
}
|
|
}
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
|
+ const { role, logOutStatus } = this.props;
|
|
|
|
+
|
|
return (
|
|
return (
|
|
- <nav class="navbar navbar-expand-lg navbar-dark bg-dark p-3">
|
|
|
|
- <Link to={routes.LANDING} class="navbar-brand" href="#">Test.io</Link>
|
|
|
|
- <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
|
|
|
- <span class="navbar-toggler-icon" />
|
|
|
|
|
|
+ <nav className="navbar navbar-expand-lg navbar-dark bg-dark p-3">
|
|
|
|
+ <Link to={routes.LANDING} className="navbar-brand" href="#">Test.io</Link>
|
|
|
|
+ <button className="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
|
|
|
+ <span className="navbar-toggler-icon" />
|
|
</button>
|
|
</button>
|
|
|
|
|
|
- <div class="collapse navbar-collapse" id="navbarSupportedContent">
|
|
|
|
- <ul class="navbar-nav mr-auto">
|
|
|
|
- <li class="nav-item active">
|
|
|
|
- <Link onClick={this.handleClick} class="nav-link" to={routes.HOME}>Home <span class="sr-only">(current)</span></Link>
|
|
|
|
|
|
+ <div className="collapse navbar-collapse" id="navbarSupportedContent">
|
|
|
|
+ <ul className="navbar-nav mr-auto">
|
|
|
|
+ <li className="nav-item active">
|
|
|
|
+ <Link onClick={this.handleClick} className="nav-link" to={routes.HOME}>Home <span className="sr-only">(current)</span></Link>
|
|
</li>
|
|
</li>
|
|
- <li class="nav-item">
|
|
|
|
- <Link onClick={this.handleClick} class="nav-link" to={routes.PROFILE}>Profile</Link>
|
|
|
|
|
|
+ <li className="nav-item">
|
|
|
|
+ <Link onClick={this.handleClick} className="nav-link" to={routes.PROFILE}>Profile</Link>
|
|
</li>
|
|
</li>
|
|
- <li class="nav-item">
|
|
|
|
- <Link onClick={this.handleClick} class="nav-link" to={routes.TESTS}>Tests</Link>
|
|
|
|
|
|
+ <li className="nav-item">
|
|
|
|
+ <Link onClick={this.handleClick} className="nav-link" to={routes.TESTS}>Tests</Link>
|
|
</li>
|
|
</li>
|
|
- <li class="nav-item">
|
|
|
|
- <Link onClick={this.handleClick} class="nav-link" to={routes.CATEGORIES}>Catigories</Link>
|
|
|
|
|
|
+ <li className="nav-item">
|
|
|
|
+ <Link onClick={this.handleClick} className="nav-link" to={routes.CATEGORIES}>Catigories</Link>
|
|
</li>
|
|
</li>
|
|
{/* TODO: admin-only ! */}
|
|
{/* TODO: admin-only ! */}
|
|
- <li class="nav-item dropdown">
|
|
|
|
- <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
|
|
|
- Dropdown
|
|
|
|
|
|
+ {
|
|
|
|
+ role
|
|
|
|
+ ?
|
|
|
|
+ <li className="nav-item dropdown">
|
|
|
|
+ {/* eslint-disable-next-line */}
|
|
|
|
+ <a className="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
|
|
|
+ Dropdown
|
|
</a>
|
|
</a>
|
|
- <div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
|
|
|
- <Link to={routes.CREATE_TEST} className="nav-link text-secondary">Create Test</Link>
|
|
|
|
- <Link to={routes.CREATE_CATEGORY} className="nav-link text-secondary">Create Category</Link>
|
|
|
|
-
|
|
|
|
- <div class="dropdown-divider"></div>
|
|
|
|
- <a class="nav-link text-secondary" href="#">Something else here</a>
|
|
|
|
- </div>
|
|
|
|
- </li>
|
|
|
|
|
|
+ <div className="dropdown-menu" aria-labelledby="navbarDropdown">
|
|
|
|
+ <Link to={routes.CREATE_TEST} className="nav-link text-secondary">Create Test</Link>
|
|
|
|
+ <Link to={routes.CREATE_CATEGORY} className="nav-link text-secondary">Create Category</Link>
|
|
|
|
|
|
|
|
+ <div className="dropdown-divider"></div>
|
|
|
|
+ {/* eslint-disable-next-line */}
|
|
|
|
+ <a className="nav-link text-secondary" href="#">Something else here</a>
|
|
|
|
+ </div>
|
|
|
|
+ </li>
|
|
|
|
+ :
|
|
|
|
+ null
|
|
|
|
+ }
|
|
</ul>
|
|
</ul>
|
|
- <form class="form-inline my-lg-0">
|
|
|
|
- <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search" />
|
|
|
|
- <button class="btn btn-outline-success my-2 my-sm-0 mr-2" type="submit">Search</button>
|
|
|
|
|
|
+ <form className="form-inline my-lg-0">
|
|
|
|
+ <input className="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search" />
|
|
|
|
+ <button className="btn btn-outline-success my-2 my-sm-0 mr-2" type="submit">Search</button>
|
|
</form>
|
|
</form>
|
|
- <div className="">
|
|
|
|
- <Link to={routes.SIGN_IN}>
|
|
|
|
- <button className="btn btn-outline-primary">Sign In</button>
|
|
|
|
- </Link>
|
|
|
|
- <Link to={routes.SIGN_UP}>
|
|
|
|
- <button className="btn btn-outline-primary mx-2">Sign Up</button>
|
|
|
|
- </Link>
|
|
|
|
- <button onClick={this.handleLogOut} className="btn btn-outline-primary">Log Out</button>
|
|
|
|
|
|
+ <div className="controls">
|
|
|
|
+ {
|
|
|
|
+ role !== null
|
|
|
|
+ ?
|
|
|
|
+ <button onClick={this.handleLogOut} className="btn btn-outline-primary">Log Out</button>
|
|
|
|
+ :
|
|
|
|
+ <React.Fragment>
|
|
|
|
+ <Link to={routes.SIGN_IN}>
|
|
|
|
+ <button className="btn btn-outline-primary">Sign In</button>
|
|
|
|
+ </Link>
|
|
|
|
+ <Link to={routes.SIGN_UP}>
|
|
|
|
+ <button className="btn btn-outline-primary mx-2">Sign Up</button>
|
|
|
|
+ </Link>
|
|
|
|
+ </React.Fragment>
|
|
|
|
+ }
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
</nav>
|
|
@@ -70,8 +85,7 @@ class Header extends React.Component {
|
|
}
|
|
}
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
const mapStateToProps = state => ({
|
|
- state: state.logOut
|
|
|
|
|
|
+ role: state.tokenCheckout.role,
|
|
});
|
|
});
|
|
-const mapDispatchToProps = dispatch => bindActionCreators({ logOut }, dispatch)
|
|
|
|
|
|
|
|
-export default connect(mapStateToProps, mapDispatchToProps)(Header);
|
|
|
|
|
|
+export default withRouter(connect(mapStateToProps, null)(Header));
|