mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-28 20:53:24 +10:00
113 lines
3.3 KiB
JavaScript
113 lines
3.3 KiB
JavaScript
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 (
|
|
<Topbar
|
|
authInProgress={authInProgress}
|
|
currentUser={currentUser}
|
|
currentUserHasListings={currentUserHasListings}
|
|
currentUserHasOrders={currentUserHasOrders}
|
|
history={history}
|
|
isAuthenticated={isAuthenticated}
|
|
location={location}
|
|
notificationCount={notificationCount}
|
|
onLogout={onLogout}
|
|
onManageDisableScrolling={onManageDisableScrolling}
|
|
onResendVerificationEmail={onResendVerificationEmail}
|
|
sendVerificationEmailInProgress={sendVerificationEmailInProgress}
|
|
sendVerificationEmailError={sendVerificationEmailError}
|
|
{...rest}
|
|
/>
|
|
);
|
|
};
|
|
|
|
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;
|