diff --git a/src/layouts/scheduling/scheduling.vue b/src/layouts/scheduling/scheduling.vue index 7cca53596..b889826c8 100644 --- a/src/layouts/scheduling/scheduling.vue +++ b/src/layouts/scheduling/scheduling.vue @@ -88,6 +88,20 @@ function toDateString(offsetDays, base = new Date()) { const SCHEDULE_FETCH_DAYS = 15; const SCHEDULING_RADIO_GROUP_NAME = "schedulingTimeSlot"; +/** + * Appends days from newSlots into entry.timeSlots, initializing it if absent. + * @param {{ timeSlots: { days: any[] } | null }} entry + * @param {{ days: any[] } | null | undefined} newSlots + */ +function appendDays(entry, newSlots) { + if (!newSlots) return; + if (!entry.timeSlots) { + entry.timeSlots = newSlots; + } else { + entry.timeSlots.days = [...(entry.timeSlots.days ?? []), ...(newSlots.days ?? [])]; + } +} + /** * Returns a promise for inshop time slots for a single provider. * @param {{ startDate: string, endDate: string, providerNumber: string, pageNameToLog: string }} params @@ -326,29 +340,13 @@ export default { const resultMap = await settleAllPromises(promiseResultMap); + // Provider order is fixed after beforeRouteEnter, so index keys are stable. this.inShopProvidersAndTimeslots.forEach((entry, index) => { - const newSlots = resultMap[`inshopTimeSlots_${index}`]; - if (!newSlots) return; - if (!entry.timeSlots) { - entry.timeSlots = newSlots; - } else { - entry.timeSlots.days = [ - ...(entry.timeSlots.days ?? []), - ...(newSlots.days ?? []), - ]; - } + appendDays(entry, resultMap[`inshopTimeSlots_${index}`]); }); - if (this.mobileProviderAndTimeSlot && resultMap.mobileTimeSlots) { - const newSlots = resultMap.mobileTimeSlots; - if (!this.mobileProviderAndTimeSlot.timeSlots) { - this.mobileProviderAndTimeSlot.timeSlots = newSlots; - } else { - this.mobileProviderAndTimeSlot.timeSlots.days = [ - ...(this.mobileProviderAndTimeSlot.timeSlots.days ?? []), - ...(newSlots.days ?? []), - ]; - } + if (this.mobileProviderAndTimeSlot) { + appendDays(this.mobileProviderAndTimeSlot, resultMap.mobileTimeSlots); } this.datePickerEndDate = newEndDate;