diff --git a/src/helpers/heritage-integration/navigation-helper.js b/src/helpers/heritage-integration/navigation-helper.js index 22d984530..8d46f6e4e 100644 --- a/src/helpers/heritage-integration/navigation-helper.js +++ b/src/helpers/heritage-integration/navigation-helper.js @@ -3,10 +3,8 @@ import { externalUrls } from "@/router/router-constants/externalUrl-values"; import { lazyLoadComponent } from "@/router/dynamic-routing/component-loader.js"; import { saveOrder } from "@/helpers/heritage-integration/order-helper.js"; import { fmgPageValues } from "@/router/router-constants/fmgPage-values"; -import { storeActions } from "@/constants/store-actions"; import store from "@/store"; import router from "@/router"; -import baseMixin from "@/mixins/base-mixin.js"; /* If the user has visited the funnel before this method will determine the bets place to @@ -54,21 +52,6 @@ export async function navigateToHeritageFunnel() { ); } -export async function navigateAfterSaveToHeritageFunnel(currentRoute) { - const currentComponent = currentRoute.matched[0].components; - - // Create the order (or save existing order) when navigating to Heritage Funnel. - await saveOrder(); - - router.navigateToExternalUrl( - externalUrls.HERITAGE_FUNNEL, - { - corid: store.getters.order.referralCorrelationId, - src: "concept-funnel" - } - ); -} - /* Logic for getting the last "valid" page a user visited. */ diff --git a/src/layouts/address-lookup/address-lookup.spec.js b/src/layouts/address-lookup/address-lookup.spec.js index b9e790576..569a6b145 100644 --- a/src/layouts/address-lookup/address-lookup.spec.js +++ b/src/layouts/address-lookup/address-lookup.spec.js @@ -8,7 +8,7 @@ import { storeActions } from "@/constants/store-actions"; import { storeMutations } from "@/constants/store-mutations"; import { navigationScenarios } from "@/router/router-constants/navigation-scenarios"; import store from "@/store"; -import { navigateAfterSaveToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; +import { navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; jest.mock("@/helpers/damage-helper", () => ({ @@ -17,7 +17,7 @@ jest.mock("@/helpers/damage-helper", () => ({ })); jest.mock("@/helpers/heritage-integration/navigation-helper", () => ({ - navigateAfterSaveToHeritageFunnel: jest.fn() + navigateToHeritageFunnel: jest.fn() })); describe("address-lookup.vue", () => { @@ -262,7 +262,7 @@ describe("address-lookup.vue", () => { // Assert expect(wrapper.vm.updateVehicleInfo).toHaveBeenCalled(); - expect(navigateAfterSaveToHeritageFunnel).toHaveBeenCalled(); + expect(navigateToHeritageFunnel).toHaveBeenCalled(); }); test("if the car entered does not match any of the multiple vehicles found, navigate to address-vehicles page", async () => { diff --git a/src/layouts/address-lookup/address-lookup.vue b/src/layouts/address-lookup/address-lookup.vue index 7e74a9e4c..f3029842f 100644 --- a/src/layouts/address-lookup/address-lookup.vue +++ b/src/layouts/address-lookup/address-lookup.vue @@ -132,17 +132,13 @@ export default { isSelectedGlassAvailableForVehicle: false, customAlertData: {}, showServiceZipField: this.getServiceZipFromStore(), - isZipServicable: false, + isZipServiceable: false, } }, methods: { arePagePrerequisitesValid() { return store.getters.vehicle.carId !== null; }, - resetDependentState() { - store.commit(storeMutations.UPDATE_REGISTRATION_LICENSE_PLATE, null); - store.dispatch(storeActions.RESET_PARTS_STATE_AND_DEPENDENCIES); - }, backButtonAction() { // route to move backwards this.$router.navigate( @@ -187,50 +183,69 @@ export default { async forwardButtonAction() { this.resetWarningsAndErrors(); - // Lookup VIN(s) with the provided address - const vinLookupPromise = this.lookupVin( - this.customerQuestions.lastName, - this.customerQuestions.addressQuestions.streetAddress, - this.customerQuestions.addressQuestions.zipCode, - this.customerQuestions.addressQuestions.state - ); + let vehicleInfoToCommit = {}; + let registrationInfoToCommit = {}; + + const vinLookupResponse = this.dispatchStoreAction( + storeActions.LOOKUP_VIN_BY_ADDRESS, + { + licenseLastName: this.customerQuestions.lastName, + licenseStreetAddress: this.customerQuestions.addressQuestions.streetAddress, + licenseZip: this.customerQuestions.addressQuestions.zipCode, + licenseState: this.customerQuestions.addressQuestions.state + }, false); + + // Settle promises and get results + const promiseResultMap = [ + { + resultKey: "vinLookupResponse", + promise: vinLookupResponse + }, + { + resultKey: "serviceZipValidationResponse", + promise: this.serviceZipCode ? + this.dispatchStoreAction(storeActions.VALIDATE_ZIP, {zip: this.serviceZipCode }) : + this.dispatchStoreAction(storeActions.VALIDATE_ZIP, {zip: this.customerQuestions.addressQuestions.zipCode }) + } + ]; + + const resultMap = await settleAllPromises(promiseResultMap); // Verify if the service zip code or registration zip code provided is serviceable - const serviceZipValidationPromise = this.serviceZipCode ? this.validateZip(this.serviceZipCode) : this.validateZip(this.customerQuestions.addressQuestions.zipCode); - - const vinLookupResponse = await vinLookupPromise; - const serviceZipValidationResponse = await serviceZipValidationPromise; - - if (!vinLookupResponse.data.isStatePermissible) { + if (!resultMap.vinLookupResponse.isStatePermissible) { // State Restrictions forbid lookup by address this.displayVinLookupByHomeAddressNotAllowedAlert = true; - this.$refs.funnelFooter.removeLoader(); - return; + return this.$refs.funnelFooter.removeLoader(); } // if the neither the registration zip code or service zip code are not serviceable - this.isZipServicable = serviceZipValidationResponse.data.isServiceable; - if (!this.isZipServicable) { + this.isZipServiceable = resultMap.serviceZipValidationResponse.isServiceable; + + if (!this.isZipServiceable) { this.displayNonServiceableZipAlert = true; this.showServiceZipField = true; - this.$refs.funnelFooter.removeLoader(); - } else if (!this.serviceZipCode) { - // if the registration zip code is servicable and nothing was entered for the service zip code - // then set the service zip code to the registration zip code + return this.$refs.funnelFooter.removeLoader(); + } + + // if the registration zip code is serviceable and nothing was entered for the service zip code + // then set the service zip code to the registration zip code + if (!this.serviceZipCode) { this.serviceZipCode = this.customerQuestions.addressQuestions.zipCode; } - const carEntered = store.getters.vehicle; - const carsFound = vinLookupResponse.data.vinVehicles; + //const carEntered = store.getters.vehicle; + const vinsFound = resultMap.vinLookupResponse.vinVehicles; - if (carsFound.length == 0) { - // No VINs found + // No VINs found + if (vinsFound.length == 0) { this.displayVinNotFoundAlert = true; - this.$refs.funnelFooter.removeLoader(); - return; - } else if (carsFound.length == 1) { - const carFound = carsFound[0].vehicle; - this.isCarIdDifferent = carFound.carId !== carEntered.carId; + return this.$refs.funnelFooter.removeLoader(); + } + + // Single VIN found + if (vinsFound.length == 1) { + const carFound = vinsFound[0].vehicle; + this.isCarIdDifferent = carFound.carId !== this.$store.getters.vehicle.carId; if (this.isCarIdDifferent && carFound.carId !== this.previouslyEnteredCarId) { // Display Alert @@ -242,49 +257,93 @@ export default { // Update button "Continue with..." this.$refs.funnelFooter.updateButtonText(`Continue with ${carFound.year} ${carFound.make} ${carFound.model}`); - this.$refs.funnelFooter.removeLoader(); + return this.$refs.funnelFooter.removeLoader(); + } + if (!this.isZipServiceable) { return; } - if (!this.isZipServicable) { - return; - } + // update data if the zip or service zip is serviceable - // update data if the zip or service zip is servicable - this.updateVehicleInfo(carsFound[0].vin, carFound); - this.updateCustomerInfo(serviceZipValidationResponse.data.state); + // --> New Save Method - } else if (carsFound.length > 1) { - if (!this.isZipServicable) { + // state.order.vehicle.registration.licensePlate = registrationInfo?.licensePlate; + // state.order.vehicle.registration.address = registrationInfo?.address; + // state.order.vehicle.registration.city = registrationInfo?.city; + // state.order.vehicle.registration.state = registrationInfo?.state; + // state.order.vehicle.registration.zipCode = registrationInfo?.zipCode; + // state.order.vehicle.registration.firstName = registrationInfo?.firstName; + // state.order.vehicle.registration.lastName = registrationInfo?.lastName; + + vehicleInfoToCommit = Object.assign(carFound, { vin: vinsFound[0].vin}); + registrationInfoToCommit = { + firstName: this.customerQuestions.firstName, + lastName: this.customerQuestions.lastName, + address: this.customerQuestions.addressQuestions.streetAddress, + city: this.customerQuestions.addressQuestions.city, + state: this.customerQuestions.addressQuestions.state, + zipCode: this.customerQuestions.addressQuestions.zipCode + }; + + this.updateVehicleInfo(vinsFound[0].vin, carFound); + this.updateCustomerInfo(resultMap.serviceZipValidationResponse.state); + + } + + // Found more than one VIN. + if (vinsFound.length > 1) { + if (!this.isZipServiceable) { return; } // if multiple cars were found - let matchingCars = carsFound.filter(car => car.vehicle.carId === carEntered.carId); + const matchingCars = vinsFound.filter(vin => vin.vehicle.carId === this.$store.getters.vehicle.carId); + + // and one and only one of them matches the carId entered, save the vehicle info + // so we can go to the Heritage Funnel directly if (matchingCars.length === 1) { - // and one and only one of them matches the carId entered, save the vehicle info - // so we can go to the Heritage Funnel directly - const matchingCar = matchingCars[0]; - this.updateVehicleInfo(matchingCar.vin, matchingCar.vehicle); + + this.updateVehicleInfo(matchingCars[0].vin, matchingCars[0].vehicle); } - // update data if the zip or service zip is servicable - this.updateCustomerInfo(serviceZipValidationResponse.data.state); + // update data if the zip or service zip is serviceable. + this.updateCustomerInfo(resultMap.serviceZipValidationResponse.state); } - this.navigateForward(carEntered, carsFound); + // store.commit(storeMutations.UPDATE_REGISTRATION_ADDRESS, this.customerQuestions.addressQuestions.streetAddress); + // store.commit(storeMutations.UPDATE_REGISTRATION_CITY, this.customerQuestions.addressQuestions.city); + // store.commit(storeMutations.UPDATE_REGISTRATION_STATE, this.customerQuestions.addressQuestions.state); + // store.commit(storeMutations.UPDATE_REGISTRATION_ZIP_CODE, this.customerQuestions.addressQuestions.zipCode); + // store.commit(storeMutations.UPDATE_REGISTRATION_FIRST_NAME, this.customerQuestions.firstName); + // store.commit(storeMutations.UPDATE_REGISTRATION_LAST_NAME, this.customerQuestions.lastName); + // store.commit(storeMutations.UPDATE_SERVICE_LOCATION_ZIP_CODE, this.serviceZipCode); + // store.commit(storeMutations.UPDATE_SERVICE_LOCATION_STATE, serviceState); + // store.commit(storeMutations.UPDATE_CUSTOMER_EMAIL_ADDRESS, this.customerQuestions.emailAddress); + + // Save vin, vehicle, customer, service and registration information + await this.dispatchStoreAction(storeActions.SAVE_REGISTRATION_LICENSE_PLATE_LOOKUP, { + isCarIdDifferent: this.isCarIdDifferent, + isSelectedGlassAvailableForVehicle: this.isSelectedGlassAvailableForVehicle, + vehicleInfo: Object.assign(vinLookup.data.vehicle, { vin: vinLookup.data.vin }), + serviceLocationInfo: { + zipCode: this.serviceZip, + state: resultMap.serviceZipValidationResponse.state, + }, + registrationInfo: { + licensePlate: this.licensePlate, + state: resultMap.registrationZipValidationResponse.state, + zipCode: this.registrationZip, + }, + customerEmail: this.email, + }, false); + + return await this.navigateForward(carEntered, vinsFound); }, - resetWarningsAndErrors() { - this.displayVinNotFoundAlert = false; - this.displayNonServiceableZipAlert = false; - this.displayMatchedDifferentVehicleAlert = false; - this.displayVinLookupByHomeAddressNotAllowedAlert = false; - }, - navigateForward(carEntered, carsFound) { + async navigateForward(carEntered, vinsFound) { this.updateServiceLocationIfNecessary(); - if (carsFound.length == 1) { + if (vinsFound.length == 1) { // if a different vehicle is found than the one entered and the selected glass // is not available for that vehicle if (this.isCarIdDifferent && !this.isSelectedGlassAvailableForVehicle) { @@ -298,11 +357,11 @@ export default { ); } else { // otherwise - this.navigateForwardWithSingleCarMatch(); + await this.navigateForwardWithSingleCarMatch(); } - } else if (carsFound.length > 1) { + } else if (vinsFound.length > 1) { // if multiple cars were found - let matchingCars = carsFound.filter(car => car.vehicle.carId === carEntered.carId); + let matchingCars = vinsFound.filter(car => car.vehicle.carId === carEntered.carId); if (matchingCars.length === 1) { // and one and only of them matches the car id entered const matchingCar = matchingCars[0]; @@ -310,39 +369,18 @@ export default { this.navigateForwardWithSingleCarMatch(); } else { // if there are no matches or there are multiple matches, navigate to "address-vehicles" page - this.$router.navigate(this.navigationScenarios.CONTINUING_WITH_MULTIPLE_VEHICLES, this.$route, {}, {}, carsFound); + this.$router.navigate(this.navigationScenarios.CONTINUING_WITH_MULTIPLE_VEHICLES, this.$route, {}, {}, vinsFound); } } }, - validateZip(zip) { - return this.dispatchStoreAction( - storeActions.VALIDATE_ZIP, - { zip }); - }, - lookupVin(lastName, streetAddress, zip, state) { - return this.dispatchStoreAction( - storeActions.LOOKUP_VIN_BY_ADDRESS, - { - licenseLastName: lastName, - licenseStreetAddress: streetAddress, - licenseZip: zip, - licenseState: state - }, false - ); - }, - updateVehicleInfo(vin, vehicleInfo) { - store.commit(storeMutations.UPDATE_VEHICLE_VIN, vin); - store.commit(storeMutations.UPDATE_YEAR, vehicleInfo.year); - store.commit(storeMutations.UPDATE_MAKE, vehicleInfo.make); - store.commit(storeMutations.UPDATE_MODEL, vehicleInfo.model); - store.commit(storeMutations.UPDATE_STYLE, vehicleInfo.style); - store.commit(storeMutations.UPDATE_CAR_ID, vehicleInfo.carId); - store.commit(storeMutations.UPDATE_VEHICLE_CATEGORY, vehicleInfo.category); - store.commit(storeMutations.UPDATE_VEHICLE_IMAGE_URL, vehicleInfo.imageUrl); - store.commit(storeMutations.UPDATE_VEHICLE_IMAGE_VIF_NUMBER, vehicleInfo.imageVifNumber); - store.commit(storeMutations.UPDATE_VEHICLE_IMAGE_COLOR, vehicleInfo.imageColor); + resetWarningsAndErrors() { + this.displayVinNotFoundAlert = false; + this.displayNonServiceableZipAlert = false; + this.displayMatchedDifferentVehicleAlert = false; + this.displayVinLookupByHomeAddressNotAllowedAlert = false; }, + updateCustomerInfo(serviceState) { store.commit(storeMutations.UPDATE_REGISTRATION_ADDRESS, this.customerQuestions.addressQuestions.streetAddress); store.commit(storeMutations.UPDATE_REGISTRATION_CITY, this.customerQuestions.addressQuestions.city); diff --git a/src/layouts/address-vehicles/address-vehicles.spec.js b/src/layouts/address-vehicles/address-vehicles.spec.js index fcccb1d94..8dcadae22 100644 --- a/src/layouts/address-vehicles/address-vehicles.spec.js +++ b/src/layouts/address-vehicles/address-vehicles.spec.js @@ -230,7 +230,7 @@ describe("addressVehicles.vue", () => { const { wrapper } = setupMocks({}); wrapper.vm.$refs.funnelFooter.updateButtonText = jest.fn(); wrapper.vm.$refs.loadingModal.showModal = jest.fn(); - navigateToHeritage.navigateAfterSaveToHeritageFunnel = jest.fn(); + navigateToHeritage.navigateToHeritageFunnel = jest.fn(); // Act await wrapper.setData({ diff --git a/src/layouts/license-plate-lookup/license-plate-lookup.spec.js b/src/layouts/license-plate-lookup/license-plate-lookup.spec.js index 3ae226fca..ea89df224 100644 --- a/src/layouts/license-plate-lookup/license-plate-lookup.spec.js +++ b/src/layouts/license-plate-lookup/license-plate-lookup.spec.js @@ -246,7 +246,7 @@ describe("license-plate-lookup.vue", () => { expect(wrapper.vm.$router.navigateAfterSave).toHaveBeenCalled(); }); - test("navigateAfterSaveToHeritageFunnel should be called if isCarIdDifferent is false or isSelectedGlassAvailableForVehicle is true when navigateForward is called", async () => { + test("navigateToHeritageFunnel should be called if isCarIdDifferent is false or isSelectedGlassAvailableForVehicle is true when navigateForward is called", async () => { // Arrange const { wrapper } = setupMocks({}); @@ -258,11 +258,11 @@ describe("license-plate-lookup.vue", () => { wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => { return ''; }); - navigateToHeritage.navigateAfterSaveToHeritageFunnel = jest.fn(); + navigateToHeritage.navigateToHeritageFunnel = jest.fn(); await wrapper.vm.navigateForward(); //Assert - expect(navigateToHeritage.navigateAfterSaveToHeritageFunnel).toHaveBeenCalled(); + expect(navigateToHeritage.navigateToHeritageFunnel).toHaveBeenCalled(); }); test("carId matches returned vehicle => navigateForwardWithSingleCarMatch", async () => { @@ -366,7 +366,7 @@ describe("license-plate-lookup.vue", () => { wrapper.vm.lookupVin = jest.fn().mockImplementation(() => new Promise(resolve => resolve(vinLookup))); await wrapper.setData({ registrationZip: "00000" }); - navigateToHeritage.navigateAfterSaveToHeritageFunnel = jest.fn(); + navigateToHeritage.navigateToHeritageFunnel = jest.fn(); // Act await wrapper.vm.forwardButtonAction(); @@ -385,7 +385,7 @@ describe("license-plate-lookup.vue", () => { }); await wrapper.setData({ registrationZip: "00000" }); - navigateToHeritage.navigateAfterSaveToHeritageFunnel = jest.fn(); + navigateToHeritage.navigateToHeritageFunnel = jest.fn(); // Act await wrapper.vm.forwardButtonAction(); @@ -404,7 +404,7 @@ describe("license-plate-lookup.vue", () => { }); await wrapper.setData({ registrationZip: "00000" }); - navigateToHeritage.navigateAfterSaveToHeritageFunnel = jest.fn(); + navigateToHeritage.navigateToHeritageFunnel = jest.fn(); await wrapper.vm.forwardButtonAction(); wrapper.vm.$router.navigateAfterSave = jest.fn(); // At this point, serviceZip field is shown @@ -417,7 +417,7 @@ describe("license-plate-lookup.vue", () => { const serviceZipField = wrapper.findComponent("[cmsWidgetName='ServiceZip']"); expect(serviceZipField.exists()).toBe(true); expect(serviceZipField.isVisible()).toBe(true); 3 - expect(navigateToHeritage.navigateAfterSaveToHeritageFunnel).not.toHaveBeenCalled(); + expect(navigateToHeritage.navigateToHeritageFunnel).not.toHaveBeenCalled(); expect(wrapper.vm.$router.navigateAfterSave).not.toHaveBeenCalled(); }); diff --git a/src/layouts/license-plate-lookup/license-plate-lookup.vue b/src/layouts/license-plate-lookup/license-plate-lookup.vue index dbce9f3fc..c92dda00b 100644 --- a/src/layouts/license-plate-lookup/license-plate-lookup.vue +++ b/src/layouts/license-plate-lookup/license-plate-lookup.vue @@ -50,13 +50,13 @@ class="my-3" :manualHeadline="NoServiceZipHeader" :manualCopy="NoServiceZipBody" - v-if="!isRegistrationZipServicable && isVinValid && !isCarIdDifferent" + v-if="!isRegistrationZipServiceable && isVinValid && !isCarIdDifferent" alertClass="alert-danger" />
{ - this.$refs.funnelFooter.removeLoader(); + const vinLookup = await this.dispatchStoreAction(storeActions.LOOKUP_VIN_BY_PLATE, + { licensePlate: this.licensePlate, licenseState: resultMap.registrationZipValidationResponse.state }, false) + .catch(() => { this.isVinValid = false; this.isCarIdDifferent = false; - return; + return this.$refs.funnelFooter.removeLoader(); }); - this.isCarIdDifferent = - vinLookup.data.vehicle.carId !== store.getters.vehicle.carId; + // Check if the CarId has changed. + this.isCarIdDifferent = vinLookup.data.vehicle.carId !== this.$store.getters.vehicle.carId; //Handle changing car - if ( - this.isCarIdDifferent && - vinLookup.data.vehicle.carId !== this.previouslyEnteredCarId - ) { + if (this.isCarIdDifferent && vinLookup.data.vehicle.carId !== this.previouslyEnteredCarId) { + this.isSelectedGlassAvailableForVehicle = await isGlassAvailableForCarId(vinLookup.data.vehicle.carId); + this.$refs.funnelFooter.updateButtonText(`Continue with ${vinLookup.data.vehicle.year} ${vinLookup.data.vehicle.make} ${vinLookup.data.vehicle.model}`); + this.previouslyEnteredCarId = vinLookup.data.vehicle.carId; this.customAlertData.vehicleInfo = vinLookup.data.vehicle; - this.$refs.funnelFooter.updateButtonText( - `Continue with ${vinLookup.data.vehicle.year} ${vinLookup.data.vehicle.make} ${vinLookup.data.vehicle.model}` - ); this.isVinValid = true; - this.isSelectedGlassAvailableForVehicle = await isGlassAvailableForCarId(vinLookup.data.vehicle.carId); - this.$refs.funnelFooter.removeLoader(); - return; + + return this.$refs.funnelFooter.removeLoader(); } - // Save vin and vehicle information - this.dispatchStoreAction(storeActions.SAVE_VIN_LOOKUP, { + // Save vin, vehicle, customer, service and registration information + await this.dispatchStoreAction(storeActions.SAVE_REGISTRATION_LICENSE_PLATE_LOOKUP, { isCarIdDifferent: this.isCarIdDifferent, isSelectedGlassAvailableForVehicle: this.isSelectedGlassAvailableForVehicle, - vehicleInfo: Object.assign(vinLookup.data.vehicle, { vin: vinLookup.data.vin}) - }); + vehicleInfo: Object.assign(vinLookup.data.vehicle, { vin: vinLookup.data.vin }), + serviceLocationInfo: { + zipCode: this.serviceZip, + state: resultMap.serviceZipValidationResponse.state, + }, + registrationInfo: { + licensePlate: this.licensePlate, + state: resultMap.registrationZipValidationResponse.state, + zipCode: this.registrationZip, + }, + customerEmail: this.email, + }, false); - - //Navigate - this.navigateForward(); + return await this.navigateForward(); }, - navigateForward() { + async navigateForward() { if (this.isCarIdDifferent && !this.isSelectedGlassAvailableForVehicle) { - this.$router.navigate( - this.navigationScenarios.CLICKED_FORWARD, - this.$route, - {}, - { displayVehicleChangeAlert: true }, - {} - ); - return; + this.$router.navigate(this.navigationScenarios.CLICKED_FORWARD,this.$route,{}, {[routerParams.DISPLAY_VEHICLE_CHANGE_ALERT]: true }); } else { - this.navigateForwardWithSingleCarMatch(); - return; + await this.navigateForwardWithSingleCarMatch(); } }, - validateZip(zip) { - return this.dispatchStoreAction(storeActions.VALIDATE_ZIP, { - zip, - }); - }, - lookupVin(plate, state) { - return this.dispatchStoreAction( - storeActions.LOOKUP_VIN_BY_PLATE, - { licensePlate: plate, licenseState: state }, - false - ); - }, }, watch: { licensePlate() { diff --git a/src/layouts/vin-lookup/vin-lookup.vue b/src/layouts/vin-lookup/vin-lookup.vue index 14850a1bc..24ddf2fdc 100644 --- a/src/layouts/vin-lookup/vin-lookup.vue +++ b/src/layouts/vin-lookup/vin-lookup.vue @@ -124,7 +124,6 @@ import loadingModal from '@/common-components/loading-modal/loading-modal.vue'; // Supporting files import { fetchCmsContentForPage } from "@/helpers/cms-content-helper"; import { settleAllPromises } from "@/helpers/layout-helper"; -import store from "@/store"; import { storeActions } from "@/constants/store-actions"; import { storeMutations } from "@/constants/store-mutations"; import { errorMessages } from "@/constants/error-messages"; @@ -133,6 +132,8 @@ import { required, regex } from "@/helpers/validation-rules"; import { Form, defineRule } from "vee-validate"; import { getFunnelCookie } from "@/helpers/heritage-integration/cookie-helper"; import { routerParams } from "@/router/router-constants/router-params"; + +import store from "@/store"; import vinPagesMixin from "@/mixins/vin-pages-mixin"; // DEFINE VALIDATION RULES @@ -243,13 +244,13 @@ export default { return store.getters.vehicle.carId !== null; }, getEmailFromStore(){ - return store.getters.order.customer.emailAddress; + return this.$store.getters.order.customer.emailAddress; }, getVinFromStore(){ - return store.getters.vehicle.vin; + return this.$store.getters.vehicle.vin; }, getZipFromStore(){ - return store.getters.order.serviceLocation.zipCode; + return this.$store.getters.order.serviceLocation.zipCode; }, attachCustomEvents() { this.prependActionToMethod(this, this.forwardButtonAction, () => { @@ -267,7 +268,7 @@ export default { } }, backButtonAction() { - if (store.getters.vehicle.vin) { + if (this.$store.getters.vehicle.vin) { this.$router.navigate(this.navigationScenarios.CLICKED_BACK_WITH_VIN, this.$route); } else { @@ -327,7 +328,7 @@ export default { } // Save vin, vehicle, customer and service information - this.dispatchStoreAction(storeActions.SAVE_VIN_LOOKUP, { + await this.dispatchStoreAction(storeActions.SAVE_VIN_LOOKUP, { isCarIdDifferent: this.isCarIdDifferent, isSelectedGlassAvailableForVehicle: this.isSelectedGlassAvailableForVehicle, vehicleInfo: Object.assign(resultMap.vehicleLookupResponse, { vin: this.vin }), @@ -338,7 +339,7 @@ export default { customerEmail: this.email, }, false); - this.navigateForward(); + return await this.navigateForward(); } // If a VIN has already been found. Validate the Service Zip (in case of changes) @@ -348,14 +349,14 @@ export default { if (zipValidationResponse.data.isServiceable) { // If the Service Zip entered is serviceable then save the Zip Info and Email Address and navigate forward - this.$store.commit(storeActions.UPDATE_SERVICE_LOCATION, { + await this.dispatchStoreAction(storeActions.SAVE_SERVICE_LOCATION, { zipCode: this.zip, state: zipValidationResponse.data.state - }); + }, false); - this.$store.commit(storeMutations.UPDATE_CUSTOMER_EMAIL_ADDRESS, this.email); - - this.navigateForward(); + await this.dispatchStoreAction(storeActions.SAVE_EMAIL, this.email, false); + + return await this.navigateForward(); } // If the Service Zip is NOT serviceable then show an alert @@ -363,11 +364,11 @@ export default { return this.$refs.funnelFooter.removeLoader(); }, - navigateForward(){ + async navigateForward(){ if (this.isCarIdDifferent && !this.isSelectedGlassAvailableForVehicle) { this.$router.navigate(this.navigationScenarios.SELECTED_VIN_HAS_MISMATCHED_GLASS, this.$route, {}, { [routerParams.DISPLAY_VEHICLE_CHANGE_ALERT]: true }); } else { - this.navigateForwardWithSingleCarMatch(); + await this.navigateForwardWithSingleCarMatch(); } }, setupUiForNonServiceableZip(zip) { diff --git a/src/mixins/vin-pages-mixin.js b/src/mixins/vin-pages-mixin.js index 383bcf237..fce96c980 100644 --- a/src/mixins/vin-pages-mixin.js +++ b/src/mixins/vin-pages-mixin.js @@ -1,7 +1,7 @@ import store from "@/store"; import { storeActions } from "@/constants/store-actions.js"; import { storeMutations } from "@/constants/store-mutations.js"; -import { navigateAfterSaveToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; +import { navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; export default { methods: { @@ -13,15 +13,15 @@ export default { const hasGlassLocationWithMultipleParts = partsOrQuestions.some(pq => pq.parts?.length > 1); if (hasPartsQuestions) { - this.$router.navigateAfterSave(this.navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, this.$route, {}, {}, result.data); + this.$router.navigate(this.navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, this.$route, {}, {}, result.data); } else if (hasGlassLocationWithMultipleParts) { - this.$router.navigateAfterSave(this.navigationScenarios.SELECTED_VIN_WITH_MULTIPLE_PARTS, this.$route, {}, {}, result.data); + this.$router.navigate(this.navigationScenarios.SELECTED_VIN_WITH_MULTIPLE_PARTS, this.$route, {}, {}, result.data); } else { store.commit(storeMutations.UPDATE_GLASS_PARTS, result.data); this.$refs.loadingModal.showModal(); - navigateAfterSaveToHeritageFunnel(this.$route); + navigateToHeritageFunnel(); } } } diff --git a/src/mixins/vin-pages-mixin.spec.js b/src/mixins/vin-pages-mixin.spec.js index aef929d52..b66cd3ea4 100644 --- a/src/mixins/vin-pages-mixin.spec.js +++ b/src/mixins/vin-pages-mixin.spec.js @@ -6,10 +6,10 @@ import { storeMutations } from "@/constants/store-mutations"; import { navigationScenarios } from "@/router/router-constants/navigation-scenarios"; import store from "@/store"; import loadingModal from '@/common-components/loading-modal/loading-modal.vue'; -import { navigateAfterSaveToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; +import { navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; jest.mock("@/helpers/heritage-integration/navigation-helper", () => ({ - navigateAfterSaveToHeritageFunnel: jest.fn() + navigateToHeritageFunnel: jest.fn() })); describe("vin-pages-mixin", () => { @@ -771,7 +771,7 @@ describe("vin-pages-mixin", () => { await wrapper.vm.navigateForwardWithSingleCarMatch(); // Assert - expect(navigateAfterSaveToHeritageFunnel).toHaveBeenCalledTimes(1); + expect(navigateToHeritageFunnel).toHaveBeenCalledTimes(1); }); test("multiple glass locations selected, each has one part and no part questions => go to heritage funnel", async () => { @@ -864,7 +864,7 @@ describe("vin-pages-mixin", () => { partsOrQuestions: partsOrQuestions }); - // wrapper.vm.navigateAfterSaveToHeritageFunnel = jest.fn(); + // wrapper.vm.navigateToHeritageFunnel = jest.fn(); store.commit = jest.fn(); // Act @@ -874,7 +874,7 @@ describe("vin-pages-mixin", () => { expect(store.commit).toHaveBeenCalledTimes(1); expect(store.commit).toHaveBeenCalledWith(storeMutations.UPDATE_GLASS_PARTS, { partsOrQuestions }) expect(wrapper.vm.$refs.loadingModal.showModal).toHaveBeenCalledTimes(1); - expect(navigateAfterSaveToHeritageFunnel).toHaveBeenCalledTimes(1); + expect(navigateToHeritageFunnel).toHaveBeenCalledTimes(1); }); }); }); diff --git a/src/store/index.js b/src/store/index.js index 1481e25cf..e3b5a00bc 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -653,6 +653,7 @@ export const actions = { // Business domain actions + // Vehicle domain saveVehicleYear(context, year) { //Reset dependent state when changing @@ -750,10 +751,29 @@ export const actions = { context.commit(storeMutations.UPDATE_GLASS_TO_REPLACE, selectedGlassToReplace); } }, - saveVinLookup(context, { isCarIdDifferent, isSelectedGlassAvailableForVehicle, vehicleInfo, registrationInfo, serviceLocationInfo, customerEmail }) { + // Vin domain + saveVinLookup(context, { isCarIdDifferent, isSelectedGlassAvailableForVehicle, vehicleInfo, registrationInfo, serviceLocationInfo, customerEmail }) { //Reset dependent state when changing - if (registrationInfo?.licensePlate !== context.state.order.registration?.licensePlate) { + if (vehicleInfo.vin !== context.state.order.vehicle.vin) { + + context.dispatch(storeActions.RESET_REGISTRATION_STATE_AND_DEPENDENCIES); + + if (isCarIdDifferent && !isSelectedGlassAvailableForVehicle) { + context.dispatch(storeActions.RESET_DAMAGE_STATE_AND_DEPENDENCIES); + } + } + + //Save new values + context.dispatch(storeActions.SAVE_EMAIL, customerEmail); + context.dispatch(storeActions.SAVE_SERVICE_LOCATION, serviceLocationInfo); + + context.commit(storeMutations.UPDATE_VEHICLE, vehicleInfo); + context.commit(storeMutations.UPDATE_REGISTRATION, registrationInfo); + }, + saveRegistrationLicensePlateLookup(context, { isCarIdDifferent, isSelectedGlassAvailableForVehicle, vehicleInfo, registrationInfo, serviceLocationInfo, customerEmail }) { + //Reset dependent state when changing + if (registrationInfo?.licensePlate !== context.state.order.vehicle.registration?.licensePlate) { context.dispatch(storeActions.RESET_REGISTRATION_STATE_AND_DEPENDENCIES); @@ -765,57 +785,35 @@ export const actions = { //Save new values context.commit(storeMutations.UPDATE_VEHICLE, vehicleInfo); context.commit(storeMutations.UPDATE_REGISTRATION, registrationInfo); - context.commit(storeMutations.UPDATE_CUSTOMER_EMAIL_ADDRESS, customerEmail); + + context.dispatch(storeActions.SAVE_EMAIL, customerEmail); + context.dispatch(storeActions.SAVE_SERVICE_LOCATION, serviceLocationInfo); + }, + saveRegistrationAddressLookup(context, { isCarIdDifferent, isSelectedGlassAvailableForVehicle, vehicleInfo, registrationInfo, serviceLocationInfo, customerEmail}) { + //Reset dependent state when changing + if (registrationInfo?.address !== context.state.order.vehicle.registration?.address || registrationInfo?.city !== context.state.order.vehicle.registration?.city || registrationInfo?.state !== context.state.order.vehicle.registration?.state || registrationInfo?.zipCode !== context.state.order.vehicle.registration?.zipCode || registrationInfo?.firstName !== context.state.order.vehicle.registration?.firstName || registrationInfo?.lastName !== context.state.order.vehicle.registration?.lastName) { + + context.dispatch(storeActions.RESET_REGISTRATION_STATE_AND_DEPENDENCIES); + + if (isCarIdDifferent && !isSelectedGlassAvailableForVehicle) { + context.dispatch(storeActions.RESET_DAMAGE_STATE_AND_DEPENDENCIES); + } + } + + //Save new values + context.commit(storeMutations.UPDATE_VEHICLE, vehicleInfo); + context.commit(storeMutations.UPDATE_REGISTRATION, registrationInfo); + + context.dispatch(storeActions.SAVE_EMAIL, customerEmail); + context.dispatch(storeActions.SAVE_SERVICE_LOCATION, serviceLocationInfo); + }, + + + saveServiceLocation(context, serviceLocationInfo) { context.commit(storeMutations.UPDATE_SERVICE_LOCATION, serviceLocationInfo); }, - - saveRegistrationLicensePlateLookup(context, { registrationInfo, serviceState, serviceZip, customerEmail, vehicleInfo, isCarIdDifferent, isSelectedGlassAvailableForVehicle }) { - - if (registrationInfo.licensePlate !== context.state.order.registration.licensePlate || registrationInfo.zipcode !== context.state.order.registration.zipcode) { - - //Reset dependent state when changing - if (isCarIdDifferent && !isSelectedGlassAvailableForVehicle) { - context.dispatch(storeMutations.RESET_DAMAGE_STATE_AND_DEPENDENCIES); - } - - context.commit(storeMutations.UPDATE_REGISTRATION_ADDRESS, null); - context.commit(storeMutations.UPDATE_REGISTRATION_CITY, null); - context.commit(storeMutations.UPDATE_REGISTRATION_FIRST_NAME, null); - context.commit(storeMutations.UPDATE_REGISTRATION_LAST_NAME, null); - - //Save new values - context.dispatch(storeActions.SAVE_VIN_LOOKUP, { isCarIdDifferent, isSelectedGlassAvailableForVehicle, vehicleInfo }); - - context.commit(storeMutations.UPDATE_REGISTRATION_LICENSE_PLATE, registrationInfo.licensePlate); - context.commit(storeMutations.UPDATE_REGISTRATION_STATE, registrationInfo.state); - context.commit(storeMutations.UPDATE_REGISTRATION_ZIP_CODE, registrationInfo.zipCode); - - context.dispatch(storeActions.SAVE_SERVICE_ZIP, serviceZip); - context.dispatch(storeActions.SAVE_SERVICE_STATE, serviceState); - context.dispatch(storeActions.SAVE_EMAIL, customerEmail); - } - }, - saveRegistrationAddressLookup(context, { licensePlate }) { - - - if (context.isCarIdDifferent && !context.isSelectedGlassAvailableForVehicle) { - storeMutations.RESET_DAMAGE_STATE_AND_DEPENDENCIES; - } - context.commit(storeMutations.UPDATE_REGISTRATION_ADDRESS, null); - context.commit(storeMutations.UPDATE_REGISTRATION_CITY, null); - context.commit(storeMutations.UPDATE_REGISTRATION_FIRST_NAME, null); - context.commit(storeMutations.UPDATE_REGISTRATION_LAST_NAME, null); - }, - saveServiceLocation(context, { zipcode, state }) { - if (zipcode !== context.state.order.service.zipcode || state !== context.state.order.service.state) { - context.commit(storeMutations.UPDATE_SERVICE_LOCATION_ZIP_CODE, zipcode); - context.commit(storeMutations.UPDATE_CUSTOMER_EMAIL_ADDRESS, state); - } - }, saveEmail(context, email) { - if (email !== context.state.order.customer.email) { - context.commit(storeMutations.UPDATE_CUSTOM, email); - } + context.commit(storeMutations.UPDATE_CUSTOMER_EMAIL_ADDRESS, email); }, saveVin(context, { isCarIdDifferent, isSelectedGlassAvailableForVehicle, vehicleInfo }) {