Moved calculation of mobile fee to the page level

This commit is contained in:
Leah Schumann 2023-02-28 09:47:13 -05:00
parent 7cc3511940
commit 81819b898e
4 changed files with 60 additions and 68 deletions

View file

@ -0,0 +1,30 @@
import { storeActions } from "@/constants/store-actions";
import baseMixin from "@/mixins/base-mixin.js";
export async function getMobileFee(serviceZipCode) {
if (!serviceZipCode) {
return 0;
}
const zipCodeData = await baseMixin.methods.getZipCodeData(serviceZipCode);
// Get the Mobile Fee Part
const mobileFeePart = await baseMixin.methods.dispatchStoreAction(
storeActions.GET_MOBILE_FEE_PART,
null,
false
);
// Get the Mobile Fee Part Price
const pricingResults = await baseMixin.methods.dispatchStoreAction(
storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA,
{
availableLineItems: [mobileFeePart.data],
serviceZipCode: serviceZipCode,
ctu: zipCodeData.zipCodeCtu,
},
false
);
return Promise.resolve(baseMixin.methods.getTotalLineItemPrice(pricingResults[0]));
}

View file

@ -51,7 +51,6 @@ import alert from "@/ux-components/alert/alert";
import addressQuestions from "@/layouts/address-lookup/customer-questions/address-questions/address-questions"; import addressQuestions from "@/layouts/address-lookup/customer-questions/address-questions/address-questions";
import vehicleProtectedQuestion from "@/layouts/service-location/mobile-location-modal-questions/vehicle-protected-question/vehicle-protected-question"; import vehicleProtectedQuestion from "@/layouts/service-location/mobile-location-modal-questions/vehicle-protected-question/vehicle-protected-question";
import textBlock from "@/digital-components/text-block/text-block"; import textBlock from "@/digital-components/text-block/text-block";
import { storeActions } from "@/constants/store-actions";
export default { export default {
name: "mobile-location-modal-questions", name: "mobile-location-modal-questions",
@ -61,7 +60,6 @@ export default {
internalModel: this.copyModel(this.modelValue), internalModel: this.copyModel(this.modelValue),
displayInvalidZipAlert: false, displayInvalidZipAlert: false,
modalName: "MobileLocationModalWidget", modalName: "MobileLocationModalWidget",
mobileFee: 0.0,
}; };
}, },
props: { props: {
@ -77,6 +75,7 @@ export default {
}, },
isVehicleProtected: null, isVehicleProtected: null,
serviceZipCode: "", serviceZipCode: "",
mobileFee: 0,
}), }),
}, },
isZipServiceableMobile: Boolean, isZipServiceableMobile: Boolean,
@ -86,35 +85,6 @@ export default {
alertNonServiceableZipWidgetName: String, alertNonServiceableZipWidgetName: String,
alertInvalidZipWidgetName: String, alertInvalidZipWidgetName: String,
}, },
async mounted() {
this.mobileFee = await this.getMobileFee();
// this.getMobileFee().then((result) => {
// console.log(result);
// this.mobileFee = result;
// console.log(this.mobileFee);
// });
// if (this.serviceZipCode !== "") {
// console.log(`Calling this.getMobileFee() inside mounted()`);
// this.mobileFee = await this.getMobileFee();
// console.log(
// `After calling this.getMobileFee() inside mounted(), result: ${this.mobileFee}`
// );
// }
// // this.getMobileFee().then((result) => {
// // console.log(`After calling this.getMobileFee() inside mounted()`);
// // console.log(`Result of this.getMobileFee() ${result}`);
// // //this.test = "this";
// // //console.log(this.test);
// // this.mobileFee = result;
// // console.log(
// // `Value of this.mobile fee after calling this.getMobileFee(): ${this.mobileFee}`
// // );
// // });
// //console.log(`After calling this.getMobileFee() inside mounted() - NOT IN THE CALLBACK`);
},
computed: { computed: {
mobileLocationLinkPromptText() { mobileLocationLinkPromptText() {
return this.getCmsContent(this.linkWidgetName, "HeaderText"); return this.getCmsContent(this.linkWidgetName, "HeaderText");
@ -139,7 +109,10 @@ export default {
}, },
mobileFeeText() { mobileFeeText() {
const cmsContentText = this.getCmsContent("MobileFeeDisclaimerWidget", "Text"); const cmsContentText = this.getCmsContent("MobileFeeDisclaimerWidget", "Text");
return cmsContentText.replaceAll("{custom:mobileFee}", this.mobileFee); if (this.modelValue.mobileFee === undefined) {
return cmsContentText.replaceAll("{custom:mobileFee}", 0);
}
return cmsContentText.replaceAll("{custom:mobileFee}", this.modelValue.mobileFee);
}, },
modalFooterText() { modalFooterText() {
return this.getCmsContent(this.modalWidgetName, "FooterText"); return this.getCmsContent(this.modalWidgetName, "FooterText");
@ -159,35 +132,6 @@ export default {
this.internalModel.serviceZipCode = serviceZipCode; this.internalModel.serviceZipCode = serviceZipCode;
}, },
async getMobileFee() {
if (!this.internalModel.serviceZipCode) {
return 0.0;
}
const zipCodeData = await this.getZipCodeData(this.internalModel.serviceZipCode);
console.log(zipCodeData);
// Get the Mobile Fee Part
const mobileFeePart = await this.dispatchStoreAction(
storeActions.GET_MOBILE_FEE_PART,
null,
false
);
console.log(mobileFeePart);
// Get the Mobile Fee Part Price
const pricingResults = await this.dispatchStoreAction(
storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA,
{
availableLineItems: [mobileFeePart.data],
serviceZipCode: this.internalModel.serviceZipCode,
ctu: zipCodeData.zipCodeCtu,
},
false
);
console.log(pricingResults);
return this.getTotalLineItemPrice(pricingResults[0]);
},
openModal() { openModal() {
this.$refs[this.modalName].openModal(); this.$refs[this.modalName].openModal();
}, },
@ -246,11 +190,6 @@ export default {
modelValue(newValue) { modelValue(newValue) {
this.internalModel = this.copyModel(newValue); this.internalModel = this.copyModel(newValue);
}, },
"modelValue.serviceZipCode": {
async handler(newValue) {
this.mobileFee = await this.getMobileFee();
},
},
}, },
components: { components: {
textLink, textLink,

View file

@ -6,6 +6,7 @@
<funnelSubHeader cmsWidgetName="FunnelSubHeaderWidget" /> <funnelSubHeader cmsWidgetName="FunnelSubHeaderWidget" />
<serviceZipModalQuestion <serviceZipModalQuestion
v-model="serviceZipCodeQuestion" v-model="serviceZipCodeQuestion"
@updated-service-zip-code="recalculateMobileFee"
ref="serviceZipCodeQuestion" ref="serviceZipCodeQuestion"
linkWidgetName="ServiceZipLinkWidget" linkWidgetName="ServiceZipLinkWidget"
modalWidgetName="ServiceZipModalWidget" /> modalWidgetName="ServiceZipModalWidget" />
@ -37,6 +38,7 @@ import { Form } from "vee-validate";
import { fetchCmsContentForPage } from "@/helpers/cms-content-helper"; import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
import { settleAllPromises } from "@/helpers/layout-helper"; import { settleAllPromises } from "@/helpers/layout-helper";
import { navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; import { navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper";
import { getMobileFee } from "@/helpers/service-location-helper";
import store from "@/store"; import store from "@/store";
export default { export default {
@ -60,20 +62,27 @@ export default {
}, },
isVehicleProtected: null, isVehicleProtected: null,
serviceZipCode: this.getServiceZipCodeFromStore(), serviceZipCode: this.getServiceZipCodeFromStore(),
mobileFee: 0,
}, },
}; };
}, },
async beforeRouteEnter(to, from, next) { async beforeRouteEnter(to, from, next) {
// Call APIs // Call APIs
const cmsContentPromise = fetchCmsContentForPage(to.query.fmgPage); const cmsContentPromise = fetchCmsContentForPage(to.query.fmgPage);
const serviceZipCode = store.getters.order.serviceLocation.zipCode;
const mobileFeePromise = getMobileFee(serviceZipCode);
// Settle promises and get results // Settle promises and get results
const promiseResultMap = [ const promiseResultMap = [
{ {
resultKey: "cmsContent", resultKey: "cmsContent",
promise: cmsContentPromise, promise: cmsContentPromise,
}, },
{
resultKey: "mobileFee",
promise: mobileFeePromise,
},
]; ];
const resultMap = await settleAllPromises(promiseResultMap); const resultMap = await settleAllPromises(promiseResultMap);
@ -81,9 +90,9 @@ export default {
// 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.setData(resultMap.mobileFee);
}); });
}, },
methods: { methods: {
arePagePrerequisitesValid() { arePagePrerequisitesValid() {
return true; return true;
@ -93,6 +102,11 @@ export default {
// store.getters.payment.isInsurance !== null // store.getters.payment.isInsurance !== null
// ); // );
}, },
setData(mobileFee) {
if (mobileFee) {
this.mobileLocationQuestions.mobileFee = mobileFee
}
},
getRegistrationAddressFromStore() { getRegistrationAddressFromStore() {
return this.$store.getters.vehicle.registration.address; return this.$store.getters.vehicle.registration.address;
}, },
@ -114,6 +128,11 @@ export default {
getIsServiceableFromStore() { getIsServiceableFromStore() {
return this.$store.getters.order.serviceLocation.isServiceable; return this.$store.getters.order.serviceLocation.isServiceable;
}, },
recalculateMobileFee(serviceZipCode) {
getMobileFee(serviceZipCode).then((mobileFee) => {
this.mobileLocationQuestions.mobileFee = mobileFee;
});
},
resetMobileLocation(updatedServiceZipCode) { resetMobileLocation(updatedServiceZipCode) {
this.mobileLocationQuestions = { this.mobileLocationQuestions = {
addressQuestions: { addressQuestions: {
@ -133,6 +152,8 @@ export default {
this.serviceZipCodeQuestion.state = newValue.state; this.serviceZipCodeQuestion.state = newValue.state;
this.serviceZipCodeQuestion.zipCode = newValue.zipCode; this.serviceZipCodeQuestion.zipCode = newValue.zipCode;
this.serviceZipCodeQuestion.isServiceable = newValue.isServiceable; this.serviceZipCodeQuestion.isServiceable = newValue.isServiceable;
this.recalculateMobileFee(this.serviceZipCodeQuestion.zipCode);
}, },
backButtonAction() { backButtonAction() {
this.$router.navigateWithoutSaving(this.navigationScenarios.CLICKED_BACK, this.$route); this.$router.navigateWithoutSaving(this.navigationScenarios.CLICKED_BACK, this.$route);

View file

@ -139,6 +139,8 @@ export default {
this.internalModel.state = zipCodeData.state; this.internalModel.state = zipCodeData.state;
this.internalModel.isServiceable = zipCodeData.isServiceable; this.internalModel.isServiceable = zipCodeData.isServiceable;
this.$emit("updated-service-zip-code", this.internalModel.zipCode);
// Update the page level model // Update the page level model
this.$emit("update:modelValue", this.internalModel); this.$emit("update:modelValue", this.internalModel);