import React, { Component, PropTypes } from 'react'; import { connect } from 'react-redux'; import LoadingBar from 'react-redux-loading-bar'; import { logoutUser } from 'redux/nodes/auth/actions'; import { push } from 'react-router-redux'; import classnames from 'classnames'; import configInterface from 'interfaces/config'; import FlashMessage from 'components/flash_messages/FlashMessage'; import PersistentFlash from 'components/flash_messages/PersistentFlash'; 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, isSmallNav: PropTypes.bool, notifications: notificationInterface, persistentFlash: PropTypes.shape({ showFlash: PropTypes.bool.isRequired, message: PropTypes.string.isRequired, }).isRequired, }; onLogoutUser = () => { const { dispatch } = this.props; dispatch(logoutUser()); return false; } onNavItemClick = (path) => { return (evt) => { evt.preventDefault(); const { dispatch } = this.props; if (path.indexOf('http') !== -1) { global.window.open(path, '_blank'); return false; } 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, persistentFlash, user, isSmallNav, } = this.props; const { onRemoveFlash, onUndoActionClick } = this; if (!user) return false; const { onLogoutUser, onNavItemClick } = this; const { pathname } = global.window.location; const siteNavClasses = classnames('site-nav', { 'site-nav--small': isSmallNav, }); const coreWrapperClasses = classnames('core-wrapper', { 'core-wrapper--small': isSmallNav, }); return (
{persistentFlash.showFlash && } {children}
); } } const mapStateToProps = (state) => { const { app: { config, isSmallNav, }, auth: { user }, notifications, persistentFlash, } = state; const fullWidthFlash = !user; return { config, fullWidthFlash, isSmallNav, notifications, persistentFlash, user, }; }; export default connect(mapStateToProps)(CoreLayout);