Skip to content

Commit

Permalink
Add a config flag for fetching availability
Browse files Browse the repository at this point in the history
  • Loading branch information
lyyder committed Jul 23, 2018
1 parent 58cd621 commit 8c2033c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
5 changes: 5 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const bookingProcessAlias = 'preauth-with-nightly-booking/release-1';
// translations when the unit is changed.
const bookingUnitType = 'line-item/night';

// Should the application fetch available time slots (currently defined as
// start and end dates) to be shown on listing page.
const fetchAvailableTimeSlots = false;

// 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.
Expand Down Expand Up @@ -318,6 +322,7 @@ const config = {
locale,
bookingProcessAlias,
bookingUnitType,
fetchAvailableTimeSlots,
dayCountAvailableForBooking,
i18n,
sdk: {
Expand Down
32 changes: 18 additions & 14 deletions src/containers/ListingPage/ListingPage.duck.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,22 @@ export const loadData = (params, search) => dispatch => {
return dispatch(showListing(listingId, true));
}

// fetch time slots for 90 days starting today
// as the booking can only be done for 90 days
// in the future due to Stripe limitations
const start = moment().toDate();
const end = moment()
.add(config.dayCountAvailableForBooking, 'days')
.toDate();
const timeSlotsParams = { listingId, start, end };

return Promise.all([
dispatch(showListing(listingId)),
dispatch(fetchTimeSlots(timeSlotsParams)),
dispatch(fetchReviews(listingId)),
]);
if (config.fetchAvailableTimeSlots) {
// fetch time slots for 90 days starting today
// as the booking can only be done for 90 days
// in the future due to Stripe limitations
const start = moment().toDate();
const end = moment()
.add(config.dayCountAvailableForBooking, 'days')
.toDate();
const timeSlotsParams = { listingId, start, end };

return Promise.all([
dispatch(showListing(listingId)),
dispatch(fetchTimeSlots(timeSlotsParams)),
dispatch(fetchReviews(listingId)),
]);
} else {
return Promise.all([dispatch(showListing(listingId)), dispatch(fetchReviews(listingId))]);
}
};

0 comments on commit 8c2033c

Please sign in to comment.