68 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-11-28 13:24:26 +01:00
/**
*
* Logout
*
*/
2017-11-28 13:24:26 +01:00
2019-07-02 08:37:41 +02:00
/* eslint-disable */
import React, { useState } from 'react';
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';
import {
ButtonDropdown,
DropdownItem,
DropdownMenu,
DropdownToggle,
} from 'reactstrap';
2019-04-16 11:53:29 +02:00
import { auth } from 'strapi-helper-plugin';
import Wrapper from './components';
2017-11-28 13:24:26 +01: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
push({
2019-12-18 12:10:02 +01:00
pathname: `/plugins/content-manager/strapi::administrator/${id}`,
search: '?redirectUrl=/plugins/content-manager/strapi::administrator',
2017-12-07 14:07:37 +01:00
});
};
const handleGoToAdministrator = () => {
push({
2019-12-06 10:44:27 +01:00
pathname: '/plugins/content-manager/strapi::administrator',
});
};
const handleLogout = () => {
2017-11-28 13:24:26 +01:00
auth.clearAppStorage();
2019-09-09 14:32:06 +02:00
push('/auth/login');
};
2017-11-28 13:24:26 +01: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" />
</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" />
</DropdownItem>
</DropdownMenu>
</ButtonDropdown>
</Wrapper>
);
};
2017-11-28 13:24:26 +01:00
2019-04-16 18:47:58 +02:00
export default withRouter(Logout);