From cff423a2a7ef2b524d7759ec5478a0790a4bae95 Mon Sep 17 00:00:00 2001 From: Vesa Luusua Date: Wed, 11 Oct 2017 20:11:15 +0300 Subject: [PATCH] TopbarContainer --- .../TopbarContainer/TopbarContainer.js | 113 ++++++++++++++++++ src/containers/index.js | 1 + 2 files changed, 114 insertions(+) create mode 100644 src/containers/TopbarContainer/TopbarContainer.js diff --git a/src/containers/TopbarContainer/TopbarContainer.js b/src/containers/TopbarContainer/TopbarContainer.js new file mode 100644 index 00000000..d2999a6f --- /dev/null +++ b/src/containers/TopbarContainer/TopbarContainer.js @@ -0,0 +1,113 @@ +import React, { PropTypes } from 'react'; +import { compose } from 'redux'; +import { connect } from 'react-redux'; +import { withRouter } from 'react-router-dom'; +import * as propTypes from '../../util/propTypes'; +import { sendVerificationEmail } from '../../ducks/user.duck'; +import { logout, authenticationInProgress } from '../../ducks/Auth.duck'; +import { manageDisableScrolling } from '../../ducks/UI.duck'; +import { Topbar } from '../../components'; + +export const TopbarContainerComponent = props => { + const { + authInProgress, + currentUser, + currentUserHasListings, + currentUserHasOrders, + history, + isAuthenticated, + location, + notificationCount, + onLogout, + onManageDisableScrolling, + sendVerificationEmailInProgress, + sendVerificationEmailError, + onResendVerificationEmail, + ...rest + } = props; + + return ( + + ); +}; + +TopbarContainerComponent.defaultProps = { + currentUser: null, + currentUserHasOrders: null, + notificationCount: 0, + sendVerificationEmailError: null, +}; + +const { bool, func, instanceOf, number, object, shape } = PropTypes; + +TopbarContainerComponent.propTypes = { + authInProgress: bool.isRequired, + currentUser: propTypes.currentUser, + currentUserHasListings: bool.isRequired, + currentUserHasOrders: bool, + isAuthenticated: bool.isRequired, + notificationCount: number, + onLogout: func.isRequired, + onManageDisableScrolling: func.isRequired, + sendVerificationEmailInProgress: bool.isRequired, + sendVerificationEmailError: instanceOf(Error), + onResendVerificationEmail: func.isRequired, + + // from withRouter + history: shape({ + push: func.isRequired, + }).isRequired, + location: shape({ state: object }).isRequired, +}; + +const mapStateToProps = state => { + // Topbar needs isAuthenticated + const { isAuthenticated } = state.Auth; + // Topbar needs user info. + const { + currentUser, + currentUserHasListings, + currentUserHasOrders, + currentUserNotificationCount: notificationCount, + sendVerificationEmailInProgress, + sendVerificationEmailError, + } = state.user; + return { + authInProgress: authenticationInProgress(state), + currentUser, + currentUserHasListings, + currentUserHasOrders, + notificationCount, + isAuthenticated, + sendVerificationEmailInProgress, + sendVerificationEmailError, + }; +}; + +const mapDispatchToProps = dispatch => ({ + onLogout: historyPush => dispatch(logout(historyPush)), + onManageDisableScrolling: (componentId, disableScrolling) => + dispatch(manageDisableScrolling(componentId, disableScrolling)), + onResendVerificationEmail: () => dispatch(sendVerificationEmail()), +}); + +const TopbarContainer = compose(connect(mapStateToProps, mapDispatchToProps), withRouter)( + TopbarContainerComponent +); + +export default TopbarContainer; diff --git a/src/containers/index.js b/src/containers/index.js index 60e9f039..b06411e9 100644 --- a/src/containers/index.js +++ b/src/containers/index.js @@ -39,4 +39,5 @@ export { default as SecurityPage } from './SecurityPage/SecurityPage'; export { default as SignupForm } from './SignupForm/SignupForm'; export { default as StripePaymentForm } from './StripePaymentForm/StripePaymentForm'; export { default as StyleguidePage } from './StyleguidePage/StyleguidePage'; +export { default as TopbarContainer } from './TopbarContainer/TopbarContainer'; export { default as TopbarSearchForm } from './TopbarSearchForm/TopbarSearchForm';