Restructure schedule beforeRouteEnter
Reduce duplicate calls and increase parallel calls
This commit is contained in:
parent
4f69380428
commit
80fea612ab
4 changed files with 82 additions and 134 deletions
|
|
@ -192,8 +192,6 @@ export default {
|
||||||
// Call APIs
|
// Call APIs
|
||||||
const cmsContentPromise = fetchCmsContentForPage(to.name);
|
const cmsContentPromise = fetchCmsContentForPage(to.name);
|
||||||
|
|
||||||
let lineItemsFromStore = deepClone(store.getters.order.lineItems);
|
|
||||||
|
|
||||||
const wipersPromise = baseMixin.methods.dispatchStoreActionWithLogging(
|
const wipersPromise = baseMixin.methods.dispatchStoreActionWithLogging(
|
||||||
storeActions.GET_WIPERS,
|
storeActions.GET_WIPERS,
|
||||||
{
|
{
|
||||||
|
|
@ -209,9 +207,6 @@ export default {
|
||||||
"payment-method"
|
"payment-method"
|
||||||
);
|
);
|
||||||
|
|
||||||
// const reviewDropdownPromise = reviewDropdown.methods.loadInitialData();
|
|
||||||
// (removed temporarily for Heritage parity effort)
|
|
||||||
|
|
||||||
const promiseResultMap = [
|
const promiseResultMap = [
|
||||||
{
|
{
|
||||||
resultKey: "cmsContent",
|
resultKey: "cmsContent",
|
||||||
|
|
@ -225,15 +220,11 @@ export default {
|
||||||
resultKey: "rainDefense",
|
resultKey: "rainDefense",
|
||||||
promise: rainDefensePromise,
|
promise: rainDefensePromise,
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// resultKey: "reviewDropdownData",
|
|
||||||
// promise: reviewDropdownPromise,
|
|
||||||
// },
|
|
||||||
// (removed temporarily for Heritage parity effort)
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const resultMap = await settleAllPromises(promiseResultMap);
|
const resultMap = await settleAllPromises(promiseResultMap);
|
||||||
|
|
||||||
|
let lineItemsFromStore = deepClone(store.getters.order.lineItems);
|
||||||
const glassParts = lineItemsFromStore.glassParts ?? [];
|
const glassParts = lineItemsFromStore.glassParts ?? [];
|
||||||
const supportingItems = lineItemsFromStore.supportingItems ?? [];
|
const supportingItems = lineItemsFromStore.supportingItems ?? [];
|
||||||
const vaps = lineItemsFromStore.vaps ?? [];
|
const vaps = lineItemsFromStore.vaps ?? [];
|
||||||
|
|
|
||||||
|
|
@ -852,7 +852,7 @@ export default {
|
||||||
promoAdded(lineItems) {
|
promoAdded(lineItems) {
|
||||||
const alert = createPromoSuccessAlert(lineItems.promos[0].promoCode);
|
const alert = createPromoSuccessAlert(lineItems.promos[0].promoCode);
|
||||||
this.$refs.funnelHeader.pushGlobalAlert(alert, alert.shouldAutoFade);
|
this.$refs.funnelHeader.pushGlobalAlert(alert, alert.shouldAutoFade);
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
funnelHeader,
|
funnelHeader,
|
||||||
|
|
|
||||||
|
|
@ -452,111 +452,47 @@ export default {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
async beforeRouteEnter(to, from, next) {
|
async beforeRouteEnter(to, from, next) {
|
||||||
const isPricingByDayExperiment = experimentMixin.methods.hasSettingEqualTo(
|
const serviceZipCode = store.getters.order.serviceLocation.zipCode;
|
||||||
experimentSettings.PRICING_BY_DAY,
|
|
||||||
"true"
|
|
||||||
);
|
|
||||||
const showPricingByDay = !store.getters.payment.isInsurance && isPricingByDayExperiment;
|
|
||||||
|
|
||||||
// Get pricingByDayBasePrice needed for Pricing By Day
|
|
||||||
const lineItems = deepClone(store.getters.order.lineItems);
|
|
||||||
const isRecalibrationOnOrder = store.getters.isRecalibrationOnOrder;
|
|
||||||
const shouldHideRecalibration =
|
|
||||||
experimentMixin.methods.hasSettingEqualTo(
|
|
||||||
experimentSettings.RECAL_PRICE_REMOVE,
|
|
||||||
"true"
|
|
||||||
) && isRecalibrationOnOrder;
|
|
||||||
const glassParts =
|
|
||||||
isRecalibrationOnOrder && shouldHideRecalibration
|
|
||||||
? getItemsWithoutRecalParts(lineItems.glassParts)
|
|
||||||
: (lineItems.glassParts ?? []);
|
|
||||||
const supportingItemsWithoutFees = baseMixin.methods.filterOutCertainPartTypesOrNumbers(
|
|
||||||
lineItems.supportingItems,
|
|
||||||
{
|
|
||||||
partNumbersToRemove: [
|
|
||||||
partNumberStrings.RECYCLE_FEE,
|
|
||||||
partNumberStrings.PRICING_BY_DAY_UPCHARGE,
|
|
||||||
],
|
|
||||||
}
|
|
||||||
);
|
|
||||||
const lineItemsToBePriced = {
|
|
||||||
glassParts: glassParts,
|
|
||||||
supportingItems: supportingItemsWithoutFees,
|
|
||||||
vaps: lineItems.vaps ?? [],
|
|
||||||
promos: lineItems.promos ?? [],
|
|
||||||
};
|
|
||||||
const priceString = getAmountDue(lineItemsToBePriced, false); // pass the IncludeTax param as false
|
|
||||||
const priceStringIntegerRoundedDown = priceString?.split(".")[0]; // same method used as getDisplayPrice() in service-package-radio used on /quote
|
|
||||||
const pricingByDayBasePrice = parseInt(priceStringIntegerRoundedDown);
|
|
||||||
let includePricingByDayUpcharge = false;
|
|
||||||
let appointmentType = store.getters.order.serviceLocation.appointmentType;
|
|
||||||
|
|
||||||
// Check to see if date should be pre-selected
|
|
||||||
let scheduleFromStore = await store.getters.order.schedule;
|
|
||||||
let preSelectedDate;
|
|
||||||
|
|
||||||
if (scheduleFromStore.date && scheduleFromStore.date.length > 0) {
|
|
||||||
preSelectedDate = scheduleFromStore.date;
|
|
||||||
|
|
||||||
if (appointmentType === AppointmentTypeStrings.MOBILE) {
|
|
||||||
preSelectedDate += "-mobile";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check to see if pre-selected date should have pricing by day upcharge
|
|
||||||
if (showPricingByDay) {
|
|
||||||
// is this preSelectedDate a higher priced pricingByDay day?
|
|
||||||
const dayIndex = convertDateStringToDate(scheduleFromStore?.date).getDay();
|
|
||||||
const dayObject = DAYS_OF_WEEK[dayIndex];
|
|
||||||
if (dayObject.isPricingByDayUpchargeDay) {
|
|
||||||
includePricingByDayUpcharge = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set up promises
|
|
||||||
const cmsContentPromise = fetchCmsContentForPage(to.name);
|
const cmsContentPromise = fetchCmsContentForPage(to.name);
|
||||||
|
|
||||||
const alertReasonsPromise = locationAlerts.methods.loadInitialData(
|
const alertReasonsPromise = locationAlerts.methods.loadInitialData(
|
||||||
store.getters.order.serviceLocation.zipCodeCtu,
|
store.getters.order.serviceLocation.zipCodeCtu,
|
||||||
store.getters.order.serviceLocation.provider?.address?.zipCodeCtu
|
store.getters.order.serviceLocation.provider?.address?.zipCodeCtu
|
||||||
);
|
);
|
||||||
|
|
||||||
const serviceZipCode = store.getters.order.serviceLocation.zipCode;
|
|
||||||
const zipCodeDataPromise = getZipCodeData(serviceZipCode);
|
|
||||||
const serviceabilityDetailsPromise = getServiceabilityDetails(
|
const serviceabilityDetailsPromise = getServiceabilityDetails(
|
||||||
serviceZipCode,
|
serviceZipCode,
|
||||||
null,
|
null,
|
||||||
"service-location"
|
"schedule"
|
||||||
|
);
|
||||||
|
let zipCodeData;
|
||||||
|
const zipCodeDataPromise = getZipCodeData(serviceZipCode);
|
||||||
|
let shopProviderData;
|
||||||
|
const shopProviderDataPromise = getShopProviderData(serviceZipCode);
|
||||||
|
const zipCodeDataAndShopProviderDataPromise = Promise.all([
|
||||||
|
zipCodeDataPromise,
|
||||||
|
shopProviderDataPromise,
|
||||||
|
]);
|
||||||
|
const mobileFeePartPromise = zipCodeDataAndShopProviderDataPromise.then(
|
||||||
|
([zipCodeDataResult, shopProviderDataResult]) => {
|
||||||
|
zipCodeData = zipCodeDataResult;
|
||||||
|
shopProviderData = shopProviderDataResult;
|
||||||
|
return baseMixin.methods.dispatchStoreActionWithLogging(
|
||||||
|
storeActions.GET_MOBILE_FEE_PART,
|
||||||
|
{
|
||||||
|
serviceZipCode: serviceZipCode,
|
||||||
|
serviceZipCodeCtu: zipCodeData.zipCodeCtu,
|
||||||
|
mobileProviderNumber: shopProviderData.data.mobileProviderNumber,
|
||||||
|
},
|
||||||
|
"schedule",
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
const mobileFeePartPromise = getPricedMobileFeePart(serviceZipCode, "service-location");
|
|
||||||
const shopProviderData = await getShopProviderData(serviceZipCode);
|
|
||||||
const providerNumber = shopProviderData?.data?.shopProviders[0]?.providerNumber;
|
|
||||||
|
|
||||||
// Get pricingByDayUpcharge needed for Pricing By Day
|
|
||||||
const pricingByDayUpchargePartPromise = showPricingByDay
|
|
||||||
? getPricingByDayPartWithPrice()
|
|
||||||
: null;
|
|
||||||
|
|
||||||
const premiumFeePromise = baseMixin.methods.dispatchStoreActionWithLogging(
|
const premiumFeePromise = baseMixin.methods.dispatchStoreActionWithLogging(
|
||||||
storeActions.GET_MOBILE_PREMIUM_FEE,
|
storeActions.GET_MOBILE_PREMIUM_FEE,
|
||||||
null,
|
null,
|
||||||
"schedule"
|
"schedule"
|
||||||
);
|
);
|
||||||
const premiumFeeWithPricePromise = premiumFeePromise.then((result) => {
|
|
||||||
if (result.data) {
|
|
||||||
return baseMixin.methods.dispatchStoreActionWithLogging(
|
|
||||||
storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA,
|
|
||||||
{
|
|
||||||
availableLineItems: [result.data],
|
|
||||||
},
|
|
||||||
"schedule",
|
|
||||||
false
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return result.data;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Settle promises and get results
|
// Settle promises and get results
|
||||||
const promiseResultMap = [
|
const promiseResultMap = [
|
||||||
{
|
{
|
||||||
|
|
@ -567,18 +503,6 @@ export default {
|
||||||
resultKey: "alertReasons",
|
resultKey: "alertReasons",
|
||||||
promise: alertReasonsPromise,
|
promise: alertReasonsPromise,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
resultKey: "pricingByDayUpchargePart",
|
|
||||||
promise: pricingByDayUpchargePartPromise,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
resultKey: "premiumFeeWithPrice",
|
|
||||||
promise: premiumFeeWithPricePromise,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
resultKey: "zipCodeData",
|
|
||||||
promise: zipCodeDataPromise,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
resultKey: "mobileFeePart",
|
resultKey: "mobileFeePart",
|
||||||
promise: mobileFeePartPromise,
|
promise: mobileFeePartPromise,
|
||||||
|
|
@ -587,39 +511,72 @@ export default {
|
||||||
resultKey: "serviceabilityDetails",
|
resultKey: "serviceabilityDetails",
|
||||||
promise: serviceabilityDetailsPromise,
|
promise: serviceabilityDetailsPromise,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
resultKey: "premiumFee",
|
||||||
|
promise: premiumFeePromise,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const resultMap = await settleAllPromises(promiseResultMap);
|
const resultMap = await settleAllPromises(promiseResultMap);
|
||||||
|
console.log("resultMap", resultMap);
|
||||||
|
const itemsToPrice = [];
|
||||||
|
if (resultMap.mobileFeePart) {
|
||||||
|
itemsToPrice.push(resultMap.mobileFeePart);
|
||||||
|
}
|
||||||
|
if (resultMap.premiumFee) {
|
||||||
|
itemsToPrice.push(resultMap.premiumFee);
|
||||||
|
}
|
||||||
|
console.log("itemsToPrice", itemsToPrice);
|
||||||
|
// Price all items
|
||||||
|
let pricedMobileFeePart = null;
|
||||||
|
let pricedPremiumFee = null;
|
||||||
|
|
||||||
// add pricing by day data
|
if (itemsToPrice.length) {
|
||||||
const pricingByDayUpcharge =
|
const pricedItems = await baseMixin.methods.dispatchStoreActionWithLogging(
|
||||||
showPricingByDay && resultMap.pricingByDayUpchargePart
|
storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA,
|
||||||
? await baseMixin.methods.getTotalLineItemPrice(
|
{
|
||||||
resultMap.pricingByDayUpchargePart,
|
availableLineItems: itemsToPrice,
|
||||||
|
},
|
||||||
|
"schedule",
|
||||||
false
|
false
|
||||||
)
|
);
|
||||||
: null;
|
pricedMobileFeePart = pricedItems.find(
|
||||||
|
(item) => item.partNumber === resultMap.mobileFeePart.partNumber
|
||||||
|
);
|
||||||
|
pricedPremiumFee = pricedItems.find(
|
||||||
|
(item) => item.partNumber === resultMap.premiumFee.partNumber
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let appointmentType = store.getters.order.serviceLocation.appointmentType;
|
||||||
|
// Check to see if date should be pre-selected
|
||||||
|
let scheduleFromStore = await store.getters.order.schedule;
|
||||||
|
let preSelectedDate;
|
||||||
|
if (scheduleFromStore.date && scheduleFromStore.date.length > 0) {
|
||||||
|
preSelectedDate = scheduleFromStore.date;
|
||||||
|
|
||||||
|
if (appointmentType === AppointmentTypeStrings.MOBILE) {
|
||||||
|
preSelectedDate += "-mobile";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Call the "next" function to complete the transition to this page.
|
// Call the "next" function to complete the transition to this page.
|
||||||
next((vm) => {
|
next((vm) => {
|
||||||
vm.setCmsContent(resultMap.cmsContent);
|
vm.setCmsContent(resultMap.cmsContent);
|
||||||
vm.$refs.locationAlerts.initializeComponent(resultMap.alertReasons);
|
vm.$refs.locationAlerts.initializeComponent(resultMap.alertReasons);
|
||||||
vm.mobilePremiumAppointmentFee = resultMap.premiumFeeWithPrice
|
vm.mobilePremiumAppointmentFee = pricedPremiumFee;
|
||||||
? resultMap.premiumFeeWithPrice[0]
|
|
||||||
: null;
|
|
||||||
vm.updateFooterButtonText(vm.selectedTimeSlotInfo);
|
vm.updateFooterButtonText(vm.selectedTimeSlotInfo);
|
||||||
vm.pricingByDayUpchargeLineItem = resultMap.pricingByDayUpchargePart;
|
vm.pricingByDayUpchargeLineItem = null; // Pricing By Day Upcharge Line Item is not used in this version
|
||||||
vm.includePricingByDayUpcharge = includePricingByDayUpcharge;
|
vm.includePricingByDayUpcharge = false; // Pricing By Day Upcharge is not used in this version
|
||||||
vm.isPricingByDayExperiment = isPricingByDayExperiment;
|
vm.isPricingByDayExperiment = false; // Pricing By Day Experiment is not used in this version
|
||||||
vm.pricingByDayBasePrice = pricingByDayBasePrice;
|
vm.pricingByDayBasePrice = null; // Pricing By Day Base Price is not used in this version
|
||||||
vm.pricingByDayUpcharge = pricingByDayUpcharge;
|
vm.pricingByDayUpcharge = null; // Pricing By Day Upcharge is not used in this version
|
||||||
vm.showPricingByDay = showPricingByDay;
|
vm.showPricingByDay = false; // Pricing By Day is not used in this version
|
||||||
vm.preSelectedDate = preSelectedDate;
|
vm.preSelectedDate = preSelectedDate;
|
||||||
vm.appointmentType = appointmentType;
|
vm.appointmentType = appointmentType;
|
||||||
vm.setData(
|
vm.setData(
|
||||||
resultMap.zipCodeData,
|
zipCodeData,
|
||||||
resultMap.serviceabilityDetails,
|
resultMap.serviceabilityDetails,
|
||||||
resultMap.mobileFeePart,
|
pricedMobileFeePart,
|
||||||
shopProviderData.data
|
shopProviderData.data
|
||||||
);
|
);
|
||||||
vm.initializeDatePicker();
|
vm.initializeDatePicker();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue