Refactor submit button logic
This commit is contained in:
parent
6c1b90225e
commit
10ca9ce8ba
2 changed files with 35 additions and 95 deletions
|
|
@ -108,11 +108,7 @@
|
||||||
v-if="isShopQuestionDisplayed"
|
v-if="isShopQuestionDisplayed"
|
||||||
:selectedProviderNumberFromParent="selectedProvider?.providerNumber"
|
:selectedProviderNumberFromParent="selectedProvider?.providerNumber"
|
||||||
:shopProviderDataFromParent="shopProviderData"
|
:shopProviderDataFromParent="shopProviderData"
|
||||||
@updated-serviceability="setServiceabilityDetails"
|
|
||||||
@shop-selected="onShopSelected"
|
@shop-selected="onShopSelected"
|
||||||
@updated-zipcode-ctu="setZipcodeCtu"
|
|
||||||
@update-shop-provider-data="shopProviderData = $event"
|
|
||||||
@updated-contains-military-base="setContainsMilitaryBase"
|
|
||||||
:zipCodeFromParent="zipCode"
|
:zipCodeFromParent="zipCode"
|
||||||
cmsWidgetName="YourSafeliteShopWidget" />
|
cmsWidgetName="YourSafeliteShopWidget" />
|
||||||
|
|
||||||
|
|
@ -1149,26 +1145,21 @@ export default {
|
||||||
startTime: "08:00",
|
startTime: "08:00",
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
onShopSelected(providerObject) {
|
onShopSelected(shopQuestionPopUpData) {
|
||||||
const current = this.shopProviderData?.shopProviders?.find(
|
this.shopProviderData = shopQuestionPopUpData.shopProviderData;
|
||||||
(p) => p.providerNumber === this.selectedProvider?.providerNumber
|
this.setServiceabilityDetails(shopQuestionPopUpData.serviceabilityDetails);
|
||||||
);
|
this.selectedProvider = this.shopProviderData.shopProviders.find(shopProvider => {
|
||||||
if (current) {
|
return shopProvider.providerNumber === shopQuestionPopUpData.selectedProviderNumber;
|
||||||
this.selectedProvider = current;
|
})
|
||||||
}
|
|
||||||
|
|
||||||
let provider = this.shopProviderData?.shopProviders?.find(
|
// No zipCodeData comes back if zip was not changed
|
||||||
(p) => p.providerNumber === providerObject?.providerNumber
|
if (shopQuestionPopUpData.zipCodeData) {
|
||||||
);
|
this.zipCode = shopQuestionPopUpData.zipCodeData.zipCode;
|
||||||
this.selectedProvider = provider;
|
this.state = shopQuestionPopUpData.zipCodeData.state;
|
||||||
if (providerObject && providerObject.address) {
|
this.zipCodeCtu = shopQuestionPopUpData.zipCodeData.zipCodeCtu;
|
||||||
this.zipCode = providerObject.searchedZip;
|
this.zipContainsMilitaryBase = shopQuestionPopUpData.zipCodeData.containsMilitaryBase;
|
||||||
this.state = providerObject.searchedState;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setZipcodeCtu(zipcodeCtu) {
|
|
||||||
this.zipCodeCtu = zipcodeCtu;
|
|
||||||
},
|
|
||||||
async getMoreScheduleData(startDate, endDate) {
|
async getMoreScheduleData(startDate, endDate) {
|
||||||
// called only when "View more dates" is clicked; not on initial page load
|
// called only when "View more dates" is clicked; not on initial page load
|
||||||
const moreShopTimeSlots = await getScheduleApiResponse({
|
const moreShopTimeSlots = await getScheduleApiResponse({
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,7 @@ export default {
|
||||||
localSelectedProviderNumber: null, // Revisit this, maybe not too hard
|
localSelectedProviderNumber: null, // Revisit this, maybe not too hard
|
||||||
displayInvalidZipAlert: false, // part of big refactor of asyn calls
|
displayInvalidZipAlert: false, // part of big refactor of asyn calls
|
||||||
displayNoShopsAlert: false, // part of big refactor of asyn calls
|
displayNoShopsAlert: false, // part of big refactor of asyn calls
|
||||||
|
zipCodeData: null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
|
|
@ -257,9 +258,11 @@ export default {
|
||||||
async onSearchZip(event) {
|
async onSearchZip(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.resetAlerts();
|
this.resetAlerts();
|
||||||
const zipCodeData = await this.getZipCodeData(this.localZipCode, "service-location");
|
this.zipCodeData = await this.getZipCodeData(this.localZipCode, "service-location");
|
||||||
if (!zipCodeData.isValid) {
|
// Add zipCode to zipCodeData as it does not come back from endpoint
|
||||||
this.displayInvalidZipAlert = true;
|
this.zipCodeData.zipCode = this.localZipCode;
|
||||||
|
if (!this.zipCodeData.isValid) {
|
||||||
|
this.displayInvalidZipAlert = true; // Think we can remove once done refactoring save method
|
||||||
} else {
|
} else {
|
||||||
if (this.isVehicleHeavyTruck) {
|
if (this.isVehicleHeavyTruck) {
|
||||||
// check the location endpoint to verify this zip can service a heavy truck
|
// check the location endpoint to verify this zip can service a heavy truck
|
||||||
|
|
@ -309,79 +312,25 @@ export default {
|
||||||
const selectedProvider = this.shopProviders.find(
|
const selectedProvider = this.shopProviders.find(
|
||||||
(provider) => provider.providerNumber == this.localSelectedProviderNumber
|
(provider) => provider.providerNumber == this.localSelectedProviderNumber
|
||||||
);
|
);
|
||||||
this.resetAlerts();
|
const serviceZipCode = selectedProvider.address.zipCode;
|
||||||
|
|
||||||
const zipCodeData = await this.getZipCodeData(this.localZipCode, "service-location");
|
// retrieve serviceability details
|
||||||
|
const serviceabilityDetails = await getServiceabilityDetails(
|
||||||
if (!zipCodeData.isValid) {
|
serviceZipCode,
|
||||||
this.displayInvalidZipAlert = true;
|
null,
|
||||||
} else {
|
"service-location"
|
||||||
if (this.isVehicleHeavyTruck) {
|
);
|
||||||
// check the location endpoint to verify this zip can service a heavy truck
|
const shopQuestionPopUpData = {
|
||||||
const closestShops = await getClosestApplicableShops(
|
serviceabilityDetails: serviceabilityDetails.data,
|
||||||
selectedProvider.address.zipCode,
|
zipCodeData: this.zipCodeData,
|
||||||
this.carId,
|
shopProviderData: this.localShopProviderData,
|
||||||
"service-location"
|
selectedProviderNumber: this.localSelectedProviderNumber
|
||||||
);
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
},
|
this.$emit("shop-selected", shopQuestionPopUpData);
|
||||||
getShopsByZip(zipCode, shops, numberToGet = 3) {
|
|
||||||
return shops
|
this.closeModal();
|
||||||
.filter(
|
|
||||||
(shop) => shop.address && shop.address.zipCode && shop.address.zipCode !== ""
|
}
|
||||||
)
|
|
||||||
.sort((a, b) => a.distanceInMiles - b.distanceInMiles)
|
|
||||||
.slice(0, numberToGet);
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
modal,
|
modal,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue