From 2e12fb3c90c6da7e79db3f0317610c162f80165e Mon Sep 17 00:00:00 2001 From: hiteshkumar87 Date: Tue, 25 Jun 2024 18:26:02 +0530 Subject: [PATCH] CSR-2087 Custom query strings --- src/constants/query-strings.js | 8 ++ src/constants/store-actions.js | 1 + src/constants/store-mutations.js | 1 + src/layouts/estimate/estimate.spec.js | 27 ++++ src/layouts/estimate/estimate.vue | 7 + .../insurance-company/insurance-company.vue | 4 + src/layouts/part-questions/part-questions.vue | 6 + src/layouts/quote/quote.spec.js | 112 ++++++++++++++- src/layouts/quote/quote.vue | 11 ++ src/layouts/service-zip/service-zip.spec.js | 56 +++++++- src/layouts/service-zip/service-zip.vue | 24 +++- .../vehicle-damage/vehicle-damage.spec.js | 53 ++++++++ src/layouts/vehicle-damage/vehicle-damage.vue | 11 ++ src/layouts/vehicle/vehicle.spec.js | 128 ++++++++++++++++-- src/layouts/vehicle/vehicle.vue | 14 +- src/mixins/base-mixin.js | 4 + src/router/index.js | 75 +++++++++- src/store/index.js | 17 ++- 18 files changed, 537 insertions(+), 22 deletions(-) diff --git a/src/constants/query-strings.js b/src/constants/query-strings.js index 76411c542..a3b3c732c 100644 --- a/src/constants/query-strings.js +++ b/src/constants/query-strings.js @@ -25,6 +25,14 @@ const queryStrings = { REFERRAL_NUMBER: "rn", PARENT_ACCOUNT: "pa", CORRELATION_ID: "ci", + VEHICLE_YEAR: "vehicleyear", + VEHICLE_MAKE: "vehiclemake", + VEHICLE_MODEL: "vehiclemodel", + VEHICLE_STYLE: "vehiclestyle", + VEHICLE_DAMAGE: "vehicledamage", + SERVICE_ZIP: "servicezip", + EMAIL: "email", + IS_INSURANCE: "isinsurance", }; export { queryStrings }; diff --git a/src/constants/store-actions.js b/src/constants/store-actions.js index bd772cafe..0001daf6a 100644 --- a/src/constants/store-actions.js +++ b/src/constants/store-actions.js @@ -96,6 +96,7 @@ const storeActions = { CREATE_SUBMITTED_ORDER: "createSubmittedOrder", RESET_SUBMITTED_ORDER: "resetSubmittedOrder", + RESET_IS_LEAD_GEN: "resetIsLeadGen", }; export { storeActions }; diff --git a/src/constants/store-mutations.js b/src/constants/store-mutations.js index 8d23f50ab..f78b970c3 100644 --- a/src/constants/store-mutations.js +++ b/src/constants/store-mutations.js @@ -60,6 +60,7 @@ const storeMutations = { Customer_Portal_Login_Token: "updateCustomerPortalLoginToken", LOCK_TOKEN: "updateLockToken", UPDATE_SETTLED_TENDER_AMOUNT: "updateSettledTenderAmount", + UPDATE_IS_LEAD_GEN: "updateIsLeadGen", // EVENT BUS MUTATIONS ADD_EVENT_TO_BUS: "addEventToBus", diff --git a/src/layouts/estimate/estimate.spec.js b/src/layouts/estimate/estimate.spec.js index a81ead0c3..14752e171 100644 --- a/src/layouts/estimate/estimate.spec.js +++ b/src/layouts/estimate/estimate.spec.js @@ -212,6 +212,33 @@ describe("estimate.vue", () => { }); }); +describe("estimate.vue", () => { + test("should call forwardButtonAction if isLeadGen is true", async () => { + // update store with isLeadGen as true + store.commit(storeMutations.UPDATE_IS_LEAD_GEN, true); + + // Set up the component + const { wrapper } = setupMocks({}); + wrapper.vm.forwardButtonAction = jest.fn(); + const nextFunction = jest.fn((c) => { + c(wrapper.vm); + }); + + // Set selectedVinLookupMethod to decline + wrapper.setData({ selectedVinLookupMethod: vinLookupMethodSelections.DECLINE }); + + // Call the method that contains the if-else logic + await estimate.beforeRouteEnter.call( + wrapper.vm, + { query: { fmgPage: "estimate" } }, + undefined, + nextFunction + ); + expect(nextFunction).toHaveBeenCalled(); + expect(wrapper.vm.forwardButtonAction).toHaveBeenCalled(); + }); +}); + function setupMocks({ groupName = "estimate", skipVin = false, diff --git a/src/layouts/estimate/estimate.vue b/src/layouts/estimate/estimate.vue index 4f7c44cdd..913520626 100644 --- a/src/layouts/estimate/estimate.vue +++ b/src/layouts/estimate/estimate.vue @@ -145,6 +145,13 @@ export default { } vm.setCmsContent(resultMap.cmsContent); + if (store.getters.isLeadGen) { + vm.selectedVinLookupMethod = vinLookupMethodSelections.DECLINE; + vm.forwardButtonAction(); + } else { + baseMixin.methods.dispatchStoreAction(storeActions.RESET_IS_LEAD_GEN); + baseMixin.methods.hideFmgLoadingModal(); + } }); }, methods: { diff --git a/src/layouts/insurance-company/insurance-company.vue b/src/layouts/insurance-company/insurance-company.vue index a15de8311..8cdec3afa 100644 --- a/src/layouts/insurance-company/insurance-company.vue +++ b/src/layouts/insurance-company/insurance-company.vue @@ -76,6 +76,10 @@ export default { next((vm) => { vm.setCmsContent(resultMap.cmsContent); vm.originalList = resultMap.insuranceCompanyList; + if (store.getters.isLeadGen) { + baseMixin.methods.dispatchStoreAction(storeActions.RESET_IS_LEAD_GEN); + baseMixin.methods.hideFmgLoadingModal(); + } }); }, data() { diff --git a/src/layouts/part-questions/part-questions.vue b/src/layouts/part-questions/part-questions.vue index 9f4a13902..9249a5a57 100644 --- a/src/layouts/part-questions/part-questions.vue +++ b/src/layouts/part-questions/part-questions.vue @@ -29,6 +29,8 @@ import { Form, defineRule } from "vee-validate"; import { required } from "@/helpers/validation-rules"; import { errorMessages } from "@/constants/error-messages"; import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin"; +import baseMixin from "@/mixins/base-mixin.js"; +import { storeActions } from "@/constants/store-actions"; // DEFINE VALIDATION RULES defineRule("questions-required", required(errorMessages.OPTION_REQUIRED)); @@ -53,6 +55,10 @@ export default { // Call the "next" function to complete the transition to this page. next((vm) => { vm.setCmsContent(resultMap.cmsContent); + if (store.getters.isLeadGen) { + baseMixin.methods.dispatchStoreAction(storeActions.RESET_IS_LEAD_GEN); + baseMixin.methods.hideFmgLoadingModal(); + } }); }, data() { diff --git a/src/layouts/quote/quote.spec.js b/src/layouts/quote/quote.spec.js index b54f5d0fb..9fd4153f7 100644 --- a/src/layouts/quote/quote.spec.js +++ b/src/layouts/quote/quote.spec.js @@ -640,12 +640,122 @@ describe("quote.vue", () => { ); }); }); +describe("quote.vue", () => { + test("should call forwardButtonAction if isLeadGen is true and Insurance is true", async () => { + // Set up the store with isLeadGen as true + + store.getters = { + lineItems: { + glassParts: ["item", "item2"], + }, + order: { + lineItems: { + glassParts: ["item", "item2"], + }, + serviceLocation: { + zipCode: "12345", + zipCodeCtu: "value", + }, + damage: { + isRepair: false, + }, + referralNumber: "1234567", + payment: { + isInsurance: true, + inactivePromos: [], + }, + }, + isLeadGen: true, + payment: { + isInsurance: true, + inactivePromos: [], + }, + vehicle: { + cardId: "123", + }, + experimentSettings: { + settingName: "SERVICE_PACKAGE_DISCOUNT", + }, + }; + + // Set up the component + const { wrapper } = setupMocks({}); + wrapper.vm.$route = { query: null }; + wrapper.vm.forwardButtonAction = jest.fn(); + const nextFunction = jest.fn((c) => { + c(wrapper.vm); + }); + + // Call the method that contains the if-else logic + await quote.beforeRouteEnter.call( + wrapper.vm, + { query: { fmgPage: "quote" } }, + undefined, + nextFunction + ); + expect(nextFunction).toHaveBeenCalled(); + expect(wrapper.vm.forwardButtonAction).toHaveBeenCalled(); + }); + test("should not call forwardButtonAction if isLeadGen is true and Insurance is false", async () => { + // Set up the store with isLeadGen as true + store.getters = { + lineItems: { + glassParts: ["item", "item2"], + }, + order: { + lineItems: { + glassParts: ["item", "item2"], + }, + serviceLocation: { + zipCode: "12345", + zipCodeCtu: "value", + }, + damage: { + isRepair: false, + }, + referralNumber: "1234567", + payment: { + isInsurance: null, + inactivePromos: [], + }, + }, + isLeadGen: true, + payment: { + isInsurance: null, + inactivePromos: [], + }, + vehicle: { + cardId: "123", + }, + experimentSettings: { + settingName: "SERVICE_PACKAGE_DISCOUNT", + }, + }; + + // Set up the component + const { wrapper } = setupMocks({}); + wrapper.vm.$route = { query: null }; + wrapper.vm.forwardButtonAction = jest.fn(); + const nextFunction = jest.fn((c) => { + c(wrapper.vm); + }); + + // Call the method that contains the if-else logic + await quote.beforeRouteEnter.call( + wrapper.vm, + { query: { fmgPage: "quote" } }, + undefined, + nextFunction + ); + expect(wrapper.vm.forwardButtonAction).not.toHaveBeenCalled(); + }); +}); function setupMocks({ customMountOptions }) { const mountOptions = getMountOptions({ ...customMountOptions, }); - + baseMixin.methods.hideFmgLoadingModal = jest.fn(); mountOptions.global.mocks["$store"] = store; mountOptions["attachTo"] = document.body; diff --git a/src/layouts/quote/quote.vue b/src/layouts/quote/quote.vue index 93c2cecb6..4477d4d0f 100644 --- a/src/layouts/quote/quote.vue +++ b/src/layouts/quote/quote.vue @@ -252,6 +252,17 @@ export default { validateAlerts[0].shouldAutoFade ); } + if (store.getters.isLeadGen) { + if (store.getters.order.payment.isInsurance == true) { + vm.forwardButtonAction(); + } else { + baseMixin.methods.dispatchStoreAction(storeActions.RESET_IS_LEAD_GEN); + baseMixin.methods.hideFmgLoadingModal(); + } + } else { + baseMixin.methods.dispatchStoreAction(storeActions.RESET_IS_LEAD_GEN); + baseMixin.methods.hideFmgLoadingModal(); + } }); }, data() { diff --git a/src/layouts/service-zip/service-zip.spec.js b/src/layouts/service-zip/service-zip.spec.js index 5341f2b8a..6b1597da7 100644 --- a/src/layouts/service-zip/service-zip.spec.js +++ b/src/layouts/service-zip/service-zip.spec.js @@ -390,12 +390,66 @@ describe("service-zip.vue", () => { }); }); +describe("service-zip.vue", () => { + test("should call forwardButtonAction if isLeadGen is true and form is valid", async () => { + // Set up the store with isLeadGen as true + store.getters.isLeadGen = true; + + // Set up the component + const wrapper = setupMocks({}); + wrapper.vm.forwardButtonAction = jest.fn(); + const nextFunction = jest.fn((c) => { + c(wrapper.vm); + }); + + // Mock the isFormValid method + wrapper.vm.isFormValid = jest.fn().mockImplementation(() => { + return true; + }); + + // Call the method that contains the if-else logic + await serviceZip.beforeRouteEnter.call( + wrapper.vm, + { query: { fmgPage: "service-zip" } }, + undefined, + nextFunction + ); + expect(nextFunction).toHaveBeenCalled(); + expect(wrapper.vm.forwardButtonAction).toHaveBeenCalled(); + }); + test("should not call forwardButtonAction if isLeadGen is true and form is invalid", async () => { + // Set up the store with isLeadGen as true + store.getters.isLeadGen = true; + + // Set up the component + const wrapper = setupMocks({}); + wrapper.vm.forwardButtonAction = jest.fn(); + const nextFunction = jest.fn((c) => { + c(wrapper.vm); + }); + + // Mock the isFormValid method + wrapper.vm.isFormValid = jest.fn().mockImplementation(() => { + return false; + }); + + // Call the method that contains the if-else logic + await serviceZip.beforeRouteEnter.call( + wrapper.vm, + { query: { fmgPage: "service-zip" } }, + undefined, + nextFunction + ); + expect(wrapper.vm.forwardButtonAction).not.toHaveBeenCalled(); + }); +}); + function setupMocks({ customMountOptions, customZipQuery, customZipDataResponse }) { const route = { query: { fmgPage: "service-zip" }, params: {} }; if (customZipQuery) { route.query.zipcode = customZipQuery; } - + baseMixin.methods.hideFmgLoadingModal = jest.fn(); const mountOptions = getMountOptions({ ...customMountOptions, route: route, diff --git a/src/layouts/service-zip/service-zip.vue b/src/layouts/service-zip/service-zip.vue index e0bb3730b..ac2cd2905 100644 --- a/src/layouts/service-zip/service-zip.vue +++ b/src/layouts/service-zip/service-zip.vue @@ -131,8 +131,17 @@ export default { const resultMap = await settleAllPromises(promiseResultMap); - next((vm) => { + next(async (vm) => { vm.setCmsContent(resultMap.cmsContent); + if (store.getters.isLeadGen) { + const isValid = await vm.isFormValid(); + if (isValid) { + vm.forwardButtonAction(); + } else { + baseMixin.methods.dispatchStoreAction(storeActions.RESET_IS_LEAD_GEN); + baseMixin.methods.hideFmgLoadingModal(); + } + } }); }, methods: { @@ -175,12 +184,20 @@ export default { if (!zipCodeData.isValid) { this.displayInvalidZipAlert = true; + if (store.getters.isLeadGen) { + baseMixin.methods.dispatchStoreAction(storeActions.RESET_IS_LEAD_GEN); + baseMixin.methods.hideFmgLoadingModal(); + } return this.$refs.navbar.removeLoader(); } this.displayInvalidZipAlert = false; if (!zipCodeData.isServiceable) { this.displayNonServiceableZipAlert = true; + if (store.getters.isLeadGen) { + baseMixin.methods.dispatchStoreAction(storeActions.RESET_IS_LEAD_GEN); + baseMixin.methods.hideFmgLoadingModal(); + } return this.$refs.navbar.removeLoader(); } this.displayNonServiceableZipAlert = false; @@ -233,6 +250,11 @@ export default { await this.navigateForwardWithSingleCarMatch(); } }, + async isFormValid() { + const form = this.$refs.theForm; + const formValidateResponse = await form.validate(); + return formValidateResponse?.valid; + }, }, computed: { AlertNonServiceableZipHeader() { diff --git a/src/layouts/vehicle-damage/vehicle-damage.spec.js b/src/layouts/vehicle-damage/vehicle-damage.spec.js index e0450fd80..2bb761d5d 100644 --- a/src/layouts/vehicle-damage/vehicle-damage.spec.js +++ b/src/layouts/vehicle-damage/vehicle-damage.spec.js @@ -66,6 +66,7 @@ jest.mock("@/store", () => ({ glassToReplace: [], }, }, + isLeadGen: false, }, })); @@ -760,6 +761,56 @@ describe("vehicle-damage.vue", () => { expect(wrapper.vm.shouldHideBackButton).toBeFalsy(); }); }); + + describe("vehicle-damage.vue", () => { + test("should call forwardButtonAction if isLeadGen is true and selectedDamageLocations is not empty", async () => { + // Set up the store with isLeadGen as true + store.getters.isLeadGen = true; + + // Set up the component + const { wrapper } = setupMocks({}); + wrapper.vm.forwardButtonAction = jest.fn(); + const nextFunction = jest.fn((c) => { + c(wrapper.vm); + }); + + // Set selectedDamageLocations + wrapper.setData({ selectedDamageLocations: ["windshield"] }); + + // Call the method that contains the if-else logic + await vehicleDamage.beforeRouteEnter.call( + wrapper.vm, + { query: { fmgPage: "vehicle-damage" } }, + undefined, + nextFunction + ); + expect(nextFunction).toHaveBeenCalled(); + expect(wrapper.vm.forwardButtonAction).toHaveBeenCalled(); + }); + test("should not call forwardButtonAction if isLeadGen is true and selectedDamageLocations is empty", async () => { + // Set up the store with isLeadGen as true + store.getters.isLeadGen = true; + + // Set up the component + const { wrapper } = setupMocks({}); + wrapper.vm.forwardButtonAction = jest.fn(); + const nextFunction = jest.fn((c) => { + c(wrapper.vm); + }); + + // Set selectedDamageLocations to empty + wrapper.setData({ selectedDamageLocations: [] }); + + // Call the method that contains the if-else logic + await vehicleDamage.beforeRouteEnter.call( + wrapper.vm, + { query: { fmgPage: "vehicle-damage" } }, + undefined, + nextFunction + ); + expect(wrapper.vm.forwardButtonAction).not.toHaveBeenCalled(); + }); + }); }); function setupMocks({ pageHeaderWidgetHeaderText, mountOptionsMockData, funnelCookie = {} }) { @@ -783,6 +834,7 @@ function setupMocks({ pageHeaderWidgetHeaderText, mountOptionsMockData, funnelCo isVerified: false, }, }, + isLeadGen: false, }, }, }; @@ -795,6 +847,7 @@ function setupMocks({ pageHeaderWidgetHeaderText, mountOptionsMockData, funnelCo //Mock api responses baseMixin.methods.dispatchStoreAction = jest.fn(); baseMixin.methods.dispatchStoreActionWithLogging = jest.fn(); + baseMixin.methods.hideFmgLoadingModal = jest.fn(); const apiResponses = { cmsContent: { FunnelSubHeaderWidget: pageHeaderWidgetHeaderText, diff --git a/src/layouts/vehicle-damage/vehicle-damage.vue b/src/layouts/vehicle-damage/vehicle-damage.vue index 20125506d..602960931 100644 --- a/src/layouts/vehicle-damage/vehicle-damage.vue +++ b/src/layouts/vehicle-damage/vehicle-damage.vue @@ -149,6 +149,17 @@ export default { vm.$refs.backGlassOptions.initializeComponent( resultMap.damageOptions.backGlassOptions.availableReplacementOptions ); + if (store.getters.isLeadGen) { + if (vm.selectedDamageLocations?.length > 0) { + vm.forwardButtonAction(); + } else { + baseMixin.methods.dispatchStoreAction(storeActions.RESET_IS_LEAD_GEN); + baseMixin.methods.hideFmgLoadingModal(); + } + } else { + baseMixin.methods.dispatchStoreAction(storeActions.RESET_IS_LEAD_GEN); + baseMixin.methods.hideFmgLoadingModal(); + } }); }, data() { diff --git a/src/layouts/vehicle/vehicle.spec.js b/src/layouts/vehicle/vehicle.spec.js index 99f96564d..0d34a9bf7 100644 --- a/src/layouts/vehicle/vehicle.spec.js +++ b/src/layouts/vehicle/vehicle.spec.js @@ -2,11 +2,13 @@ import vehicle from "@/layouts/vehicle/vehicle.vue"; // Supporting Files +import store from "@/store"; import { shallowMount } from "@vue/test-utils"; import { nextTick } from "vue"; import { getMountOptions } from "@/helpers/unit-test-helper.js"; import { fetchCmsContentForPage } from "@/helpers/cms-content-helper"; import baseMixin from "../../mixins/base-mixin"; +import { settleAllPromises } from "@/helpers/layout-helper.js"; // Mock our module for promises. jest.mock("@/helpers/layout-helper.js", () => ({ @@ -18,6 +20,32 @@ jest.mock("@/helpers/cms-content-helper", () => ({ fetchCmsContentForPage: jest.fn(), })); +// Mock Store +jest.mock("@/store", () => ({ + commit: jest.fn(), + dispatch: jest.fn(), + getters: { + applicationUser: { + experiments: [{ universeName: "ConceptFunnel" }], + }, + isLeadGen: false, + vehicle: { + carId: "C00000000", + image: "test.jpg", + }, + order: { + vehicle: { + year: 2018, + make: "Honda", + model: "Accord", + style: "4 door sedan", + carId: "C00000000", + image: "test.jpg", + }, + }, + }, +})); + describe("vehicle.vue", () => { test("arePagePrerequisitesValid should be true ", async () => { //Arrange @@ -58,25 +86,101 @@ describe("vehicle.vue", () => { }); }); -function setupMocks() { - const mountOptions = getMountOptions({ - router: { - navigate: jest.fn(), - navigate: jest.fn(), - navigateWithSaving: jest.fn(), - navigateWithoutSaving: jest.fn(), - }, - }); +describe("vehicle.vue", () => { + test("should call forwardButtonAction if isLeadGen is true and displayNoServiceAlert is false", async () => { + // Set up the store with isLeadGen as true + store.getters.isLeadGen = true; + // Set up the component + const { wrapper } = setupMocks(); + wrapper.vm.forwardButtonAction = jest.fn(); + const nextFunction = jest.fn((c) => { + c(wrapper.vm); + }); + + // Set displayNoServiceAlert to false + wrapper.setData({ displayNoServiceAlert: false }); + + // Mock the getVehicleDetails method + wrapper.vm.getVehicleDetails = jest.fn(); + + // Call the method that contains the if-else logic + await vehicle.beforeRouteEnter.call( + wrapper.vm, + { query: { fmgPage: "vehicle" } }, + undefined, + nextFunction + ); + expect(nextFunction).toHaveBeenCalled(); + expect(wrapper.vm.forwardButtonAction).toHaveBeenCalled(); + }); + test("should not call forwardButtonAction if isLeadGen is true and displayNoServiceAlert is true", async () => { + // Set up the store with isLeadGen as true + store.getters.isLeadGen = true; + + // Set up the component + const { wrapper } = setupMocks(); + wrapper.vm.forwardButtonAction = jest.fn(); + const nextFunction = jest.fn((c) => { + c(wrapper.vm); + }); + + // Set displayNoServiceAlert to false + wrapper.setData({ displayNoServiceAlert: true }); + + // Mock the getVehicleDetails method + wrapper.vm.getVehicleDetails = jest.fn(); + + // Call the method that contains the if-else logic + await vehicle.beforeRouteEnter.call( + wrapper.vm, + { query: { fmgPage: "vehicle" } }, + undefined, + nextFunction + ); + expect(wrapper.vm.forwardButtonAction).not.toHaveBeenCalled(); + }); +}); + +function setupMocks() { + const groupName = "vehicle"; + const cmsQuestionText = "Vehicle Year"; + const cmsAnswers = [{ Name: "Vehicle year" }]; + const FunnelFooterWidget = { ForwardButtonText: "vehicle button" }; + + //Mock CMS Content + const cmsContent = { + groupName: groupName, + QuestionText: cmsQuestionText, + Answers: cmsAnswers, + FunnelFooterWidget: FunnelFooterWidget, + }; //Mock props const mockMixin = { methods: { getCmsContent: jest.fn(), }, }; + const mountOptionsMockData = { + router: { + navigate: jest.fn(), + navigateWithSaving: jest.fn(), + navigateWithoutSaving: jest.fn(), + }, + route: { + query: {}, + }, + }; + const apiPromise = Promise.resolve({ cmsContent }); + settleAllPromises.mockImplementation(() => apiPromise); + + const mountOptions = getMountOptions({ + ...mountOptionsMockData, + mixins: [baseMixin, mockMixin], + }); + mountOptions["attachTo"] = document.body; - mountOptions.mixins = [mockMixin]; const wrapper = shallowMount(vehicle, mountOptions); - - return { wrapper }; + wrapper.vm.isDisabled = jest.fn(); + return { wrapper, apiPromise }; } diff --git a/src/layouts/vehicle/vehicle.vue b/src/layouts/vehicle/vehicle.vue index 82dc54f22..2b9b02863 100644 --- a/src/layouts/vehicle/vehicle.vue +++ b/src/layouts/vehicle/vehicle.vue @@ -218,7 +218,7 @@ export default { let resultMap = await settleAllPromises(promiseResultMap); // Call the "next" function to complete the transition to this page. - next((vm) => { + next(async (vm) => { vm.setCmsContent(resultMap.cmsContent); vm.initializeYearComponent(resultMap.yearQuestionInitialData); @@ -232,6 +232,18 @@ export default { resultMap.modelQuestionInitialData, resultMap.styleQuestionInitialData ); + if (store.getters.isLeadGen) { + await vm.getVehicleDetails(); + if (!vm.displayNoServiceAlert) { + vm.forwardButtonAction(); + } else { + baseMixin.methods.dispatchStoreAction(storeActions.RESET_IS_LEAD_GEN); + baseMixin.methods.hideFmgLoadingModal(); + } + } else { + baseMixin.methods.dispatchStoreAction(storeActions.RESET_IS_LEAD_GEN); + baseMixin.methods.hideFmgLoadingModal(); + } }); }, diff --git a/src/mixins/base-mixin.js b/src/mixins/base-mixin.js index f01b0fe1f..90a6a7838 100644 --- a/src/mixins/base-mixin.js +++ b/src/mixins/base-mixin.js @@ -7,6 +7,7 @@ import { routerParams } from "@/router/router-constants/router-params"; import { queryStrings } from "@/constants/query-strings"; import { dynamicStrings } from "@/constants/dynamic-strings"; import { partTypeStrings } from "../constants/part-type-strings"; +import { showFmgLoadingModal } from "@/helpers/loading-modal-helper"; export default { data() { @@ -192,6 +193,9 @@ export default { const container = document.getElementsByClassName("page-container-grouped-styles")[0]; container.scrollTo({ top: container.scrollHeight, left: 0, behavior: "smooth" }); }, + hideFmgLoadingModal() { + showFmgLoadingModal(false); + }, }, computed: { storeActions() { diff --git a/src/router/index.js b/src/router/index.js index 2ce833135..db28a5ef1 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -84,6 +84,14 @@ const routes = [ ); const parentAccount = getQuerystringParameter(queryStrings.PARENT_ACCOUNT); const correlationId = getQuerystringParameter(queryStrings.CORRELATION_ID); + const vehicleYear = getQuerystringParameter(queryStrings.VEHICLE_YEAR); + const vehicleMake = getQuerystringParameter(queryStrings.VEHICLE_MAKE); + const vehicleModel = getQuerystringParameter(queryStrings.VEHICLE_MODEL); + const vehicleStyle = getQuerystringParameter(queryStrings.VEHICLE_STYLE); + const vehicleDamage = getQuerystringParameter(queryStrings.VEHICLE_DAMAGE); + const serviceZip = getQuerystringParameter(queryStrings.SERVICE_ZIP); + const email = getQuerystringParameter(queryStrings.EMAIL); + const isInsurance = getQuerystringParameter(queryStrings.IS_INSURANCE); if (referralNumber) { store.commit(storeMutations.UPDATE_REFERRAL_NUMBER, referralNumber); store.commit(storeMutations.UPDATE_PARENT_ACCT_NUMBER, parentAccount); @@ -93,6 +101,50 @@ const routes = [ ); updateOrCreateFunnelCookie(); } + if ( + vehicleYear && + vehicleMake && + vehicleModel && + vehicleStyle && + vehicleDamage && + serviceZip && + email && + isInsurance + ) { + if (!store.getters.applicationUser.triggeredSiteEntry) { + store.commit(storeMutations.UPDATE_YEAR, vehicleYear); + store.commit(storeMutations.UPDATE_MAKE, vehicleMake); + store.commit(storeMutations.UPDATE_MODEL, vehicleModel); + store.commit(storeMutations.UPDATE_STYLE, vehicleStyle); + store.commit(storeMutations.UPDATE_IS_LEAD_GEN, true); + if (vehicleDamage == "windshieldReplace") { + store.commit(storeMutations.UPDATE_IS_REPAIR, false); + store.commit(storeMutations.UPDATE_NUMBER_OF_CHIPS, null); + const glassToReplace = [ + { glassLocation: "Windshield", glassName: "Single" }, + ]; + store.commit( + storeMutations.UPDATE_GLASS_TO_REPLACE, + glassToReplace + ); + } else if (vehicleDamage == "windshieldRepair") { + store.commit(storeMutations.UPDATE_IS_REPAIR, true); + store.commit(storeMutations.UPDATE_NUMBER_OF_CHIPS, 1); + } + const serviceZipInfo = { + state: null, + zipCode: serviceZip, + zipCodeCtu: null, + }; + store.commit(storeMutations.UPDATE_SERVICE_ZIP, serviceZipInfo); + store.commit(storeMutations.UPDATE_CUSTOMER_EMAIL_ADDRESS, email); + if (isInsurance == "true") { + store.commit(storeMutations.UPDATE_IS_INSURANCE, true); + } else { + store.commit(storeMutations.UPDATE_IS_INSURANCE, null); + } + } + } const loadSessionResponse = await loadSessionIfPresent( to.query.isInsurance != null @@ -234,6 +286,22 @@ router.beforeEach(async (to, from, next) => { const notToPIAReturn = toQueryPage != fmgPageValues.PAYMENT_PIA_RETURN; const isInIframe = window !== window.top; + if (store.getters.isLeadGen) { + // Check if alert event is on the bus + const alertEvent = eventBus.readEventFromBus( + globalEvents.Categories.GLOBAL_ALERT, + globalEvents.SubCategories.PAGE_NOT_FOUND + ); + //Uknown alerts most likely were added by a failed api call in global-methods + const unknownAlertEvent = eventBus.readEventFromBus( + globalEvents.Categories.GLOBAL_ALERT, + globalEvents.SubCategories.UNKNOWN_ERROR + ); + // If alert event is on the bus, then display the alert + if (alertEvent !== undefined || unknownAlertEvent !== undefined) { + store.commit(storeMutations.UPDATE_IS_LEAD_GEN, false); + } + } // fromPaymentToConfirmation workaround for navigating from an iframe but // isInIframe evaluates to false for some reason when navigating from payment to confirmation const fromPaymentToConfirmation = @@ -265,8 +333,9 @@ router.afterEach(async (to, from) => { await saveSession({ pageNameToLog: to.query.fmgPage }); } } - - showFmgLoadingModal(false); + if (!store.getters.isLeadGen) { + showFmgLoadingModal(false); + } // Push page view to GA analyticsMixin.methods.pushPageViewToGA(); @@ -487,7 +556,7 @@ async function DisplayPageError() { type: globalEventTypes.Danger, } ); - + store.commit(storeMutations.UPDATE_IS_LEAD_GEN, false); baseMixin.methods.dispatchStoreAction(storeActions.RESET_SAVE_SESSION_PROMISE); const pageError = getQuerystringParameter(queryStrings.PAGE_ERROR); diff --git a/src/store/index.js b/src/store/index.js index 3ccfa4c01..c449a61c5 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -160,6 +160,7 @@ const getDefaultState = () => { customerPortalLoginToken: null, lockToken: null, settledTenderAmount: 0, + isLeadGen: false, }, applicationUser: { eventBus: [], @@ -294,6 +295,9 @@ export const mutations = { updateSettledTenderAmount(state, settledTenderAmount) { state.order.settledTenderAmount = settledTenderAmount; }, + updateIsLeadGen(state, isLeadGen) { + state.order.isLeadGen = isLeadGen; + }, updateCCToken(state, ccToken) { state.order.payment.ccToken.subscriptionId = ccToken.subscriptionId; state.order.payment.ccToken.expMonth = ccToken.expMonth; @@ -674,6 +678,7 @@ export const getters = { isOvernightDropOffAppointment: (state) => { return state.order.schedule.routeCode?.includes(RouteCodeFlags.OVERNIGHT_DROP_OFF); }, + isLeadGen: (state) => state.order.isLeadGen, isRecalibrationOnOrder: (state) => { return getHasRecalibrationPart(state); }, @@ -1927,10 +1932,13 @@ export const actions = { context.state.order.vehicle.year != year || context.state.order.vehicle.make != make || context.state.order.vehicle.model != model || - context.state.order.vehicle.style != style + context.state.order.vehicle.style != style || + context.state.order.isLeadGen ) { - context.dispatch(storeActions.RESET_DAMAGE_STATE_AND_DEPENDENCIES); - context.dispatch(storeActions.RESET_REGISTRATION_STATE_AND_DEPENDENCIES); + if (!context.state.order.isLeadGen) { + context.dispatch(storeActions.RESET_DAMAGE_STATE_AND_DEPENDENCIES); + context.dispatch(storeActions.RESET_REGISTRATION_STATE_AND_DEPENDENCIES); + } context.commit(storeMutations.UPDATE_VEHICLE_VIN, null); context.commit(storeMutations.UPDATE_YEAR, year); context.commit(storeMutations.UPDATE_MAKE, make); @@ -2701,6 +2709,9 @@ export const actions = { // clear from local storage window.sessionStorage.removeItem("submittedOrder"); }, + resetIsLeadGen(context) { + context.commit(storeMutations.UPDATE_IS_LEAD_GEN, false); + }, }; export default createStore({