diff --git a/src/layouts/schedule/schedule.vue b/src/layouts/schedule/schedule.vue index 1adf90f21..87357744a 100644 --- a/src/layouts/schedule/schedule.vue +++ b/src/layouts/schedule/schedule.vue @@ -108,11 +108,7 @@ v-if="isShopQuestionDisplayed" :selectedProviderNumberFromParent="selectedProvider?.providerNumber" :shopProviderDataFromParent="shopProviderData" - @updated-serviceability="setServiceabilityDetails" @shop-selected="onShopSelected" - @updated-zipcode-ctu="setZipcodeCtu" - @update-shop-provider-data="shopProviderData = $event" - @updated-contains-military-base="setContainsMilitaryBase" :zipCodeFromParent="zipCode" cmsWidgetName="YourSafeliteShopWidget" /> @@ -1149,26 +1145,21 @@ export default { startTime: "08:00", }; }, - onShopSelected(providerObject) { - const current = this.shopProviderData?.shopProviders?.find( - (p) => p.providerNumber === this.selectedProvider?.providerNumber - ); - if (current) { - this.selectedProvider = current; - } + onShopSelected(shopQuestionPopUpData) { + this.shopProviderData = shopQuestionPopUpData.shopProviderData; + this.setServiceabilityDetails(shopQuestionPopUpData.serviceabilityDetails); + this.selectedProvider = this.shopProviderData.shopProviders.find(shopProvider => { + return shopProvider.providerNumber === shopQuestionPopUpData.selectedProviderNumber; + }) - let provider = this.shopProviderData?.shopProviders?.find( - (p) => p.providerNumber === providerObject?.providerNumber - ); - this.selectedProvider = provider; - if (providerObject && providerObject.address) { - this.zipCode = providerObject.searchedZip; - this.state = providerObject.searchedState; + // No zipCodeData comes back if zip was not changed + if (shopQuestionPopUpData.zipCodeData) { + this.zipCode = shopQuestionPopUpData.zipCodeData.zipCode; + this.state = shopQuestionPopUpData.zipCodeData.state; + this.zipCodeCtu = shopQuestionPopUpData.zipCodeData.zipCodeCtu; + this.zipContainsMilitaryBase = shopQuestionPopUpData.zipCodeData.containsMilitaryBase; } }, - setZipcodeCtu(zipcodeCtu) { - this.zipCodeCtu = zipcodeCtu; - }, async getMoreScheduleData(startDate, endDate) { // called only when "View more dates" is clicked; not on initial page load const moreShopTimeSlots = await getScheduleApiResponse({ diff --git a/src/layouts/service-location/shop-question/shop-question-popup.vue b/src/layouts/service-location/shop-question/shop-question-popup.vue index 1fa864178..b7683ba18 100644 --- a/src/layouts/service-location/shop-question/shop-question-popup.vue +++ b/src/layouts/service-location/shop-question/shop-question-popup.vue @@ -114,6 +114,7 @@ export default { localSelectedProviderNumber: null, // Revisit this, maybe not too hard displayInvalidZipAlert: false, // part of big refactor of asyn calls displayNoShopsAlert: false, // part of big refactor of asyn calls + zipCodeData: null, }; }, props: { @@ -257,9 +258,11 @@ export default { async onSearchZip(event) { event.preventDefault(); this.resetAlerts(); - const zipCodeData = await this.getZipCodeData(this.localZipCode, "service-location"); - if (!zipCodeData.isValid) { - this.displayInvalidZipAlert = true; + this.zipCodeData = await this.getZipCodeData(this.localZipCode, "service-location"); + // Add zipCode to zipCodeData as it does not come back from endpoint + this.zipCodeData.zipCode = this.localZipCode; + if (!this.zipCodeData.isValid) { + this.displayInvalidZipAlert = true; // Think we can remove once done refactoring save method } else { if (this.isVehicleHeavyTruck) { // check the location endpoint to verify this zip can service a heavy truck @@ -309,79 +312,25 @@ export default { const selectedProvider = this.shopProviders.find( (provider) => provider.providerNumber == this.localSelectedProviderNumber ); - this.resetAlerts(); + const serviceZipCode = selectedProvider.address.zipCode; - const zipCodeData = await this.getZipCodeData(this.localZipCode, "service-location"); - - if (!zipCodeData.isValid) { - this.displayInvalidZipAlert = true; - } else { - if (this.isVehicleHeavyTruck) { - // check the location endpoint to verify this zip can service a heavy truck - const closestShops = await getClosestApplicableShops( - selectedProvider.address.zipCode, - this.carId, - "service-location" - ); - - if (!closestShops || closestShops.providers?.length === 0) { - this.displayNoServiceAlert = true; - return null; - } - } - - selectedProvider.address.zipCodeCtu = zipCodeData.zipCodeCtu; - - // retrieve mobile fee part - const serviceZipCode = selectedProvider.address.zipCode; - const mobileFeePart = await getPricedMobileFeePart( - serviceZipCode, - "service-location" - ); - - // retrieve recycle fee part - const recycleFeePart = await getPricedRecycleFeePart( - serviceZipCode, - "service-location" - ); - - // retrieve serviceability details - const serviceabilityDetails = await getServiceabilityDetails( - serviceZipCode, - null, - "service-location" - ); - - const billToAccountNumber = await getBillToAccountNumber( - selectedProvider.address.zipCodeCtu - ); - - // update content related to service zip code - this.$emit("updated-mobile-fee-part", mobileFeePart); - this.$emit("updated-recycle-fee-part", recycleFeePart); - this.$emit("updated-serviceability", serviceabilityDetails.data); - this.$emit("updated-contains-military-base", zipCodeData.containsMilitaryBase); - this.$emit("updated-bill-to-account-number", billToAccountNumber); - this.$emit("updated-zipcode-ctu", selectedProvider.address.zipCodeCtu); - this.$emit("update-shop-provider-data", this.localShopProviderData); - this.$emit("shop-selected", { - providerNumber: selectedProvider?.providerNumber, - address: selectedProvider?.address, - searchedZip: this.localZipCode, - searchedState: zipCodeData.state, - }); - - this.closeModal(); + // retrieve serviceability details + const serviceabilityDetails = await getServiceabilityDetails( + serviceZipCode, + null, + "service-location" + ); + const shopQuestionPopUpData = { + serviceabilityDetails: serviceabilityDetails.data, + zipCodeData: this.zipCodeData, + shopProviderData: this.localShopProviderData, + selectedProviderNumber: this.localSelectedProviderNumber } - }, - getShopsByZip(zipCode, shops, numberToGet = 3) { - return shops - .filter( - (shop) => shop.address && shop.address.zipCode && shop.address.zipCode !== "" - ) - .sort((a, b) => a.distanceInMiles - b.distanceInMiles) - .slice(0, numberToGet); - }, + this.$emit("shop-selected", shopQuestionPopUpData); + + this.closeModal(); + + } }, components: { modal,