From 8c2033ccc6dd99979d2f18ba1fc27db8d7f04890 Mon Sep 17 00:00:00 2001 From: Hannu Lyytikainen Date: Mon, 23 Jul 2018 18:39:03 +0300 Subject: [PATCH] Add a config flag for fetching availability --- src/config.js | 5 ++++ .../ListingPage/ListingPage.duck.js | 30 +++++++++++-------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/config.js b/src/config.js index 93a3db5d..3b94037a 100644 --- a/src/config.js +++ b/src/config.js @@ -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. @@ -318,6 +322,7 @@ const config = { locale, bookingProcessAlias, bookingUnitType, + fetchAvailableTimeSlots, dayCountAvailableForBooking, i18n, sdk: { diff --git a/src/containers/ListingPage/ListingPage.duck.js b/src/containers/ListingPage/ListingPage.duck.js index a2617191..2dafe664 100644 --- a/src/containers/ListingPage/ListingPage.duck.js +++ b/src/containers/ListingPage/ListingPage.duck.js @@ -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 }; + 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)), - ]); + return Promise.all([ + dispatch(showListing(listingId)), + dispatch(fetchTimeSlots(timeSlotsParams)), + dispatch(fetchReviews(listingId)), + ]); + } else { + return Promise.all([dispatch(showListing(listingId)), dispatch(fetchReviews(listingId))]); + } };