mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
122 lines
2.8 KiB
JavaScript
122 lines
2.8 KiB
JavaScript
import React, { Component, PropTypes } from 'react';
|
|
import { connect } from 'react-redux';
|
|
import { logoutUser } from 'redux/nodes/auth/actions';
|
|
import { push } from 'react-router-redux';
|
|
|
|
import configInterface from 'interfaces/config';
|
|
import FlashMessage from 'components/FlashMessage';
|
|
import SiteNavHeader from 'components/side_panels/SiteNavHeader';
|
|
import SiteNavSidePanel from 'components/side_panels/SiteNavSidePanel';
|
|
import userInterface from 'interfaces/user';
|
|
import notificationInterface from 'interfaces/notification';
|
|
import { hideFlash } from 'redux/nodes/notifications/actions';
|
|
|
|
export class CoreLayout extends Component {
|
|
static propTypes = {
|
|
children: PropTypes.node,
|
|
config: configInterface,
|
|
dispatch: PropTypes.func,
|
|
user: userInterface,
|
|
fullWidthFlash: PropTypes.bool,
|
|
notifications: notificationInterface,
|
|
};
|
|
|
|
onLogoutUser = () => {
|
|
const { dispatch } = this.props;
|
|
|
|
dispatch(logoutUser());
|
|
|
|
return false;
|
|
}
|
|
|
|
onNavItemClick = (path) => {
|
|
return (evt) => {
|
|
evt.preventDefault();
|
|
|
|
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();
|
|
};
|
|
}
|
|
|
|
render () {
|
|
const { fullWidthFlash, notifications, children, config, user } = this.props;
|
|
const { onRemoveFlash, onUndoActionClick } = this;
|
|
|
|
if (!user) return false;
|
|
|
|
const { onLogoutUser, onNavItemClick } = this;
|
|
const { pathname } = global.window.location;
|
|
|
|
return (
|
|
<div className="app-wrap">
|
|
<nav className="site-nav">
|
|
<SiteNavHeader
|
|
config={config}
|
|
onLogoutUser={onLogoutUser}
|
|
onNavItemClick={onNavItemClick}
|
|
user={user}
|
|
/>
|
|
<SiteNavSidePanel
|
|
config={config}
|
|
onNavItemClick={onNavItemClick}
|
|
pathname={pathname}
|
|
user={user}
|
|
/>
|
|
</nav>
|
|
<div className="core-wrapper">
|
|
<FlashMessage
|
|
fullWidth={fullWidthFlash}
|
|
notification={notifications}
|
|
onRemoveFlash={onRemoveFlash}
|
|
onUndoActionClick={onUndoActionClick}
|
|
/>
|
|
{children}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
const mapStateToProps = (state) => {
|
|
const {
|
|
app: { config },
|
|
auth: { user },
|
|
notifications,
|
|
} = state;
|
|
|
|
const fullWidthFlash = !user;
|
|
|
|
return {
|
|
notifications,
|
|
fullWidthFlash,
|
|
config,
|
|
user,
|
|
};
|
|
};
|
|
|
|
export default connect(mapStateToProps)(CoreLayout);
|