diff --git a/src/layouts/address-lookup/address-lookup.vue b/src/layouts/address-lookup/address-lookup.vue index cbbfe0323..ed1ffd3db 100644 --- a/src/layouts/address-lookup/address-lookup.vue +++ b/src/layouts/address-lookup/address-lookup.vue @@ -140,7 +140,7 @@ export default { }, backButtonAction() { // route to move backwards - this.$router.navigate( + this.$router.navigateWithoutSaving( this.navigationScenarios.CLICKED_BACK, this.$route ); @@ -309,11 +309,11 @@ export default { // If a different vehicle is found than the one entered and the selected glass is not available for that vehicle then navigate back to "vehicle-damage" // display vehicle changed alert on that page. if (this.isCarIdDifferent && !this.isSelectedGlassAvailableForVehicle && matchingCars.length === 1) { - this.$router.navigate(this.navigationScenarios.SELECTED_VIN_HAS_MISMATCHED_GLASS, this.$route, {}, {[routerParams.DISPLAY_VEHICLE_CHANGE_ALERT]: true}); + this.$router.navigateWithSaving(this.navigationScenarios.SELECTED_VIN_HAS_MISMATCHED_GLASS, this.$route, {}, {[routerParams.DISPLAY_VEHICLE_CHANGE_ALERT]: true}); } else if (matchingCars.length === 1) { await this.navigateForwardWithSingleCarMatch(); } else { - this.$router.navigate(this.navigationScenarios.CONTINUING_WITH_MULTIPLE_VEHICLES, this.$route, {}, {}, carsFound); + this.$router.navigateWithSaving(this.navigationScenarios.CONTINUING_WITH_MULTIPLE_VEHICLES, this.$route, {}, {}, carsFound); } }, diff --git a/src/layouts/address-vehicles/address-vehicles.vue b/src/layouts/address-vehicles/address-vehicles.vue index b0669e720..081b83fe9 100644 --- a/src/layouts/address-vehicles/address-vehicles.vue +++ b/src/layouts/address-vehicles/address-vehicles.vue @@ -162,7 +162,7 @@ export default { return false; }, backButtonAction() { - this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route); + this.$router.navigateWithoutSaving(this.navigationScenarios.CLICKED_BACK, this.$route); }, async forwardButtonAction() { @@ -184,7 +184,7 @@ export default { }, async navigateForward() { if (this.isCarIdDifferent && !this.isSelectedGlassAvailableForVehicle) { - this.$router.navigate(this.navigationScenarios.CLICKED_FORWARD,this.$route,{},{[routerParams.DISPLAY_VEHICLE_CHANGE_ALERT]: true },); + this.$router.navigateWithSaving(this.navigationScenarios.CLICKED_FORWARD,this.$route,{},{[routerParams.DISPLAY_VEHICLE_CHANGE_ALERT]: true },); } else { await this.navigateForwardWithSingleCarMatch(); } diff --git a/src/layouts/capability-questions/capability-questions.vue b/src/layouts/capability-questions/capability-questions.vue index 69fc8aad5..8b6eb127c 100644 --- a/src/layouts/capability-questions/capability-questions.vue +++ b/src/layouts/capability-questions/capability-questions.vue @@ -122,7 +122,7 @@ export default { }, backButtonAction() { // route to move backwards - this.$router.navigate( + this.$router.navigateWithoutSaving( this.navigationScenarios.CLICKED_BACK, this.$route ); diff --git a/src/layouts/estimate/estimate.vue b/src/layouts/estimate/estimate.vue index 3949d4c41..956e9d8bb 100644 --- a/src/layouts/estimate/estimate.vue +++ b/src/layouts/estimate/estimate.vue @@ -87,7 +87,7 @@ export default { }, backButtonAction() { // route to move backwards - this.$router.navigate( + this.$router.navigateWithoutSaving( this.navigationScenarios.CLICKED_BACK, this.$route ); @@ -95,19 +95,19 @@ export default { async forwardButtonAction() { if (this.selectedVinLookupMethod === vinLookupMethodSelections.MANUALVIN) { await this.dispatchStoreAction(storeActions.CLEAR_VIN); - return this.$router.navigate( + return this.$router.navigateWithSaving( this.navigationScenarios.SELECTED_MANUAL_VIN, this.$route ); } if (this.selectedVinLookupMethod === vinLookupMethodSelections.LICENSEPLATE) { - return this.$router.navigate( + return this.$router.navigateWithSaving( this.navigationScenarios.SELECTED_LICENSE_PLATE, this.$route ); } if (this.selectedVinLookupMethod === vinLookupMethodSelections.HOMEADDRESS) { - return this.$router.navigate( + return this.$router.navigateWithSaving( this.navigationScenarios.SELECTED_HOME_ADDRESS, this.$route ); diff --git a/src/layouts/license-plate-lookup/license-plate-lookup.vue b/src/layouts/license-plate-lookup/license-plate-lookup.vue index 667bac7fc..1b163ef30 100644 --- a/src/layouts/license-plate-lookup/license-plate-lookup.vue +++ b/src/layouts/license-plate-lookup/license-plate-lookup.vue @@ -177,7 +177,7 @@ export default { }, backButtonAction() { // route to move backwards - this.$router.navigate( + this.$router.navigateWithoutSaving( this.navigationScenarios.CLICKED_BACK, this.$route ); @@ -298,7 +298,7 @@ export default { }, async navigateForward() { if (this.isCarIdDifferent && !this.isSelectedGlassAvailableForVehicle) { - this.$router.navigate(this.navigationScenarios.CLICKED_FORWARD, this.$route, {}, { [routerParams.DISPLAY_VEHICLE_CHANGE_ALERT]: true }); + this.$router.navigateWithSaving(this.navigationScenarios.CLICKED_FORWARD, this.$route, {}, { [routerParams.DISPLAY_VEHICLE_CHANGE_ALERT]: true }); } else { await this.navigateForwardWithSingleCarMatch(); } diff --git a/src/layouts/molding-questions/molding-questions.vue b/src/layouts/molding-questions/molding-questions.vue index d2b469a36..eb1da755b 100644 --- a/src/layouts/molding-questions/molding-questions.vue +++ b/src/layouts/molding-questions/molding-questions.vue @@ -125,7 +125,7 @@ export default { }, backButtonAction() { // route to move backwards - this.$router.navigate( + this.$router.navigateWithoutSaving( this.navigationScenarios.CLICKED_BACK, this.$route ); @@ -156,7 +156,7 @@ export default { if (hasCapabilityQuestions) { // if has capability questions // go to capability-questions page - this.$router.navigate(this.navigationScenarios.HAS_CAPABILITY_QUESTIONS,this.$route,{},{},{partsOrQuestions: glassNameAndPartsForStore}); + this.$router.navigateWithSaving(this.navigationScenarios.HAS_CAPABILITY_QUESTIONS,this.$route,{},{},{partsOrQuestions: glassNameAndPartsForStore}); } else { // if single parts only const collectedGlassParts = this.reducedGlassPartsArray(glassNameAndPartsForStore); diff --git a/src/layouts/part-questions/part-questions.vue b/src/layouts/part-questions/part-questions.vue index db237ce2b..4d10d1b98 100644 --- a/src/layouts/part-questions/part-questions.vue +++ b/src/layouts/part-questions/part-questions.vue @@ -121,7 +121,7 @@ export default { }, backButtonAction() { // route to move backwards - this.$router.navigate( + this.$router.navigateWithoutSaving( this.navigationScenarios.CLICKED_BACK, this.$route ); @@ -155,15 +155,15 @@ export default { if (hasGlassLocationWithMultipleParts) { // if multiple parts on any glass // go to vehicle-parts page and pass the partsData - this.$router.navigate(this.navigationScenarios.ANSWERED_QUESTIONS_WITH_MULTIPLE_PARTS,this.$route,{},{},{partsOrQuestions: glassNameAndPartsForStore}); + this.$router.navigateWithSaving(this.navigationScenarios.ANSWERED_QUESTIONS_WITH_MULTIPLE_PARTS,this.$route,{},{},{partsOrQuestions: glassNameAndPartsForStore}); } else if (hasChildPartQuestions) { // if any childpart questions // go to molding-questions page and pass the partsData - this.$router.navigate(this.navigationScenarios.HAS_MOLDING_QUESTIONS,this.$route,{},{},{partsOrQuestions: glassNameAndPartsForStore}); + this.$router.navigateWithSaving(this.navigationScenarios.HAS_MOLDING_QUESTIONS,this.$route,{},{},{partsOrQuestions: glassNameAndPartsForStore}); } else if (hasCapabilityQuestions) { // if has capability questions // go to capability-questions page and pass the partsData - this.$router.navigate(this.navigationScenarios.HAS_CAPABILITY_QUESTIONS,this.$route,{},{},{partsOrQuestions: glassNameAndPartsForStore}); + this.$router.navigateWithSaving(this.navigationScenarios.HAS_CAPABILITY_QUESTIONS,this.$route,{},{},{partsOrQuestions: glassNameAndPartsForStore}); } else { // if single parts only const collectedGlassParts = this.reducedGlassPartsArray(glassNameAndPartsForStore); diff --git a/src/layouts/reveal/reveal.vue b/src/layouts/reveal/reveal.vue index 4280b099f..9ef10d61d 100644 --- a/src/layouts/reveal/reveal.vue +++ b/src/layouts/reveal/reveal.vue @@ -40,7 +40,7 @@ export default { methods: { backButtonAction() { // route to move backwards - this.$router.navigate( + this.$router.navigateWithoutSaving( this.navigationScenarios.CLICKED_BACK, this.$route ); diff --git a/src/layouts/vehicle-damage/vehicle-damage.vue b/src/layouts/vehicle-damage/vehicle-damage.vue index 7d61814f8..233107c20 100644 --- a/src/layouts/vehicle-damage/vehicle-damage.vue +++ b/src/layouts/vehicle-damage/vehicle-damage.vue @@ -170,7 +170,7 @@ export default { backButtonAction() { // route to move backwards - this.$router.navigate( + this.$router.navigateWithoutSaving( this.navigationScenarios.CLICKED_BACK, this.$route ); @@ -293,10 +293,10 @@ export default { // If vin already exists, navigate directly to vin-lookup if(store.getters.vehicle.vin) { - this.$router.navigate(this.navigationScenarios.CLICKED_FORWARD_WITH_VIN, this.$route); + this.$router.navigateWithSaving(this.navigationScenarios.CLICKED_FORWARD_WITH_VIN, this.$route); } else { - this.$router.navigate(this.navigationScenarios.CLICKED_FORWARD_WITHOUT_VIN, this.$route); + this.$router.navigateWithSaving(this.navigationScenarios.CLICKED_FORWARD_WITHOUT_VIN, this.$route); } }, diff --git a/src/layouts/vehicle-make/vehicle-make.vue b/src/layouts/vehicle-make/vehicle-make.vue index 8cd77c545..83361fe98 100644 --- a/src/layouts/vehicle-make/vehicle-make.vue +++ b/src/layouts/vehicle-make/vehicle-make.vue @@ -70,7 +70,7 @@ export default { methods: { backButtonAction() { // route to move backwards - this.$router.navigate( + this.$router.navigateWithoutSaving( this.navigationScenarios.CLICKED_BACK, this.$route ); @@ -86,7 +86,7 @@ export default { watch: { selectedMake(make) { this.dispatchStoreAction(storeActions.SAVE_VEHICLE_MAKE, make, false); - this.$router.navigate( + this.$router.navigateWithSaving( this.navigationScenarios.SELECTED_MAKE, this.$route ); diff --git a/src/layouts/vehicle-model/vehicle-model.vue b/src/layouts/vehicle-model/vehicle-model.vue index 455f3d8b3..2db7e34c8 100644 --- a/src/layouts/vehicle-model/vehicle-model.vue +++ b/src/layouts/vehicle-model/vehicle-model.vue @@ -71,7 +71,7 @@ export default { methods: { backButtonAction() { // route to move backwards - this.$router.navigate( + this.$router.navigateWithoutSaving( this.navigationScenarios.CLICKED_BACK, this.$route ); @@ -87,7 +87,7 @@ export default { watch: { selectedModel(model) { this.dispatchStoreAction(storeActions.SAVE_VEHICLE_MODEL, model, false); - this.$router.navigate( + this.$router.navigateWithSaving( this.navigationScenarios.SELECTED_MODEL, this.$route ); diff --git a/src/layouts/vehicle-parts/vehicle-parts.vue b/src/layouts/vehicle-parts/vehicle-parts.vue index 27a92ddf4..02cb557a1 100644 --- a/src/layouts/vehicle-parts/vehicle-parts.vue +++ b/src/layouts/vehicle-parts/vehicle-parts.vue @@ -162,7 +162,7 @@ export default { const hasPartQuestions = this.hasPartQuestions(this.$store.getters.pageData(fmgPageValues.PART_QUESTIONS)?.partsOrQuestions); const backNavigationScenario = hasPartQuestions ? this.navigationScenarios.CLICKED_BACK_WITH_PART_QUESTION_ANSWERS : this.navigationScenarios.CLICKED_BACK_WITHOUT_PART_QUESTION_ANSWERS; - this.$router.navigate( + this.$router.WithoutSaving( backNavigationScenario, this.$route ); @@ -203,7 +203,7 @@ export default { // Navigate to the next page if (hasChildPartQuestions) { - this.$router.navigate( + this.$router.navigateWithSaving( this.navigationScenarios.HAS_MOLDING_QUESTIONS, this.$route, {}, @@ -211,7 +211,7 @@ export default { {partsOrQuestions: matchedParts} ); } else if (hasCapabilityQuestions) { - this.$router.navigate( + this.$router.navigateWithSaving( this.navigationScenarios.HAS_CAPABILITY_QUESTIONS, this.$route, {}, diff --git a/src/layouts/vehicle-style/vehicle-style.vue b/src/layouts/vehicle-style/vehicle-style.vue index 4587172e7..1b99f88a4 100644 --- a/src/layouts/vehicle-style/vehicle-style.vue +++ b/src/layouts/vehicle-style/vehicle-style.vue @@ -71,7 +71,7 @@ export default { methods: { backButtonAction() { // route to move backwards - this.$router.navigate( + this.$router.WithoutSaving( this.navigationScenarios.CLICKED_BACK, this.$route ); @@ -99,7 +99,7 @@ export default { selectedStyle(style) { this.dispatchStoreAction(storeActions.SAVE_VEHICLE_STYLE, style, false); this.setVehicle().then(() => { - this.$router.navigate( + this.$router.navigateWithSaving( this.navigationScenarios.SELECTED_STYLE, this.$route ); diff --git a/src/layouts/vehicle-year/vehicle-year.vue b/src/layouts/vehicle-year/vehicle-year.vue index 4ef506eef..029234a14 100644 --- a/src/layouts/vehicle-year/vehicle-year.vue +++ b/src/layouts/vehicle-year/vehicle-year.vue @@ -88,7 +88,7 @@ export default { selectedYear(year) { const parsedYear = parseInt(year); this.dispatchStoreAction(storeActions.SAVE_VEHICLE_YEAR, parsedYear); - this.$router.navigate( + this.$router.navigateWithSaving( this.navigationScenarios.SELECTED_YEAR, this.$route ); diff --git a/src/layouts/vin-lookup/vin-lookup.vue b/src/layouts/vin-lookup/vin-lookup.vue index 84c17cfd9..21d06ff56 100644 --- a/src/layouts/vin-lookup/vin-lookup.vue +++ b/src/layouts/vin-lookup/vin-lookup.vue @@ -211,10 +211,10 @@ export default { }, backButtonAction() { if (this.$store.getters.vehicle.vin) { - this.$router.navigate(this.navigationScenarios.CLICKED_BACK_WITH_VIN, this.$route); + this.$router.navigateWithoutSaving(this.navigationScenarios.CLICKED_BACK_WITH_VIN, this.$route); } else { - this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route); + this.$router.navigateWithoutSaving(this.navigationScenarios.CLICKED_BACK, this.$route); } }, @@ -331,7 +331,7 @@ export default { }, 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 }); + this.$router.navigateWithSaving(this.navigationScenarios.SELECTED_VIN_HAS_MISMATCHED_GLASS, this.$route, {}, { [routerParams.DISPLAY_VEHICLE_CHANGE_ALERT]: true }); } else { await this.navigateForwardWithSingleCarMatch(); } diff --git a/src/mixins/vin-pages-mixin.js b/src/mixins/vin-pages-mixin.js index a7ba799a2..61aaeb7fc 100644 --- a/src/mixins/vin-pages-mixin.js +++ b/src/mixins/vin-pages-mixin.js @@ -17,16 +17,16 @@ export default { const hasCapabilityQuestions = this.hasCapabilityQuestions(partsOrQuestions); if (hasPartsQuestions) { - this.$router.navigate(this.navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, this.$route, {}, {}, result.data); + this.$router.navigateWithSaving(this.navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, this.$route, {}, {}, result.data); } else if (hasGlassLocationWithMultipleParts) { - this.$router.navigate(this.navigationScenarios.SELECTED_VIN_WITH_MULTIPLE_PARTS, this.$route, {}, {}, result.data); + this.$router.navigateWithSaving(this.navigationScenarios.SELECTED_VIN_WITH_MULTIPLE_PARTS, this.$route, {}, {}, result.data); } else if (hasChildPartQuestions) { - this.$router.navigate(this.navigationScenarios.SELECTED_VIN_WITH_MOLDING_QUESTIONS, this.$route, {}, {}, result.data); + this.$router.navigateWithSaving(this.navigationScenarios.SELECTED_VIN_WITH_MOLDING_QUESTIONS, this.$route, {}, {}, result.data); } else if (hasCapabilityQuestions) { - this.$router.navigate(this.navigationScenarios.SELECTED_VIN_WITH_CAPABILITY_QUESTIONS, this.$route, {}, {}, result.data); + this.$router.navigateWithSaving(this.navigationScenarios.SELECTED_VIN_WITH_CAPABILITY_QUESTIONS, this.$route, {}, {}, result.data); } else { // if single parts only diff --git a/src/router/index.js b/src/router/index.js index 525664dd5..368d9aff6 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -127,6 +127,13 @@ router.afterEach((to, from) => { // Push page view to GA analyticsMixin.methods.pushPageViewToGA(to.query[queryStrings.FMG_PAGE]); + // If saving on navigation is requested, check for saved SessionId or EmailAddress to determine if saving is appropriate + if (eval(to.params.isSavingNavigation)) { + if (store.getters.applicationUser.savedSessionId || store.getters.order.customer?.emailAddress) { + saveOrder(); + } + } + baseMixin.methods.dispatchStoreAction(storeActions.GET_EXPERIMENTS_BY_USER, { userId: getDeviceIdValue() }) .then( (response) => { analyticsMixin.methods.pushExperimentsToDataLayer(response.data); @@ -134,10 +141,13 @@ router.afterEach((to, from) => { }); -router.navigate = (scenario, currentRoute, optionalQuery = {}, optionalParams = {}, optionalPageData) => { - navigate(scenario, currentRoute, optionalQuery, optionalParams, optionalPageData); +router.navigateWithoutSaving = (scenario, currentRoute, optionalQuery = {}, optionalParams = {}, optionalPageData = {}) => { + navigate(scenario, currentRoute, false, optionalQuery, optionalParams, optionalPageData); } +router.navigateWithSaving = (scenario, currentRoute, optionalQuery = {}, optionalParams = {}, optionalPageData = {}) => { + navigate(scenario, currentRoute, true, optionalQuery, optionalParams, optionalPageData); +} router.navigateToExternalUrl = (url, optionalQuery = {}) => { navigateToUrl(url, optionalQuery); @@ -146,7 +156,7 @@ router.navigateToExternalUrl = (url, optionalQuery = {}) => { // PRIVATE FUNCTIONS // Navigate to the next route, depending on the scenario. -async function navigate(scenario, currentRoute, optionalQuery = {}, optionalParams = {}, optionalPageData) { +async function navigate(scenario, currentRoute, isSavingNavigation, optionalQuery = {}, optionalParams = {}, optionalPageData = {}) { if (!scenario) { console.error("No scenario provided. Please review the routing table."); return; @@ -164,10 +174,7 @@ async function navigate(scenario, currentRoute, optionalQuery = {}, optionalPara baseMixin.methods.savePageDataToStore(destinationFmgPageValue, optionalPageData); } - // if cookie and referralNumber/Date exists OR an emailAddress has been saved - if ((getFunnelCookie()?.ReferralNumber && getFunnelCookie()?.ReferralDate) || store.getters.order.customer?.emailAddress) { - saveOrder(); - } + optionalParams.isSavingNavigation = isSavingNavigation; router.push({ name: "root",