From b7f5cc788b6003ddb28ecda17e2749d223ba9174 Mon Sep 17 00:00:00 2001 From: Vesa Luusua Date: Mon, 11 Sep 2017 19:55:03 +0300 Subject: [PATCH] Booking period should be within the date range where Stripe is able to hold the funds. --- .../DateRangeInputField/DateRangeInput.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/DateRangeInputField/DateRangeInput.js b/src/components/DateRangeInputField/DateRangeInput.js index e64d6ce9..086ead10 100644 --- a/src/components/DateRangeInputField/DateRangeInput.js +++ b/src/components/DateRangeInputField/DateRangeInput.js @@ -1,10 +1,12 @@ /** * DateRangeInput wraps DateRangePicker from React-dates and gives a list of all default props we use. * Styles for DateRangePicker can be found from 'public/reactDates.css'. + * + * N.B. *isOutsideRange* in defaultProps is defining what dates are available to booking. */ import React, { Component, PropTypes } from 'react'; import { intlShape, injectIntl } from 'react-intl'; -import { DateRangePicker, isInclusivelyAfterDay } from 'react-dates'; +import { DateRangePicker, isInclusivelyAfterDay, isInclusivelyBeforeDay } from 'react-dates'; import classNames from 'classnames'; import moment from 'moment'; @@ -71,7 +73,15 @@ const defaultProps = { minimumNights: 1, enableOutsideDays: false, isDayBlocked: () => false, - isOutsideRange: day => !isInclusivelyAfterDay(day, moment()), + + // Stripe holds funds in a reserve for up to 90 days from charge creation. + // outside range -><- today ... today+89 days -><- outside range + isOutsideRange: day => { + const daysCountAvailableToBook = 90; + const endOfRange = daysCountAvailableToBook - 1; + return !isInclusivelyAfterDay(day, moment()) || + !isInclusivelyBeforeDay(day, moment().add(endOfRange, 'days')); + }, isDayHighlighted: () => {}, // Internationalization props