2016-09-21 03:07:32 +00:00
|
|
|
import React, { Component, PropTypes } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
2016-11-03 19:40:54 +00:00
|
|
|
import classnames from 'classnames';
|
2016-12-05 17:55:30 +00:00
|
|
|
import { logoutUser } from 'redux/nodes/auth/actions';
|
|
|
|
import { push } from 'react-router-redux';
|
2016-10-19 20:22:18 +00:00
|
|
|
|
2016-12-01 22:14:39 +00:00
|
|
|
import configInterface from 'interfaces/config';
|
|
|
|
import FlashMessage from 'components/FlashMessage';
|
2016-12-05 17:55:30 +00:00
|
|
|
import { hideFlash } from 'redux/nodes/notifications/actions';
|
2016-12-01 22:14:39 +00:00
|
|
|
import SiteNavHeader from 'components/side_panels/SiteNavHeader';
|
|
|
|
import SiteNavSidePanel from 'components/side_panels/SiteNavSidePanel';
|
|
|
|
import notificationInterface from 'interfaces/notification';
|
|
|
|
import userInterface from 'interfaces/user';
|
2016-09-21 03:07:32 +00:00
|
|
|
|
|
|
|
export class CoreLayout extends Component {
|
|
|
|
static propTypes = {
|
|
|
|
children: PropTypes.node,
|
2016-10-21 23:13:41 +00:00
|
|
|
config: configInterface,
|
2016-09-21 03:07:32 +00:00
|
|
|
dispatch: PropTypes.func,
|
2016-10-21 23:13:41 +00:00
|
|
|
notifications: notificationInterface,
|
2016-10-11 15:32:39 +00:00
|
|
|
showRightSidePanel: PropTypes.bool,
|
2016-10-21 23:13:41 +00:00
|
|
|
user: userInterface,
|
2016-09-21 03:07:32 +00:00
|
|
|
};
|
|
|
|
|
2016-12-05 17:55:30 +00:00
|
|
|
onLogoutUser = () => {
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
|
|
|
dispatch(logoutUser());
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
onNavItemClick = (path) => {
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
|
|
|
dispatch(push(path));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
onRemoveFlash = () => {
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
|
|
|
dispatch(hideFlash);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
onUndoActionClick = (undoAction) => {
|
|
|
|
return (evt) => {
|
|
|
|
evt.preventDefault();
|
|
|
|
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
const { onRemoveFlash } = this;
|
|
|
|
|
|
|
|
dispatch(undoAction);
|
|
|
|
|
|
|
|
return onRemoveFlash();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-09-21 03:07:32 +00:00
|
|
|
render () {
|
2016-12-05 17:55:30 +00:00
|
|
|
const { children, config, notifications, showRightSidePanel, user } = this.props;
|
2016-11-03 19:40:54 +00:00
|
|
|
const wrapperClass = classnames(
|
|
|
|
'core-wrapper',
|
|
|
|
{ 'core-wrapper--show-panel': showRightSidePanel }
|
|
|
|
);
|
2016-09-21 03:07:32 +00:00
|
|
|
|
|
|
|
if (!user) return false;
|
|
|
|
|
2016-12-05 17:55:30 +00:00
|
|
|
const { onLogoutUser, onNavItemClick, onRemoveFlash, onUndoActionClick } = this;
|
2016-09-30 18:55:15 +00:00
|
|
|
const { pathname } = global.window.location;
|
|
|
|
|
2016-09-21 03:07:32 +00:00
|
|
|
return (
|
2016-11-03 19:40:54 +00:00
|
|
|
<div>
|
2016-12-01 22:14:39 +00:00
|
|
|
<nav className="site-nav">
|
|
|
|
<SiteNavHeader
|
|
|
|
config={config}
|
2016-12-05 17:55:30 +00:00
|
|
|
onLogoutUser={onLogoutUser}
|
2016-12-01 22:14:39 +00:00
|
|
|
user={user}
|
|
|
|
/>
|
|
|
|
<SiteNavSidePanel
|
|
|
|
config={config}
|
2016-12-05 17:55:30 +00:00
|
|
|
onNavItemClick={onNavItemClick}
|
2016-12-01 22:14:39 +00:00
|
|
|
pathname={pathname}
|
|
|
|
user={user}
|
|
|
|
/>
|
|
|
|
</nav>
|
2016-11-03 19:40:54 +00:00
|
|
|
<div className={wrapperClass}>
|
2016-12-05 17:55:30 +00:00
|
|
|
<FlashMessage
|
|
|
|
notification={notifications}
|
|
|
|
onRemoveFlash={onRemoveFlash}
|
|
|
|
onUndoActionClick={onUndoActionClick}
|
|
|
|
/>
|
2016-09-30 18:55:15 +00:00
|
|
|
{children}
|
|
|
|
</div>
|
2016-11-03 19:40:54 +00:00
|
|
|
</div>
|
2016-09-21 03:07:32 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => {
|
2016-10-11 15:32:39 +00:00
|
|
|
const {
|
|
|
|
app: { config, showRightSidePanel },
|
|
|
|
auth: { user },
|
|
|
|
notifications,
|
|
|
|
} = state;
|
|
|
|
|
|
|
|
return {
|
|
|
|
config,
|
|
|
|
notifications,
|
|
|
|
showRightSidePanel,
|
|
|
|
user,
|
|
|
|
};
|
2016-09-21 03:07:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(CoreLayout);
|