2017-11-28 13:24:26 +01:00
|
|
|
/**
|
2019-04-09 12:09:03 +02:00
|
|
|
*
|
|
|
|
* Logout
|
|
|
|
*
|
|
|
|
*/
|
2017-11-28 13:24:26 +01:00
|
|
|
|
2019-07-02 08:37:41 +02:00
|
|
|
/* eslint-disable */
|
2017-11-28 13:24:26 +01:00
|
|
|
import React from 'react';
|
2019-01-07 01:26:04 +03:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2019-04-16 18:47:58 +02:00
|
|
|
import { withRouter } from 'react-router-dom';
|
2017-11-28 13:24:26 +01:00
|
|
|
import { get } from 'lodash';
|
2019-04-09 12:09:03 +02:00
|
|
|
import {
|
|
|
|
ButtonDropdown,
|
|
|
|
DropdownItem,
|
|
|
|
DropdownMenu,
|
|
|
|
DropdownToggle,
|
|
|
|
} from 'reactstrap';
|
2019-04-16 11:53:29 +02:00
|
|
|
import { auth } from 'strapi-helper-plugin';
|
2017-11-28 13:24:26 +01:00
|
|
|
|
|
|
|
import styles from './styles.scss';
|
|
|
|
|
2019-04-09 12:09:03 +02:00
|
|
|
class Logout extends React.Component {
|
|
|
|
// eslint-disable-line react/prefer-stateless-function
|
2017-11-28 13:24:26 +01:00
|
|
|
state = { isOpen: false };
|
|
|
|
|
|
|
|
handleGoTo = () => {
|
|
|
|
const id = get(auth.getUserInfo(), 'id') || get(auth.getUserInfo(), '_id');
|
2019-04-16 18:47:58 +02:00
|
|
|
this.props.history.push({
|
2019-04-09 12:09:03 +02:00
|
|
|
pathname: `/plugins/content-manager/administrator/${id}`,
|
|
|
|
search:
|
|
|
|
'?redirectUrl=/plugins/content-manager/administrator/?page=0&limit=0&sort=id&source=admin',
|
2017-12-07 14:07:37 +01:00
|
|
|
});
|
2019-04-09 12:09:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
handleGoToAdministrator = () => {
|
2019-04-16 18:47:58 +02:00
|
|
|
this.props.history.push({
|
2019-04-16 11:53:29 +02:00
|
|
|
pathname: '/plugins/content-manager/administrator',
|
2019-04-09 12:09:03 +02:00
|
|
|
search: '?source=admin',
|
|
|
|
});
|
|
|
|
};
|
2017-11-28 13:24:26 +01:00
|
|
|
|
|
|
|
handleLogout = () => {
|
|
|
|
auth.clearAppStorage();
|
2019-04-16 18:47:58 +02:00
|
|
|
this.props.history.push('/plugins/users-permissions/auth/login');
|
2019-04-09 12:09:03 +02:00
|
|
|
};
|
2017-11-28 13:24:26 +01:00
|
|
|
|
|
|
|
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 02:03:35 +03:00
|
|
|
<FormattedMessage id="app.components.Logout.profile" />
|
2017-11-28 13:24:26 +01:00
|
|
|
</DropdownItem>
|
2019-04-09 12:09:03 +02:00
|
|
|
<DropdownItem
|
|
|
|
onClick={this.handleGoToAdministrator}
|
|
|
|
className={styles.item}
|
|
|
|
>
|
|
|
|
<FormattedMessage id="app.components.Logout.admin" />
|
|
|
|
</DropdownItem>
|
2017-11-28 13:24:26 +01:00
|
|
|
<DropdownItem onClick={this.handleLogout}>
|
2019-01-07 02:03:35 +03:00
|
|
|
<FormattedMessage id="app.components.Logout.logout" />
|
2017-11-28 13:24:26 +01:00
|
|
|
<i className="fa fa-sign-out" />
|
|
|
|
</DropdownItem>
|
|
|
|
</DropdownMenu>
|
|
|
|
</ButtonDropdown>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-16 18:47:58 +02:00
|
|
|
export default withRouter(Logout);
|