2017-11-28 13:24:26 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Logout
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
2019-01-07 01:26:04 +03:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2017-11-28 13:24:26 +01:00
|
|
|
import { get } from 'lodash';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { ButtonDropdown, DropdownItem, DropdownMenu, DropdownToggle } from 'reactstrap';
|
|
|
|
import auth from 'utils/auth';
|
|
|
|
|
|
|
|
import styles from './styles.scss';
|
|
|
|
|
|
|
|
class Logout extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
|
|
|
state = { isOpen: false };
|
|
|
|
|
|
|
|
handleGoTo = () => {
|
|
|
|
const id = get(auth.getUserInfo(), 'id') || get(auth.getUserInfo(), '_id');
|
2017-12-07 14:07:37 +01:00
|
|
|
this.context.router.history.push({
|
|
|
|
pathname: `/plugins/content-manager/user/${id}`,
|
|
|
|
search: '?redirectUrl=/plugins/content-manager/user/?page=0&limit=0&sort=id&source=users-permissions',
|
|
|
|
});
|
2017-11-28 13:24:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
handleLogout = () => {
|
|
|
|
auth.clearAppStorage();
|
|
|
|
this.context.router.history.push('/plugins/users-permissions/auth/login');
|
|
|
|
}
|
|
|
|
|
|
|
|
toggle = () => this.setState({ isOpen: !this.state.isOpen });
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div className={styles.logout}>
|
|
|
|
<ButtonDropdown isOpen={this.state.isOpen} toggle={this.toggle}>
|
|
|
|
<DropdownToggle>
|
|
|
|
{get(auth.getUserInfo(), 'username')}
|
2018-05-02 11:01:27 +02:00
|
|
|
<i className="fa fa-caret-down" alt={`${this.state.isOpen}`} />
|
2017-11-28 13:24:26 +01:00
|
|
|
</DropdownToggle>
|
|
|
|
<DropdownMenu className={styles.dropDownContent}>
|
2017-12-04 17:32:45 +01:00
|
|
|
<DropdownItem onClick={this.handleGoTo} className={styles.item}>
|
2019-01-07 01:26:04 +03:00
|
|
|
<FormattedMessage
|
|
|
|
id="app.components.Logout.profile"
|
|
|
|
defaultMessage="Profile"
|
|
|
|
/>
|
2017-11-28 13:24:26 +01:00
|
|
|
</DropdownItem>
|
|
|
|
<DropdownItem onClick={this.handleLogout}>
|
2019-01-07 01:26:04 +03:00
|
|
|
<FormattedMessage
|
|
|
|
id="app.components.Logout.logout"
|
|
|
|
defaultMessage="Logout"
|
|
|
|
/>
|
2017-11-28 13:24:26 +01:00
|
|
|
<i className="fa fa-sign-out" />
|
|
|
|
</DropdownItem>
|
|
|
|
</DropdownMenu>
|
|
|
|
</ButtonDropdown>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Logout.contextTypes = {
|
|
|
|
router: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Logout;
|