Skip to content

Commit

Permalink
Extract max number of days for booking to config
Browse files Browse the repository at this point in the history
  • Loading branch information
lyyder committed Jul 17, 2018
1 parent 49d8457 commit 82e2ca7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/components/FieldDateInput/DateInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@ const defaultProps = {
enableOutsideDays: false,
isDayBlocked: () => false,

// Stripe holds funds in a reserve for up to 90 days from charge creation.
// outside range -><- today ... today+89 days -><- outside range
// outside range -><- today ... today+available days -1 -><- outside range
isOutsideRange: day => {
const daysCountAvailableToBook = 90;
const endOfRange = daysCountAvailableToBook - 1;
const endOfRange = config.dayCountAvailableForBooking - 1;
return (
!isInclusivelyAfterDay(day, moment()) ||
!isInclusivelyBeforeDay(day, moment().add(endOfRange, 'days'))
Expand Down
6 changes: 2 additions & 4 deletions src/components/FieldDateRangeInput/DateRangeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,9 @@ const defaultProps = {
enableOutsideDays: false,
isDayBlocked: () => false,

// Stripe holds funds in a reserve for up to 90 days from charge creation.
// outside range -><- today ... today+89 days -><- outside range
// outside range -><- today ... today+available days -1 -><- outside range
isOutsideRange: day => {
const daysCountAvailableToBook = 90;
const endOfRange = daysCountAvailableToBook - 1;
const endOfRange = config.dayCountAvailableForBooking - 1;
return (
!isInclusivelyAfterDay(day, moment()) ||
!isInclusivelyBeforeDay(day, moment().add(endOfRange, 'days'))
Expand Down
6 changes: 6 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ const bookingProcessAlias = 'preauth-with-nightly-booking/release-1';
// translations when the unit is changed.
const bookingUnitType = 'line-item/night';

// A maximum number of days forwards during which a booking can be made.
// This is limited due to Stripe holding funds up to 90 days from the
// moment they are charged.
const dayCountAvailableForBooking = 90;

// To pass environment variables to the client app in the build
// script, react-scripts (and the sharetribe-scripts fork of
// react-scripts) require using the REACT_APP_ prefix to avoid
Expand Down Expand Up @@ -293,6 +298,7 @@ const config = {
locale,
bookingProcessAlias,
bookingUnitType,
dayCountAvailableForBooking,
i18n,
sdk: {
clientId: sdkClientId,
Expand Down
2 changes: 1 addition & 1 deletion src/containers/ListingPage/ListingPage.duck.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export const loadData = (params, search) => dispatch => {
// in the future due to Stripe limitations
const start = moment().toDate();
const end = moment()
.add(90, 'days')
.add(config.dayCountAvailableForBooking, 'days')
.toDate();
const timeSlotsParams = { listingId, start, end };

Expand Down

0 comments on commit 82e2ca7

Please sign in to comment.