|
@@ -1,19 +1,33 @@
|
|
|
import React, { PureComponent } from 'react';
|
|
|
import { Link, withRouter, Redirect } from "react-router-dom";
|
|
|
import { connect } from 'react-redux';
|
|
|
+import { bindActionCreators } from 'redux';
|
|
|
+import axios from 'axios';
|
|
|
+
|
|
|
import storageKey from './../../utils/storageKey';
|
|
|
+import { signInStateZeroing } from './../../actions/auth/signIn';
|
|
|
+import { LOG_OUT_URL } from './../../constants/auth';
|
|
|
|
|
|
import * as routes from '../../constants/routes';
|
|
|
-import logOut from '../../actions/auth/logOut';
|
|
|
|
|
|
//pure component + make storage check an action -> connect router
|
|
|
class Header extends PureComponent {
|
|
|
handleLogOut = () => {
|
|
|
- const { history: { push } } = this.props;
|
|
|
+ console.log(this.props)
|
|
|
+ const { history, zeroState } = this.props;
|
|
|
+
|
|
|
+ axios.get(LOG_OUT_URL, {})
|
|
|
+ .then(() => {
|
|
|
+ console.log('request was succesfull')
|
|
|
+ localStorage.removeItem(storageKey);
|
|
|
+ zeroState();
|
|
|
+ history.push('/sign-in');
|
|
|
+ })
|
|
|
+ .catch(e => alert('Sorry, something bad happened, try log out later \n' + e.message));
|
|
|
}
|
|
|
|
|
|
render() {
|
|
|
- const { role, logOutStatus } = this.props;
|
|
|
+ const { role } = this.props;
|
|
|
|
|
|
return (
|
|
|
<nav className="navbar navbar-expand-lg navbar-dark bg-dark p-3">
|
|
@@ -87,5 +101,8 @@ class Header extends PureComponent {
|
|
|
const mapStateToProps = state => ({
|
|
|
role: state.tokenCheckout.role,
|
|
|
});
|
|
|
+const mapDispatchToProps = dispatch => bindActionCreators({
|
|
|
+ zeroState: signInStateZeroing
|
|
|
+}, dispatch)
|
|
|
|
|
|
-export default withRouter(connect(mapStateToProps, null)(Header));
|
|
|
+export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Header));
|