mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-27 19:42:11 +10:00
TopbarContainer
This commit is contained in:
parent
d5bb389dc6
commit
cff423a2a7
2 changed files with 114 additions and 0 deletions
113
src/containers/TopbarContainer/TopbarContainer.js
Normal file
113
src/containers/TopbarContainer/TopbarContainer.js
Normal file
|
|
@ -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 (
|
||||
<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;
|
||||
|
|
@ -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';
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue