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
|
|
@ -321,7 +321,7 @@ export default {
|
|||
"payment-method",
|
||||
false
|
||||
);
|
||||
|
||||
|
||||
// Match all line items to the line items as they are in the store
|
||||
// and rebuild the original structure.
|
||||
this.lineItems = taxedLineItems;
|
||||
|
|
|
|||
|
|
@ -192,8 +192,6 @@ export default {
|
|||
// Call APIs
|
||||
const cmsContentPromise = fetchCmsContentForPage(to.name);
|
||||
|
||||
let lineItemsFromStore = deepClone(store.getters.order.lineItems);
|
||||
|
||||
const wipersPromise = baseMixin.methods.dispatchStoreActionWithLogging(
|
||||
storeActions.GET_WIPERS,
|
||||
{
|
||||
|
|
@ -209,9 +207,6 @@ export default {
|
|||
"payment-method"
|
||||
);
|
||||
|
||||
// const reviewDropdownPromise = reviewDropdown.methods.loadInitialData();
|
||||
// (removed temporarily for Heritage parity effort)
|
||||
|
||||
const promiseResultMap = [
|
||||
{
|
||||
resultKey: "cmsContent",
|
||||
|
|
@ -225,15 +220,11 @@ export default {
|
|||
resultKey: "rainDefense",
|
||||
promise: rainDefensePromise,
|
||||
},
|
||||
// {
|
||||
// resultKey: "reviewDropdownData",
|
||||
// promise: reviewDropdownPromise,
|
||||
// },
|
||||
// (removed temporarily for Heritage parity effort)
|
||||
];
|
||||
|
||||
const resultMap = await settleAllPromises(promiseResultMap);
|
||||
|
||||
let lineItemsFromStore = deepClone(store.getters.order.lineItems);
|
||||
const glassParts = lineItemsFromStore.glassParts ?? [];
|
||||
const supportingItems = lineItemsFromStore.supportingItems ?? [];
|
||||
const vaps = lineItemsFromStore.vaps ?? [];
|
||||
|
|
|
|||
|
|
@ -852,7 +852,7 @@ export default {
|
|||
promoAdded(lineItems) {
|
||||
const alert = createPromoSuccessAlert(lineItems.promos[0].promoCode);
|
||||
this.$refs.funnelHeader.pushGlobalAlert(alert, alert.shouldAutoFade);
|
||||
}
|
||||
},
|
||||
},
|
||||
components: {
|
||||
funnelHeader,
|
||||
|
|
|
|||
|
|
@ -452,111 +452,47 @@ export default {
|
|||
};
|
||||
},
|
||||
async beforeRouteEnter(to, from, next) {
|
||||
const isPricingByDayExperiment = experimentMixin.methods.hasSettingEqualTo(
|
||||
experimentSettings.PRICING_BY_DAY,
|
||||
"true"
|
||||
);
|
||||
const showPricingByDay = !store.getters.payment.isInsurance && isPricingByDayExperiment;
|
||||
const serviceZipCode = store.getters.order.serviceLocation.zipCode;
|
||||
|
||||
// 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 alertReasonsPromise = locationAlerts.methods.loadInitialData(
|
||||
store.getters.order.serviceLocation.zipCodeCtu,
|
||||
store.getters.order.serviceLocation.provider?.address?.zipCodeCtu
|
||||
);
|
||||
|
||||
const serviceZipCode = store.getters.order.serviceLocation.zipCode;
|
||||
const zipCodeDataPromise = getZipCodeData(serviceZipCode);
|
||||
const serviceabilityDetailsPromise = getServiceabilityDetails(
|
||||
serviceZipCode,
|
||||
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(
|
||||
storeActions.GET_MOBILE_PREMIUM_FEE,
|
||||
null,
|
||||
"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
|
||||
const promiseResultMap = [
|
||||
{
|
||||
|
|
@ -567,18 +503,6 @@ export default {
|
|||
resultKey: "alertReasons",
|
||||
promise: alertReasonsPromise,
|
||||
},
|
||||
{
|
||||
resultKey: "pricingByDayUpchargePart",
|
||||
promise: pricingByDayUpchargePartPromise,
|
||||
},
|
||||
{
|
||||
resultKey: "premiumFeeWithPrice",
|
||||
promise: premiumFeeWithPricePromise,
|
||||
},
|
||||
{
|
||||
resultKey: "zipCodeData",
|
||||
promise: zipCodeDataPromise,
|
||||
},
|
||||
{
|
||||
resultKey: "mobileFeePart",
|
||||
promise: mobileFeePartPromise,
|
||||
|
|
@ -587,39 +511,72 @@ export default {
|
|||
resultKey: "serviceabilityDetails",
|
||||
promise: serviceabilityDetailsPromise,
|
||||
},
|
||||
{
|
||||
resultKey: "premiumFee",
|
||||
promise: premiumFeePromise,
|
||||
},
|
||||
];
|
||||
|
||||
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
|
||||
const pricingByDayUpcharge =
|
||||
showPricingByDay && resultMap.pricingByDayUpchargePart
|
||||
? await baseMixin.methods.getTotalLineItemPrice(
|
||||
resultMap.pricingByDayUpchargePart,
|
||||
false
|
||||
)
|
||||
: null;
|
||||
if (itemsToPrice.length) {
|
||||
const pricedItems = await baseMixin.methods.dispatchStoreActionWithLogging(
|
||||
storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA,
|
||||
{
|
||||
availableLineItems: itemsToPrice,
|
||||
},
|
||||
"schedule",
|
||||
false
|
||||
);
|
||||
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.
|
||||
next((vm) => {
|
||||
vm.setCmsContent(resultMap.cmsContent);
|
||||
vm.$refs.locationAlerts.initializeComponent(resultMap.alertReasons);
|
||||
vm.mobilePremiumAppointmentFee = resultMap.premiumFeeWithPrice
|
||||
? resultMap.premiumFeeWithPrice[0]
|
||||
: null;
|
||||
vm.mobilePremiumAppointmentFee = pricedPremiumFee;
|
||||
vm.updateFooterButtonText(vm.selectedTimeSlotInfo);
|
||||
vm.pricingByDayUpchargeLineItem = resultMap.pricingByDayUpchargePart;
|
||||
vm.includePricingByDayUpcharge = includePricingByDayUpcharge;
|
||||
vm.isPricingByDayExperiment = isPricingByDayExperiment;
|
||||
vm.pricingByDayBasePrice = pricingByDayBasePrice;
|
||||
vm.pricingByDayUpcharge = pricingByDayUpcharge;
|
||||
vm.showPricingByDay = showPricingByDay;
|
||||
vm.pricingByDayUpchargeLineItem = null; // Pricing By Day Upcharge Line Item is not used in this version
|
||||
vm.includePricingByDayUpcharge = false; // Pricing By Day Upcharge is not used in this version
|
||||
vm.isPricingByDayExperiment = false; // Pricing By Day Experiment is not used in this version
|
||||
vm.pricingByDayBasePrice = null; // Pricing By Day Base Price is not used in this version
|
||||
vm.pricingByDayUpcharge = null; // Pricing By Day Upcharge is not used in this version
|
||||
vm.showPricingByDay = false; // Pricing By Day is not used in this version
|
||||
vm.preSelectedDate = preSelectedDate;
|
||||
vm.appointmentType = appointmentType;
|
||||
vm.setData(
|
||||
resultMap.zipCodeData,
|
||||
zipCodeData,
|
||||
resultMap.serviceabilityDetails,
|
||||
resultMap.mobileFeePart,
|
||||
pricedMobileFeePart,
|
||||
shopProviderData.data
|
||||
);
|
||||
vm.initializeDatePicker();
|
||||
|
|
|
|||
Loading…
Reference in a new issue