Move some logic out of time-slot into schedule

Get rid of lots of watchers in time-slot
This commit is contained in:
Scott Kiener 2025-08-04 10:24:58 -04:00
parent 6af4bca738
commit fd3a8e1aee
2 changed files with 90 additions and 123 deletions

View file

@ -146,7 +146,8 @@
:isPricingByDayExperiment="isPricingByDayExperiment" /> :isPricingByDayExperiment="isPricingByDayExperiment" />
<timeSlotQuestion <timeSlotQuestion
ref="timeSlotModalQuestion" ref="timeSlotModalQuestion"
@timeSlotSelected="updateTimeSlot" v-if="showTimeSlotQuestion"
@time-slot-selection-changed="updateTimeSlot"
cmsWidgetName="TimeSlotModalQuestion" cmsWidgetName="TimeSlotModalQuestion"
waitListLabelWidget="WaitListLabelWidget" waitListLabelWidget="WaitListLabelWidget"
waitListQuestionWidget="WaitListQuestionWidget" waitListQuestionWidget="WaitListQuestionWidget"
@ -156,13 +157,12 @@
sameDayDropOffCmsWidgetName="SameDayDropOffTimeSlotModal" sameDayDropOffCmsWidgetName="SameDayDropOffTimeSlotModal"
overnightDropOffCmsWidgetName="OvernightDropOffTimeSlotModal" overnightDropOffCmsWidgetName="OvernightDropOffTimeSlotModal"
dropOffOrPickATimeQuestionCmsWidgetName="DropOffOrPickATimeQuestionWidget" dropOffOrPickATimeQuestionCmsWidgetName="DropOffOrPickATimeQuestionWidget"
:selectedDate="selectedDate"
:appointmentType="appointmentType" :appointmentType="appointmentType"
:premiumAppointmentFee="premiumAppointmentFee" :premiumAppointmentFee="mobilePremiumAppointmentFee"
:displayWaitList="displayWaitList" :displayWaitList="displayWaitList"
:timeSlotsForSelectedDate="timeSlotsForSelectedDate" :timeSlotsForSelectedDate="timeSlotsForSelectedDate"
:estimatedServiceMinutesMinimum="estimatedServiceMinutesMinimum" :isSameDay="isSameDay"
:estimatedServiceMinutesMaximum="estimatedServiceMinutesMaximum" :selectedRouteCodeData="selectedRouteCodeData"
@waitListRequested="handleWaitListRequested" /> @waitListRequested="handleWaitListRequested" />
<navbar <navbar
cmsWidgetName="FunnelFooterWidget" cmsWidgetName="FunnelFooterWidget"
@ -649,6 +649,11 @@ export default {
return this.isGlassServiceableMobile; return this.isGlassServiceableMobile;
} }
}, },
showTimeSlotQuestion() {
return (
this.selectedDate && this.appointmentTypeFromAppointmentTypeQuestion
)
},
isMobileStaticRecalibrationApplicable() { isMobileStaticRecalibrationApplicable() {
return ( return (
this.displayMSR && this.displayMSR &&
@ -806,6 +811,18 @@ export default {
} }
return []; return [];
}, },
selectedRouteCodeData() {
console.log('1', JSON.stringify(this.selectedTimeSlotInfo))
if (!this.selectedTimeSlotInfo?.timeSlot?.routeCode) {
console.log('returning null')
return null;
}
console.log('returning data');
return {
routeCode: this.selectedTimeSlotInfo.timeSlot.routeCode,
isPremiumAppointment: this.selectedTimeSlotInfo.isPremiumAppointment
}
},
questionText() { questionText() {
return this.getCmsContent("YourSafeliteShopWidget", "QuestionText"); return this.getCmsContent("YourSafeliteShopWidget", "QuestionText");
}, },
@ -1194,7 +1211,6 @@ export default {
datePickerInitialData.pricingByDayBasePrice = this.pricingByDayBasePrice; datePickerInitialData.pricingByDayBasePrice = this.pricingByDayBasePrice;
datePickerInitialData.pricingByDayUpcharge = this.pricingByDayUpcharge; datePickerInitialData.pricingByDayUpcharge = this.pricingByDayUpcharge;
await this.$refs.datePicker.initializeComponent(datePickerInitialData); await this.$refs.datePicker.initializeComponent(datePickerInitialData);
await this.$refs.timeSlotModalQuestion.initializeComponent();
this.selectableDatesInshop = this.selectableDatesInshop =
datePickerInitialData.initialShopTimeSlotsResponse.inshopTimeSlotsData; datePickerInitialData.initialShopTimeSlotsResponse.inshopTimeSlotsData;
this.selectableDatesMobile = this.selectableDatesMobile =
@ -1592,7 +1608,7 @@ export default {
console.log("timeSlotObj", timeSlotObj); console.log("timeSlotObj", timeSlotObj);
if (!timeSlotObj?.routeCode) { if (!timeSlotObj?.routeCode) {
this.appointmentType = AppointmentTypeStrings.IN_SHOP_OR_DROP_OFF; this.appointmentType = AppointmentTypeStrings.IN_SHOP_OR_DROP_OFF;
return { this.selectedTimeSlotInfo = {
timeSlot: { timeSlot: {
date: null, date: null,
routeCode: null, routeCode: null,
@ -1603,6 +1619,7 @@ export default {
}, },
isPremiumAppointment: null, isPremiumAppointment: null,
}; };
return;
} }
const timeSlot = this.timeSlotsForSelectedDate?.timeSlots?.find( const timeSlot = this.timeSlotsForSelectedDate?.timeSlots?.find(
(slot) => slot.id == timeSlotObj.routeCode (slot) => slot.id == timeSlotObj.routeCode
@ -1788,6 +1805,7 @@ export default {
} }
}, },
selectedTimeSlotInfo(newValue) { selectedTimeSlotInfo(newValue) {
console.log('heard a change on selectedTimeslotInfo', newValue);
this.updateFooterButtonText(newValue); this.updateFooterButtonText(newValue);
}, },
}, },

View file

@ -3,6 +3,7 @@
<buttonQuestion <buttonQuestion
v-if="isDropOffAppointmentAvailable" v-if="isDropOffAppointmentAvailable"
v-model="selectedAnswerForDropOffOrInshop" v-model="selectedAnswerForDropOffOrInshop"
@update:modelValue="dropOffSelectionChanged"
:questionText="dropOffOrPickATimeQuestionLabelText" :questionText="dropOffOrPickATimeQuestionLabelText"
:answers="answersForDropOffQuestion" :answers="answersForDropOffQuestion"
isRequired isRequired
@ -22,6 +23,7 @@
<buttonQuestion <buttonQuestion
ref="buttonQuestion" ref="buttonQuestion"
v-if="shouldDisplayTimeSlotQuestion" v-if="shouldDisplayTimeSlotQuestion"
@update:modelValue="timeSlotSelectionChanged"
buttonTypeString="timeSlotModalListButton" buttonTypeString="timeSlotModalListButton"
:buttonTypeObject="timeSlotModalListButton" :buttonTypeObject="timeSlotModalListButton"
class="mt-4 timeslots" class="mt-4 timeslots"
@ -41,7 +43,7 @@
v-if="supplementalInformationBlock" v-if="supplementalInformationBlock"
v-html="supplementalInformationBlock" /> v-html="supplementalInformationBlock" />
<div <div
v-if="hasWaitListExperiment && displayWaitListFeature && selectedDate" v-if="hasWaitListExperiment && displayWaitListFeature"
class="mt-5 bg-light rounded waitlist"> class="mt-5 bg-light rounded waitlist">
<textBlock <textBlock
cmsWidgetName="WaitListLabelWidget" cmsWidgetName="WaitListLabelWidget"
@ -55,7 +57,7 @@
@click="waitListChecked" /> @click="waitListChecked" />
</div> </div>
<div <div
v-if="waitListRequested && displayWaitList && selectedDate" v-if="waitListRequested && displayWaitList"
class="rounded waitlist-success" class="rounded waitlist-success"
ref="waitlistSuccessMessage"> ref="waitlistSuccessMessage">
<img :src="waitListSuccessImage" class="success-image" /> <img :src="waitListSuccessImage" class="success-image" />
@ -111,7 +113,7 @@ defineRule("time-slot-required", required(errorMessages.OPTION_REQUIRED));
export default { export default {
name: "time-slot-question", name: "time-slot-question",
emits: ["update:modelValue", "TimeSlotSelected", "click-event"], emits: ["update:modelValue", "time-slot-selection-changed",],
props: { props: {
cmsWidgetName: String, cmsWidgetName: String,
mobileCmsWidgetName: String, mobileCmsWidgetName: String,
@ -125,15 +127,15 @@ export default {
premiumAppointmentFee: Object, premiumAppointmentFee: Object,
validationRules: String, validationRules: String,
customComponentId: String, customComponentId: String,
selectedDate: String, isSameDay: Boolean,
displayWaitList: Boolean, displayWaitList: Boolean,
selectedRouteCodeData: Object,
}, },
data() { data() {
return { return {
selectedRouteCode: null,
timeSlotModalListButton: timeSlotModalListButton, timeSlotModalListButton: timeSlotModalListButton,
selectedAnswerForDropOffOrInshop: null, selectedAnswerForDropOffOrInshop: null,
selectedAnswerForTimeSlots: null, selectedAnswerForTimeSlots: null
}; };
}, },
setup(props) { setup(props) {
@ -165,12 +167,28 @@ export default {
errors, errors,
}; };
}, },
watch: {
waitListRequested(newVal) {
if (newVal) {
this.$nextTick(() => {
this.scrollToSuccessMessage();
});
}
},
selectedRouteCodeData(newValue) {
this.updateDropoffAndTimeSlotAnswersFromSelectedRouteCodeData(newValue);
},
timeSlotsForSelectedDate() {
this.selectedAnswerForDropOffOrInshop = null;
this.selectedAnswerForTimeSlots = null;
}
},
computed: { computed: {
supplementalInformationBlock() { supplementalInformationBlock() {
let appointmentTypeCmsWidgetName; let appointmentTypeCmsWidgetName;
if ( if (
this.selectedDate == null ||
this.appointmentType === AppointmentTypeStrings.IN_SHOP_OR_DROP_OFF || this.appointmentType === AppointmentTypeStrings.IN_SHOP_OR_DROP_OFF ||
this.appointmentType === AppointmentTypeStrings.IN_SHOP || this.appointmentType === AppointmentTypeStrings.IN_SHOP ||
this.appointmentType === AppointmentTypeStrings.DROP_OFF this.appointmentType === AppointmentTypeStrings.DROP_OFF
@ -192,11 +210,7 @@ export default {
// ); // );
// } // }
} else { } else {
if (!this.selectedAnswerForTimeSlots && this.selectedRouteCode) { appointmentTypeCmsWidgetName = this.selectedRouteCodeData?.routeCode?.includes(
// Clearing selectedRouteCode if no time slot is selected
this.resetSelectedTimeSlot();
}
appointmentTypeCmsWidgetName = this.selectedRouteCode?.includes(
PREMIUM_TIME_SLOT_ID_FLAG PREMIUM_TIME_SLOT_ID_FLAG
) )
? this.mobilePremiumCmsWidgetName ? this.mobilePremiumCmsWidgetName
@ -273,13 +287,6 @@ export default {
// return null; // return null;
// } // }
// }, // },
isSameDay() {
if (!this.timeSlotsForSelectedDate) {
return false;
}
const todaysDate = new Date().toISOString().split("T")[0];
return this.selectedDate === todaysDate;
},
availableTimeSlots() { availableTimeSlots() {
if (!this.timeSlotsForSelectedDate) { if (!this.timeSlotsForSelectedDate) {
return null; return null;
@ -381,16 +388,45 @@ export default {
}, },
}, },
methods: { methods: {
initializeComponent() { updateDropoffAndTimeSlotAnswersFromSelectedRouteCodeData(selectedRouteCodeData) {
this.setSelectedRouteCodeFromParent(); if (selectedRouteCodeData?.routeCode) {
if (isDropOffRouteCode(selectedRouteCodeData.routeCode)) {
this.selectedAnswerForDropOffOrInshop = selectedRouteCodeData.routeCode;
} else {
this.selectedAnswerForDropOffOrInshop = PICK_A_TIME_BUTTON_VALUE;
this.selectedAnswerForTimeSlots = selectedRouteCodeData.routeCode;
}
} else {
this.selectedAnswerForDropOffOrInshop = null;
this.selectedAnswerForTimeSlots = null;
}
}, },
async setSelectedTimeSlot() { dropOffSelectionChanged(newValue) {
this.selectedRouteCode = let newSelectedRouteCodeData = null;
this.selectedAnswerForTimeSlots || this.selectedAnswerForDropOffOrInshop; if(newValue && newValue != PICK_A_TIME_BUTTON_VALUE) {
this.$emit( newSelectedRouteCodeData ={
"TimeSlotSelected", routeCode: newValue,
this.getSelectedTimeSlotInfoObject(this.selectedRouteCode) isPremiumAppointment: false
); };
}
this.selectedAnswerForTimeSlots = null;
this.$emit("time-slot-selection-changed", newSelectedRouteCodeData);
},
timeSlotSelectionChanged(newValue) {
console.log('heard time slot change', newValue);
if(newValue) {
let routeCode = newValue;
let isPremiumAppointment = routeCode.includes(
PREMIUM_TIME_SLOT_ID_FLAG
);
if (isPremiumAppointment) {
routeCode = this.removePremiumFlagFromInput(routeCode);
}
this.$emit("time-slot-selection-changed", {
routeCode: routeCode,
isPremiumAppointment: isPremiumAppointment
})
}
}, },
getRelevantDropOffCmsWidgetNameForSelectedTimeSlot( getRelevantDropOffCmsWidgetNameForSelectedTimeSlot(
selectedRouteCode, selectedRouteCode,
@ -437,8 +473,6 @@ export default {
); );
} }
this.resetSelectedTimeSlotIfDateChange(timeSlotsForSelectedDate);
return availableTimeSlots; return availableTimeSlots;
}, },
getPremiumAppointmentTimeSlot(timeSlotData) { getPremiumAppointmentTimeSlot(timeSlotData) {
@ -454,27 +488,10 @@ export default {
}, },
}; };
}, },
setSelectedRouteCodeFromParent() {
if (!this.modelValue?.timeSlot?.routeCode) {
return;
}
const routeCodeFromParent = this.modelValue.timeSlot.routeCode;
if (this.modelValue?.isPremiumAppointment) {
// Mobile Only
this.selectedAnswerForTimeSlots = this.addPremiumFlagToInput(routeCodeFromParent);
} else {
if (isDropOffRouteCode(routeCodeFromParent)) {
this.selectedAnswerForDropOffOrInshop = routeCodeFromParent;
} else {
this.selectedAnswerForDropOffOrInshop = PICK_A_TIME_BUTTON_VALUE;
this.selectedAnswerForTimeSlots = routeCodeFromParent;
}
}
},
getWaitListRequestedFromStore() { getWaitListRequestedFromStore() {
return store.getters.order.customer?.waitListRequested; return store.getters.order.customer?.waitListRequested;
}, },
autoSelectTimeSlotIfOnlyOneIsAvailable() { autoSelectTimeSlotIfOnlyOneIsAvailable() { // this needs to be fixed
const numberOfOptions = this.timeSlotsForSelectedDate?.timeSlots?.length; const numberOfOptions = this.timeSlotsForSelectedDate?.timeSlots?.length;
if (this.appointmentType && numberOfOptions === 1) { if (this.appointmentType && numberOfOptions === 1) {
if (this.availableTimeSlots.length > 0) { if (this.availableTimeSlots.length > 0) {
@ -491,21 +508,6 @@ export default {
removePremiumFlagFromInput(routeCode) { removePremiumFlagFromInput(routeCode) {
return routeCode.replace(PREMIUM_TIME_SLOT_ID_FLAG, ""); return routeCode.replace(PREMIUM_TIME_SLOT_ID_FLAG, "");
}, },
getSelectedTimeSlotInfoObject(routeCode) {
// Pick a time button is not a time slot
if(routeCode === PICK_A_TIME_BUTTON_VALUE)
return null;
const routeCodeIncludesPremium = routeCode?.includes(PREMIUM_TIME_SLOT_ID_FLAG);
if (routeCodeIncludesPremium) {
routeCode = this.removePremiumFlagFromInput(routeCode);
}
return {
routeCode: routeCode,
isPremiumAppointment: routeCodeIncludesPremium
}
},
waitListChecked(event) { waitListChecked(event) {
this.$emit("waitListRequested", event.target.checked); this.$emit("waitListRequested", event.target.checked);
}, },
@ -515,59 +517,6 @@ export default {
successMessageElement.scrollIntoView({ behavior: "smooth" }); successMessageElement.scrollIntoView({ behavior: "smooth" });
} }
}, },
resetSelectedTimeSlotIfDateChange(timeSlotsForSelectedDate) {
if (this.selectedRouteCode) {
const selectedRouteCodeString = this.selectedRouteCode.replace(
PREMIUM_TIME_SLOT_ID_FLAG,
""
);
const matchingTimeSlot = timeSlotsForSelectedDate.find((slot) => {
return slot.id === selectedRouteCodeString;
});
if (!matchingTimeSlot) {
this.resetSelectedTimeSlot();
}
}
},
resetSelectedTimeSlot() {
this.selectedRouteCode = null;
},
},
watch: {
waitListRequested(newVal) {
if (newVal) {
this.$nextTick(() => {
this.scrollToSuccessMessage();
});
}
},
selectedDate: {
handler() {
this.resetSelectedTimeSlot();
this.selectedAnswerForDropOffOrInshop = null;
this.selectedAnswerForTimeSlots = null;
this.autoSelectTimeSlotIfOnlyOneIsAvailable();
},
},
selectedRouteCode(newValue) {
if (newValue) {
this.setSelectedTimeSlot();
}
},
selectedAnswerForDropOffOrInshop(newValue) {
if (newValue == PICK_A_TIME_BUTTON_VALUE) {
this.selectedRouteCode = null;
this.setSelectedTimeSlot();
} else {
this.selectedAnswerForTimeSlots = null;
this.selectedRouteCode = newValue;
}
},
selectedAnswerForTimeSlots(newValue) {
if (newValue) {
this.selectedRouteCode = newValue;
}
},
}, },
components: { components: {
textBlock, textBlock,