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 */
|
2019-09-05 14:28:17 +02:00
|
|
|
import React, { useState } 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-12-10 11:11:55 +01:00
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
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';
|
2019-09-05 14:28:17 +02:00
|
|
|
import Wrapper from './components';
|
2017-11-28 13:24:26 +01:00
|
|
|
|
2019-09-05 14:28:17 +02:00
|
|
|
const Logout = ({ history: { push } }) => {
|
|
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
|
|
const toggle = () => setIsOpen(prev => !prev);
|
|
|
|
const handleGoTo = () => {
|
|
|
|
const id = get(auth.getUserInfo(), 'id');
|
2017-11-28 13:24:26 +01:00
|
|
|
|
2019-09-05 14:28:17 +02:00
|
|
|
push({
|
2019-12-18 12:10:02 +01:00
|
|
|
pathname: `/plugins/content-manager/strapi::administrator/${id}`,
|
2020-02-04 15:36:10 +01:00
|
|
|
search: '?redirectUrl=/plugins/content-manager/strapi::administrator',
|
2017-12-07 14:07:37 +01:00
|
|
|
});
|
2019-04-09 12:09:03 +02:00
|
|
|
};
|
2019-09-05 14:28:17 +02:00
|
|
|
const handleGoToAdministrator = () => {
|
|
|
|
push({
|
2019-12-06 10:44:27 +01:00
|
|
|
pathname: '/plugins/content-manager/strapi::administrator',
|
2019-04-09 12:09:03 +02:00
|
|
|
});
|
|
|
|
};
|
2019-09-05 14:28:17 +02:00
|
|
|
const handleLogout = () => {
|
2017-11-28 13:24:26 +01:00
|
|
|
auth.clearAppStorage();
|
2019-09-09 14:32:06 +02:00
|
|
|
push('/auth/login');
|
2019-04-09 12:09:03 +02:00
|
|
|
};
|
2017-11-28 13:24:26 +01:00
|
|
|
|
2019-09-05 14:28:17 +02:00
|
|
|
return (
|
|
|
|
<Wrapper>
|
|
|
|
<ButtonDropdown isOpen={isOpen} toggle={toggle}>
|
|
|
|
<DropdownToggle>
|
|
|
|
{get(auth.getUserInfo(), 'username')}
|
2019-12-10 11:11:55 +01:00
|
|
|
<FontAwesomeIcon icon="caret-down" />
|
2019-09-05 14:28:17 +02:00
|
|
|
</DropdownToggle>
|
|
|
|
<DropdownMenu className="dropDownContent">
|
|
|
|
<DropdownItem onClick={handleGoTo} className="item">
|
|
|
|
<FormattedMessage id="app.components.Logout.profile" />
|
|
|
|
</DropdownItem>
|
|
|
|
<DropdownItem onClick={handleGoToAdministrator} className="item">
|
|
|
|
<FormattedMessage id="app.components.Logout.admin" />
|
|
|
|
</DropdownItem>
|
|
|
|
<DropdownItem onClick={handleLogout}>
|
|
|
|
<FormattedMessage id="app.components.Logout.logout" />
|
2019-12-10 11:11:55 +01:00
|
|
|
<FontAwesomeIcon icon="sign-out-alt" />
|
2019-09-05 14:28:17 +02:00
|
|
|
</DropdownItem>
|
|
|
|
</DropdownMenu>
|
|
|
|
</ButtonDropdown>
|
|
|
|
</Wrapper>
|
|
|
|
);
|
|
|
|
};
|
2017-11-28 13:24:26 +01:00
|
|
|
|
2019-04-16 18:47:58 +02:00
|
|
|
export default withRouter(Logout);
|