add logout in system and if not isnotlogin go to register

This commit is contained in:
enggar_ganteng 2019-02-01 15:01:34 +07:00
parent 12e7f13c1a
commit b5b9cd1187
3 changed files with 107 additions and 93 deletions

View File

@ -73,6 +73,7 @@ import CartIcon from '@material-ui/icons/ShoppingCart';
import NotificationsIcon from '@material-ui/icons/Notifications'; import NotificationsIcon from '@material-ui/icons/Notifications';
import MoreIcon from '@material-ui/icons/MoreVert'; import MoreIcon from '@material-ui/icons/MoreVert';
import CancelIcon from '@material-ui/icons/Cancel'; import CancelIcon from '@material-ui/icons/Cancel';
import ListIcon from '@material-ui/icons/FormatListBulleted';
import { styles } from './styles'; import { styles } from './styles';
import Drawer from '@material-ui/core/Drawer'; import Drawer from '@material-ui/core/Drawer';
@ -237,26 +238,26 @@ class App extends React.Component {
} }
willLogout() { willLogout() {
// Modal.confirm({ Modal.confirm({
// title: 'Log out the system?', title: 'Log out the system?',
// content: 'Are sure sure you want to log out the system?', content: 'Are sure sure you want to log out the system?',
// okText: 'Confirm', okText: 'Confirm',
// cancelText: 'Cancel', cancelText: 'Cancel',
// visible: this.state.visible, visible: this.state.visible,
// zIndex: 3000, zIndex: 3000,
// onOk: () => { onOk: () => {
// this.authStore.logout(); this.authStore.logout();
// this.setState({ this.setState({
// visible: false, visible: false,
// redirect: true redirect: true
// }); });
// }, },
// onCancel: () => { onCancel: () => {
// this.setState({ this.setState({
// visible: false, visible: false,
// }); });
// } }
// }); });
} }
openCreateProjectDialog() { openCreateProjectDialog() {
@ -404,9 +405,12 @@ class App extends React.Component {
</Link> </Link>
<Link onClick={this <Link onClick={this
.changeRoute .changeRoute
.bind(this, '/login')} to={LINKS.LOGIN}> .bind(this, '/app/transaction')} to={LINKS.TRANSACTION}>
<MenuItem>Sign Out</MenuItem> <MenuItem>Transaction</MenuItem>
</Link> </Link>
{/* <Link onClick={this.willLogout.bind(this)}> */}
<MenuItem onClick={this.willLogout.bind(this)}>Sign Out</MenuItem>
{/* </Link> */}
</Menu> </Menu>
); );
@ -420,14 +424,14 @@ class App extends React.Component {
> >
{window.location.pathname.split("/")[2] == "shop" ? ( {window.location.pathname.split("/")[2] == "shop" ? (
<MenuItem> <MenuItem>
<IconButton color="inherit"> <IconButton color="inherit">
<Badge badgeContent={4} color="secondary"> <Badge badgeContent={4} color="secondary">
<CartIcon /> <CartIcon />
</Badge> </Badge>
</IconButton> </IconButton>
<p>Cart</p> <p>Cart</p>
</MenuItem> </MenuItem>
) : "" } ) : ""}
<MenuItem> <MenuItem>
<IconButton color="inherit"> <IconButton color="inherit">
<Badge badgeContent={11} color="secondary"> <Badge badgeContent={11} color="secondary">
@ -439,39 +443,49 @@ class App extends React.Component {
<Link onClick={this <Link onClick={this
.changeRoute .changeRoute
.bind(this, '/app/profile')} to={LINKS.PROFILE}> .bind(this, '/app/profile')} to={LINKS.PROFILE}>
<MenuItem> <MenuItem>
<IconButton color="inherit"> <IconButton color="inherit">
<AccountCircle /> <AccountCircle />
</IconButton> </IconButton>
<p>Profile</p> <p>Profile</p>
</MenuItem> </MenuItem>
</Link> </Link>
<Link onClick={this <Link onClick={this
.changeRoute .changeRoute
.bind(this, '/login')} to={LINKS.LOGIN}> .bind(this, '/transaction')} to={LINKS.TRANSACTION}>
<MenuItem> <MenuItem>
<IconButton color="inherit"> <IconButton color="inherit">
<CancelIcon /> <ListIcon />
</IconButton> </IconButton>
<p>Sign Out</p> <p>Transaction</p>
</MenuItem> </MenuItem>
</Link> </Link>
{/* <Link onClick={this
.changeRoute
.bind(this, '/login')} to={LINKS.LOGIN}> */}
<MenuItem onClick={this.willLogout.bind(this)}>
<IconButton color="inherit">
<CancelIcon />
</IconButton>
<p>Sign Out</p>
</MenuItem>
{/* </Link> */}
</Menu> </Menu>
); );
const sideList = ( const sideList = (
<div className={classes.list}> <div className={classes.list}>
<div className={classes.backgroundLogo}> <div className={classes.backgroundLogo}>
<Link onClick={this <Link onClick={this
.changeRoute .changeRoute
.bind(this, '/app/dashboard')} to={LINKS.DASHBOARD}> .bind(this, '/app/dashboard')} to={LINKS.DASHBOARD}>
<img <img
style={{ style={{
width: "100%", width: "100%",
height: "100%" height: "100%"
}} }}
src={applicationIcon} /> src={applicationIcon} />
</Link> </Link>
</div> </div>
<Divider /> <Divider />
<List> <List>
@ -515,7 +529,7 @@ class App extends React.Component {
</List> </List>
<Divider /> <Divider />
<List> <List>
<div style={{padding:15}}> <div style={{ padding: 15 }}>
<a> <a>
<WalletComponent /> <WalletComponent />
</a> </a>
@ -553,21 +567,21 @@ class App extends React.Component {
<AppBar position="fixed"> <AppBar position="fixed">
<Toolbar className={classes.toolbar}> <Toolbar className={classes.toolbar}>
<div className={classes.sectionMobile}> <div className={classes.sectionMobile}>
<IconButton className={classes.menuButton} color="action" aria-label="Open drawer" onClick={this.toggleDrawerNew(true)}> <IconButton className={classes.menuButton} color="action" aria-label="Open drawer" onClick={this.toggleDrawerNew(true)}>
<MenuIcon /> <MenuIcon />
</IconButton> </IconButton>
</div> </div>
<Link onClick={this <Link onClick={this
.changeRoute .changeRoute
.bind(this, '/app/dashboard')} to={LINKS.DASHBOARD}> .bind(this, '/app/dashboard')} to={LINKS.DASHBOARD}>
<img <img
className={classes.title} className={classes.title}
style={{ style={{
width: 100, width: 100,
height: 30 height: 30
}} }}
src={applicationIcon} /> src={applicationIcon} />
</Link> </Link>
<div className={classes.search}> <div className={classes.search}>
<div className={classes.searchIcon}> <div className={classes.searchIcon}>
<SearchIcon /> <SearchIcon />
@ -587,7 +601,7 @@ class App extends React.Component {
<Badge badgeContent={4} color="secondary"> <Badge badgeContent={4} color="secondary">
<CartIcon /> <CartIcon />
</Badge> </Badge>
</IconButton>) : "" } </IconButton>) : ""}
<IconButton color="action"> <IconButton color="action">
<Badge badgeContent={17} color="secondary"> <Badge badgeContent={17} color="secondary">

View File

@ -145,9 +145,9 @@ export default class Routes extends React.Component {
<Route <Route
{...rest} {...rest}
render={ render={
(props) => true === true (props) => this.authStore.isLoggedIn === true
? (<Component {...props}/>) ? (<Component {...props}/>)
: (<Redirect to={{pathname : LINKS.LOGIN}}/> : (<Redirect to={{pathname : LINKS.REGISTER}}/>
) )
} }
/> />

View File

@ -86,29 +86,29 @@ export class Authentication {
logout() { logout() {
this.context.setToken(""); this.context.setToken("");
this.context.setUserData({}); this.context.setUserData({});
// return this.http.post("authentication/logout", {token : localStorage.getItem('tokens')}) return this.http.post("authentication/logout", {token : localStorage.getItem('tokens')})
// .then(res => { .then(res => {
// this.context.setToken(""); this.context.setToken("");
// this.context.setUserData({}); this.context.setUserData({});
//
// localStorage.removeItem('id_token'); localStorage.removeItem('id_token');
// localStorage.removeItem('user.name'); localStorage.removeItem('user.name');
// localStorage.removeItem('user.profile_image'); localStorage.removeItem('user.profile_image');
// localStorage.setItem('isLoggingIn', false); localStorage.setItem('isLoggingIn', false);
// let cookies = document.cookie.split(";"); let cookies = document.cookie.split(";");
// for (let i = 0; i < cookies.length; i++) { for (let i = 0; i < cookies.length; i++) {
// this.eraseCookie(cookies[i].split("=")[0]); this.eraseCookie(cookies[i].split("=")[0]);
// } }
//
// if (window && window.Tawk_API && window.Tawk_API.isChatHidden()) { if (window && window.Tawk_API && window.Tawk_API.isChatHidden()) {
// window.Tawk_API.hideWidget() window.Tawk_API.hideWidget()
// } }
//
// return res; return res;
// }) })
// .catch(err => { .catch(err => {
// throw err; throw err;
// }) })
} }