69 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';
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({
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
});
};
const handleGoToAdministrator = () => {
push({
2019-04-16 11:53:29 +02:00
pathname: '/plugins/content-manager/administrator',
search: '?source=admin',
});
};
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')}
<i className="fa fa-caret-down" alt={`${isOpen}`} />
</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" />
<i className="fa fa-sign-out" />
</DropdownItem>
</DropdownMenu>
</ButtonDropdown>
</Wrapper>
);
};
2017-11-28 13:24:26 +01:00
2019-04-16 18:47:58 +02:00
export default withRouter(Logout);