diff --git a/src/containers/InboxPage/InboxPage.js b/src/containers/InboxPage/InboxPage.js index a72cc526..aee393cc 100644 --- a/src/containers/InboxPage/InboxPage.js +++ b/src/containers/InboxPage/InboxPage.js @@ -3,10 +3,12 @@ import PropTypes from 'prop-types'; import { compose } from 'redux'; import { connect } from 'react-redux'; import { FormattedMessage, injectIntl, intlShape } from 'react-intl'; +import moment from 'moment'; import classNames from 'classnames'; import * as propTypes from '../../util/propTypes'; import { formatMoney } from '../../util/currency'; import { userDisplayName } from '../../util/data'; +import { daysBetween } from '../../util/dates'; import { getMarketplaceEntities } from '../../ducks/marketplaceData.duck'; import { isScrollingDisabled } from '../../ducks/UI.duck'; import { @@ -25,6 +27,7 @@ import { Footer, } from '../../components'; import { TopbarContainer } from '../../containers'; +import config from '../../config'; import { loadData } from './InboxPage.duck'; import css from './InboxPage.css'; @@ -115,17 +118,26 @@ const txState = (intl, tx, isOrder) => { }; }; -const bookingData = (tx, isOrder, intl) => { - const booking = tx.booking; - const bookingStart = formatDate(intl, booking.attributes.start); - const bookingEnd = formatDate(intl, booking.attributes.end); +const bookingData = (unitType, tx, isOrder, intl) => { + const { start, end } = tx.booking.attributes; + const isDaily = unitType === propTypes.LINE_ITEM_DAY; + const isSingleDay = isDaily && daysBetween(start, end) === 1; + const bookingStart = formatDate(intl, start); + + // Shift the exclusive API end date with daily bookings + const endDate = isDaily + ? moment(end) + .subtract(1, 'days') + .toDate() + : end; + const bookingEnd = formatDate(intl, endDate); const bookingPrice = isOrder ? tx.attributes.payinTotal : tx.attributes.payoutTotal; const price = formatMoney(intl, bookingPrice); - return { bookingStart, bookingEnd, price }; + return { bookingStart, bookingEnd, price, isSingleDay }; }; export const InboxItem = props => { - const { type, tx, intl } = props; + const { unitType, type, tx, intl } = props; const { customer, provider } = tx; const isOrder = type === 'order'; @@ -142,7 +154,10 @@ export const InboxItem = props => { const lastTransitionedAt = formatDate(intl, tx.attributes.lastTransitionedAt); const isEnquiry = propTypes.txIsEnquired(tx); - const { bookingStart, bookingEnd, price } = isEnquiry ? {} : bookingData(tx, isOrder, intl); + const { bookingStart, bookingEnd, price, isSingleDay } = isEnquiry + ? {} + : bookingData(unitType, tx, isOrder, intl); + const dateInfo = isSingleDay ? bookingStart.short : `${bookingStart.short} - ${bookingEnd.short}`; const linkClasses = classNames(css.itemLink, { [css.bannedUserLink]: isOtherUserBanned, @@ -165,7 +180,7 @@ export const InboxItem = props => { {!isEnquiry ? (
- {bookingStart.short} - {bookingEnd.short} + {dateInfo} {price}
) : null} @@ -187,6 +202,7 @@ export const InboxItem = props => { }; InboxItem.propTypes = { + unitType: oneOf([propTypes.LINE_ITEM_NIGHT, propTypes.LINE_ITEM_DAY]), type: oneOf(['order', 'sale']).isRequired, tx: propTypes.transaction.isRequired, intl: intlShape.isRequired, @@ -194,6 +210,7 @@ InboxItem.propTypes = { export const InboxPageComponent = props => { const { + unitType, currentUser, fetchInProgress, fetchOrdersOrSalesError, @@ -220,7 +237,7 @@ export const InboxPageComponent = props => { const toTxItem = tx => { return (
  • - +
  • ); }; @@ -320,6 +337,7 @@ export const InboxPageComponent = props => { }; InboxPageComponent.defaultProps = { + unitType: config.bookingUnitType, currentUser: null, currentUserHasOrders: null, fetchOrdersOrSalesError: null, @@ -333,6 +351,7 @@ InboxPageComponent.propTypes = { tab: string.isRequired, }).isRequired, + unitType: oneOf([propTypes.LINE_ITEM_NIGHT, propTypes.LINE_ITEM_DAY]), currentUser: propTypes.currentUser, fetchInProgress: bool.isRequired, fetchOrdersOrSalesError: propTypes.error, diff --git a/src/containers/InboxPage/InboxPage.test.js b/src/containers/InboxPage/InboxPage.test.js index 70ff35d3..34957b16 100644 --- a/src/containers/InboxPage/InboxPage.test.js +++ b/src/containers/InboxPage/InboxPage.test.js @@ -10,7 +10,7 @@ import { } from '../../util/test-data'; import { InboxPageComponent, InboxItem } from './InboxPage'; import routeConfiguration from '../../routeConfiguration'; -import { TX_TRANSITION_PREAUTHORIZE } from '../../util/propTypes'; +import { TX_TRANSITION_PREAUTHORIZE, LINE_ITEM_NIGHT } from '../../util/propTypes'; const noop = () => null; @@ -31,6 +31,7 @@ describe('InboxPage', () => { }); const ordersProps = { + unitType: LINE_ITEM_NIGHT, location: { search: '' }, history: { push: () => console.log('HistoryPush called'), @@ -74,11 +75,17 @@ describe('InboxPage', () => { // Deeply render one InboxItem const orderItem = renderDeep( - + ); expect(orderItem).toMatchSnapshot(); const salesProps = { + unitType: LINE_ITEM_NIGHT, location: { search: '' }, history: { push: () => console.log('HistoryPush called'), @@ -122,7 +129,12 @@ describe('InboxPage', () => { // Deeply render one InboxItem const saleItem = renderDeep( - + ); expect(saleItem).toMatchSnapshot(); }); diff --git a/src/containers/InboxPage/__snapshots__/InboxPage.test.js.snap b/src/containers/InboxPage/__snapshots__/InboxPage.test.js.snap index 7ab5e382..55f06600 100644 --- a/src/containers/InboxPage/__snapshots__/InboxPage.test.js.snap +++ b/src/containers/InboxPage/__snapshots__/InboxPage.test.js.snap @@ -195,6 +195,7 @@ exports[`InboxPage matches snapshot 1`] = ` } } type="order" + unitType="line-item/night" />
  • @@ -317,6 +318,7 @@ exports[`InboxPage matches snapshot 1`] = ` } } type="order" + unitType="line-item/night" />
  • @@ -373,9 +375,7 @@ exports[`InboxPage matches snapshot 2`] = `
    - 2017-02-15 - - - 2017-02-16 + 2017-02-15 - 2017-02-16 @@ -597,6 +597,7 @@ exports[`InboxPage matches snapshot 3`] = ` } } type="sale" + unitType="line-item/night" />
  • @@ -719,6 +720,7 @@ exports[`InboxPage matches snapshot 3`] = ` } } type="sale" + unitType="line-item/night" />
  • @@ -779,9 +781,7 @@ exports[`InboxPage matches snapshot 4`] = `
    - 2017-02-15 - - - 2017-02-16 + 2017-02-15 - 2017-02-16