diff --git a/src/layouts/schedule/schedule.vue b/src/layouts/schedule/schedule.vue index cf0ca4d40..885dfd6a7 100644 --- a/src/layouts/schedule/schedule.vue +++ b/src/layouts/schedule/schedule.vue @@ -241,14 +241,14 @@ export default { let includePricingByDayUpcharge = false; // Check to see if date should be pre-selected - let preSelectedDate = await store.getters.order.schedule.date; - if (!preSelectedDate || preSelectedDate.startTime === null) { - preSelectedDate = null; + let preSelectedSlot = await store.getters.order.schedule; + if (!preSelectedSlot.date || preSelectedSlot?.date?.length < 1) { + preSelectedSlot = null; } else { // Check to see if pre-selected date should have pricing by day upcharge if (showPricingByDay) { // is this preSelectedDate a premium day? - const dayIndex = convertDateStringToDate(preSelectedDate).getDay(); + const dayIndex = convertDateStringToDate(preSelectedSlot?.date).getDay(); const dayObject = DAYS_OF_WEEK[dayIndex]; if (dayObject.isPricingByDayUpchargeDay) { includePricingByDayUpcharge = true; @@ -268,9 +268,9 @@ export default { const datePickerInitialDataPromise = await datePicker.methods.loadInitialData({ // setup config options for date-picker selectableDatesSetting: "custom", - initialViewRowsToShow: 5, + initialViewRowsToShow: 2, customSelectableDatesCallback: getAvailableDates, - preSelectedDate: preSelectedDate, + preSelectedDate: preSelectedSlot ? preSelectedSlot.date : preSelectedSlot, }); // Get pricingByDayUpcharge needed for Pricing By Day @@ -340,7 +340,7 @@ export default { vm.setCmsContent(resultMap.cmsContent); vm.$refs.datePicker.initializeComponent(datePickerInitialData); vm.$refs.locationAlerts.initializeComponent(resultMap.alertReasons); - vm.selectableDatesData = resultMap.datePickerInitialData.initialShopTimeSlotsResponse; + vm.selectableDatesData = datePickerInitialData.initialShopTimeSlotsResponse; vm.mobilePremiumAppointmentFee = resultMap.premiumFeeWithPrice ? resultMap.premiumFeeWithPrice[0] : null; @@ -354,6 +354,16 @@ export default { vm.showPricingByDay = showPricingByDay; }); }, + mounted() { + this.$nextTick(() => { + const selectableDatesData = this.selectableDatesData; + + // if no date selected on load, then use first available date + if (!this.selectedDate && selectableDatesData?.days?.length > 0) { + this.selectedDate = selectableDatesData.days[0].date; + } + }); + }, computed: { ChangeShopLinkText() { return this.getCmsContent("ChangeShopLink", "Text"); @@ -368,10 +378,6 @@ export default { timeSlotsForSelectedDate() { if (!this.selectedDate) return null; - let tempOutput = this.selectableDatesData.days?.find( - (selectableDate) => selectableDate.date === this.selectedDate - ); - return this.selectableDatesData.days?.find( (selectableDate) => selectableDate.date === this.selectedDate );