From b5b9cd118791faea3b3b9a974ee00d235205f0e1 Mon Sep 17 00:00:00 2001 From: enggar_ganteng Date: Fri, 1 Feb 2019 15:01:34 +0700 Subject: [PATCH] add logout in system and if not isnotlogin go to register --- src/common/pages/App/index.js | 150 ++++++++++++++++------------- src/common/routes.js | 4 +- src/common/stores/authenticaton.js | 46 ++++----- 3 files changed, 107 insertions(+), 93 deletions(-) diff --git a/src/common/pages/App/index.js b/src/common/pages/App/index.js index 3548395..eaca535 100644 --- a/src/common/pages/App/index.js +++ b/src/common/pages/App/index.js @@ -73,6 +73,7 @@ import CartIcon from '@material-ui/icons/ShoppingCart'; import NotificationsIcon from '@material-ui/icons/Notifications'; import MoreIcon from '@material-ui/icons/MoreVert'; import CancelIcon from '@material-ui/icons/Cancel'; +import ListIcon from '@material-ui/icons/FormatListBulleted'; import { styles } from './styles'; import Drawer from '@material-ui/core/Drawer'; @@ -237,26 +238,26 @@ class App extends React.Component { } willLogout() { - // Modal.confirm({ - // title: 'Log out the system?', - // content: 'Are sure sure you want to log out the system?', - // okText: 'Confirm', - // cancelText: 'Cancel', - // visible: this.state.visible, - // zIndex: 3000, - // onOk: () => { - // this.authStore.logout(); - // this.setState({ - // visible: false, - // redirect: true - // }); - // }, - // onCancel: () => { - // this.setState({ - // visible: false, - // }); - // } - // }); + Modal.confirm({ + title: 'Log out the system?', + content: 'Are sure sure you want to log out the system?', + okText: 'Confirm', + cancelText: 'Cancel', + visible: this.state.visible, + zIndex: 3000, + onOk: () => { + this.authStore.logout(); + this.setState({ + visible: false, + redirect: true + }); + }, + onCancel: () => { + this.setState({ + visible: false, + }); + } + }); } openCreateProjectDialog() { @@ -404,9 +405,12 @@ class App extends React.Component { - Sign Out + .bind(this, '/app/transaction')} to={LINKS.TRANSACTION}> + Transaction + {/* */} + Sign Out + {/* */} ); @@ -420,14 +424,14 @@ class App extends React.Component { > {window.location.pathname.split("/")[2] == "shop" ? ( - - - - - -

Cart

-
- ) : "" } + + + + + +

Cart

+ + ) : ""} @@ -439,39 +443,49 @@ class App extends React.Component { - - - - -

Profile

-
+ + + + +

Profile

+
- - - - -

Sign Out

-
+ .bind(this, '/transaction')} to={LINKS.TRANSACTION}> + + + + +

Transaction

+
+ {/* */} + + + + +

Sign Out

+
+ {/* */} ); const sideList = (
- - - + + +
@@ -515,7 +529,7 @@ class App extends React.Component { -
+
@@ -553,21 +567,21 @@ class App extends React.Component {
- - - + + +
- - + .changeRoute + .bind(this, '/app/dashboard')} to={LINKS.DASHBOARD}> + +
@@ -587,7 +601,7 @@ class App extends React.Component { - ) : "" } + ) : ""} diff --git a/src/common/routes.js b/src/common/routes.js index 1bf7d7d..3b4a08d 100644 --- a/src/common/routes.js +++ b/src/common/routes.js @@ -145,9 +145,9 @@ export default class Routes extends React.Component { true === true + (props) => this.authStore.isLoggedIn === true ? () - : ( + : ( ) } /> diff --git a/src/common/stores/authenticaton.js b/src/common/stores/authenticaton.js index 2e20726..fa8bf50 100644 --- a/src/common/stores/authenticaton.js +++ b/src/common/stores/authenticaton.js @@ -86,29 +86,29 @@ export class Authentication { logout() { this.context.setToken(""); this.context.setUserData({}); - // return this.http.post("authentication/logout", {token : localStorage.getItem('tokens')}) - // .then(res => { - // this.context.setToken(""); - // this.context.setUserData({}); - // - // localStorage.removeItem('id_token'); - // localStorage.removeItem('user.name'); - // localStorage.removeItem('user.profile_image'); - // localStorage.setItem('isLoggingIn', false); - // let cookies = document.cookie.split(";"); - // for (let i = 0; i < cookies.length; i++) { - // this.eraseCookie(cookies[i].split("=")[0]); - // } - // - // if (window && window.Tawk_API && window.Tawk_API.isChatHidden()) { - // window.Tawk_API.hideWidget() - // } - // - // return res; - // }) - // .catch(err => { - // throw err; - // }) + return this.http.post("authentication/logout", {token : localStorage.getItem('tokens')}) + .then(res => { + this.context.setToken(""); + this.context.setUserData({}); + + localStorage.removeItem('id_token'); + localStorage.removeItem('user.name'); + localStorage.removeItem('user.profile_image'); + localStorage.setItem('isLoggingIn', false); + let cookies = document.cookie.split(";"); + for (let i = 0; i < cookies.length; i++) { + this.eraseCookie(cookies[i].split("=")[0]); + } + + if (window && window.Tawk_API && window.Tawk_API.isChatHidden()) { + window.Tawk_API.hideWidget() + } + + return res; + }) + .catch(err => { + throw err; + }) }