SalePage: pass Topbar props

This commit is contained in:
Vesa Luusua 2017-07-11 17:13:40 +03:00
parent b75ac9c444
commit 0f5ec32b24
3 changed files with 76 additions and 9 deletions

View file

@ -15,6 +15,7 @@ import {
Topbar,
} from '../../components';
import { getMarketplaceEntities } from '../../ducks/marketplaceData.duck';
import { logout, authenticationInProgress } from '../../ducks/Auth.duck';
import { manageDisableScrolling, isScrollingDisabled } from '../../ducks/UI.duck';
import { acceptSale, rejectSale, loadData } from './SalePage.duck';
@ -24,16 +25,22 @@ import css from './SalePage.css';
// It show loading data text or SaleDetailsPanel (and later also another panel for messages).
export const SalePageComponent = props => {
const {
authInProgress,
currentUser,
currentUserHasListings,
fetchSaleError,
history,
intl,
isAuthenticated,
location,
notificationCount,
onAcceptSale,
onLogout,
onManageDisableScrolling,
onRejectSale,
params,
scrollingDisabled,
transaction,
history,
location,
} = props;
const currentTransaction = ensureTransaction(transaction);
const currentListing = ensureListing(currentTransaction.listing);
@ -87,7 +94,17 @@ export const SalePageComponent = props => {
title={intl.formatMessage({ id: 'SalePage.title' }, { title: listingTitle })}
scrollingDisabled={scrollingDisabled}
>
<Topbar history={history} location={location} />
<Topbar
isAuthenticated={isAuthenticated}
authInProgress={authInProgress}
currentUser={currentUser}
currentUserHasListings={currentUserHasListings}
notificationCount={notificationCount}
history={history}
location={location}
onLogout={onLogout}
onManageDisableScrolling={onManageDisableScrolling}
/>
<div className={css.root}>
{panel}
{actionButtons}
@ -96,15 +113,26 @@ export const SalePageComponent = props => {
);
};
SalePageComponent.defaultProps = { transaction: null, currentUser: null, fetchSaleError: null };
SalePageComponent.defaultProps = {
currentUser: null,
fetchSaleError: null,
notificationCount: 0,
transaction: null,
};
const { bool, func, instanceOf, oneOf, shape, string } = PropTypes;
const { bool, func, instanceOf, number, oneOf, shape, string } = PropTypes;
SalePageComponent.propTypes = {
authInProgress: bool.isRequired,
currentUser: propTypes.currentUser,
currentUserHasListings: bool.isRequired,
fetchSaleError: instanceOf(Error),
intl: intlShape.isRequired,
isAuthenticated: bool.isRequired,
notificationCount: number,
onAcceptSale: func.isRequired,
onLogout: func.isRequired,
onManageDisableScrolling: func.isRequired,
onRejectSale: func.isRequired,
params: shape({ id: string }).isRequired,
scrollingDisabled: bool.isRequired,
@ -122,7 +150,12 @@ SalePageComponent.propTypes = {
const mapStateToProps = state => {
const { fetchSaleError, transactionRef } = state.SalePage;
const { currentUser } = state.user;
const { isAuthenticated } = state.Auth;
const {
currentUser,
currentUserHasListings,
currentUserNotificationCount: notificationCount,
} = state.user;
const transactions = getMarketplaceEntities(state, transactionRef ? [transactionRef] : []);
const transaction = transactions.length > 0 ? transactions[0] : null;
@ -130,7 +163,11 @@ const mapStateToProps = state => {
return {
transaction,
fetchSaleError,
isAuthenticated,
authInProgress: authenticationInProgress(state),
currentUser,
currentUserHasListings,
notificationCount,
scrollingDisabled: isScrollingDisabled(state),
};
};
@ -139,6 +176,7 @@ const mapDispatchToProps = dispatch => {
return {
onAcceptSale: transactionId => dispatch(acceptSale(transactionId)),
onRejectSale: transactionId => dispatch(rejectSale(transactionId)),
onLogout: historyPush => dispatch(logout(historyPush)),
onManageDisableScrolling: (componentId, disableScrolling) =>
dispatch(manageDisableScrolling(componentId, disableScrolling)),
};

View file

@ -10,6 +10,8 @@ import {
import { renderShallow } from '../../util/test-helpers';
import { SalePageComponent } from './SalePage';
const noop = () => null;
describe('SalePage', () => {
it('matches snapshot', () => {
const txId = 'tx-sale-1';
@ -32,8 +34,13 @@ describe('SalePage', () => {
history: {
push: () => console.log('HistoryPush called'),
},
onAcceptSale: () => {},
onRejectSale: () => {},
authInProgress: false,
currentUserHasListings: false,
isAuthenticated: false,
onLogout: noop,
onManageDisableScrolling: noop,
onAcceptSale: noop,
onRejectSale: noop,
params: { id: txId },
scrollingDisabled: false,
transaction,

View file

@ -3,16 +3,38 @@ exports[`SalePage matches snapshot 1`] = `
scrollingDisabled={false}
title="SalePage.title">
<Topbar
authInProgress={false}
currentUser={
Object {
"attributes": Object {
"email": "provider1@example.com",
"profile": Object {
"firstName": "provider1 first name",
"lastName": "provider1 last name",
},
"stripeConnected": true,
},
"id": UUID {
"uuid": "provider1",
},
"type": "user",
}
}
currentUserHasListings={false}
history={
Object {
"push": [Function],
}
}
isAuthenticated={false}
location={
Object {
"search": "",
}
} />
}
notificationCount={0}
onLogout={[Function]}
onManageDisableScrolling={[Function]} />
<div>
<SaleDetailsPanel
className="undefined"