diff --git a/src/constants/store-actions.js b/src/constants/store-actions.js index 87331daea..6fa81d45f 100644 --- a/src/constants/store-actions.js +++ b/src/constants/store-actions.js @@ -31,6 +31,7 @@ const storeActions = { INITIALIZE_SESSION: "initializeSession", GET_EXPERIMENTS_BY_USER: "GetExperimentsByUser", CLEAR_VIN: "clearVin", + RESET_SAVE_ORDER_PROMISE: "resetSaveOrderPromise", // DEPENDENCY MUTATIONS RESET_VEHICLE_STATE_AND_DEPENDENCIES: "resetVehicleAndDependencies", diff --git a/src/constants/store-mutations.js b/src/constants/store-mutations.js index 80697cc46..66b9ded0e 100644 --- a/src/constants/store-mutations.js +++ b/src/constants/store-mutations.js @@ -58,6 +58,7 @@ const storeMutations = { UPDATE_STATE_WITH_ORDER_INFORMATION: "updateStateWithOrderInformation", UPDATE_SAVE_ORDER_PROMISE: "updateSaveOrderPromise", UPDATE_LAST_PAGE_VISITED: "updateLastPageVisited", + RESET_SAVE_ORDER_PROMISE: "resetSaveOrderPromise", }; export { storeMutations }; diff --git a/src/helpers/heritage-integration/order-helper.js b/src/helpers/heritage-integration/order-helper.js index 9722744f0..2e6fcade0 100644 --- a/src/helpers/heritage-integration/order-helper.js +++ b/src/helpers/heritage-integration/order-helper.js @@ -60,6 +60,8 @@ export async function saveOrder() { and returns the response. */ async function loadOrder(referralNumber, referralDate, referralCorrelationId, accountNumber) { + // await the saveOrderPromise in the store to make sure we're loading up to date information + await store.getters.applicationUser.saveOrderPromise; const response = await baseMixin.methods.dispatchStoreAction(storeActions.LOAD_ORDER, { referralNumber: referralNumber.toString(), diff --git a/src/layouts/test-one.vue b/src/layouts/test-one.vue new file mode 100644 index 000000000..5ba269f2a --- /dev/null +++ b/src/layouts/test-one.vue @@ -0,0 +1,15 @@ + + + + \ No newline at end of file diff --git a/src/layouts/test-two.vue b/src/layouts/test-two.vue new file mode 100644 index 000000000..2ea5fd624 --- /dev/null +++ b/src/layouts/test-two.vue @@ -0,0 +1,15 @@ + + + + \ No newline at end of file diff --git a/src/router/index.js b/src/router/index.js index b09f734a2..98b26483b 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -19,7 +19,24 @@ import eventBus from "@/helpers/event-bus/event-bus"; import store from "@/store"; import analyticsMixin from "@/mixins/analytics-mixin"; +import TestOne from "@/layouts/test-one"; +import TestTwo from "@/layouts/test-two"; + const routes = [ + { + path: "/test1", + name: "test1", + components: { + default: TestOne + } + }, + { + path: "/test2", + name: "test2", + components: { + default: TestTwo + } + }, { path: "/", name: "root", @@ -43,6 +60,9 @@ const routes = [ // On entering the funnel "fresh", read cookie information, decide what to do next. if (from.redirectedFrom === undefined) { + // clear the saveOrderPromise - if it exists in the vuex store but a new instance was created + // the saveOrderPromise will no longer point to a valid promise + baseMixin.methods.dispatchStoreAction(storeActions.RESET_SAVE_ORDER_PROMISE); const loadOrderResponse = await loadOrderIfPresent(); const pageToRedirectTo = await getPageToRouteExistingOrderTo(to, loadOrderResponse); @@ -53,7 +73,6 @@ const routes = [ return next(false); } - // Assign our fmgPage so it will load normally like the other pages. to.query.fmgPage = pageToRedirectTo; } @@ -180,15 +199,16 @@ async function navigate(scenario, currentRoute, optionalQuery = {}, optionalPara // Get navigation map depending on the scenario and the current 'page' you're on. function getNavigationMap(scenario, currentRoute) { const fmgPageValue = currentRoute.query.fmgPage; - const matchedQueryValue = routingTable + const matchedQueryValue = routingTable(store) .filter( (item) => item.fmgPageValue === fmgPageValue && item.maps.filter((map) => map.scenario === scenario).length > 0 ) - .map((m) => m.maps.filter((map) => map.scenario === scenario)); + .map((m) => m.maps.filter((map) => map.scenario === scenario))[0] + .filter(x => x.filter === true || x.filter === undefined); - return matchedQueryValue[0][0]; + return matchedQueryValue[0]; } //---------------------------------------------------------- Private Functions ---------------------------------------------------------- diff --git a/src/router/router-constants/routing-table.js b/src/router/router-constants/routing-table.js index 82bb59ff6..51ac52efa 100644 --- a/src/router/router-constants/routing-table.js +++ b/src/router/router-constants/routing-table.js @@ -1,261 +1,274 @@ import { fmgPageValues } from "@/router/router-constants/fmgPage-values"; import { navigationScenarios } from "@/router/router-constants/navigation-scenarios"; -const routingTable = [ - { - fmgPageValue: fmgPageValues.VEHICLE_YEAR, - maps: [ - { - scenario: navigationScenarios.SELECTED_YEAR, - destinationFmgPageValue: fmgPageValues.VEHICLE_MAKE, - }, - ], - }, - { - fmgPageValue: fmgPageValues.VEHICLE_MAKE, - maps: [ - { - scenario: navigationScenarios.SELECTED_MAKE, - destinationFmgPageValue: fmgPageValues.VEHICLE_MODEL, - }, - { - scenario: navigationScenarios.CLICKED_BACK, - destinationFmgPageValue: fmgPageValues.VEHICLE_YEAR, - }, - ], - }, - { - fmgPageValue: fmgPageValues.VEHICLE_MODEL, - maps: [ - { - scenario: navigationScenarios.SELECTED_MODEL, - destinationFmgPageValue: fmgPageValues.VEHICLE_STYLE, - }, - { - scenario: navigationScenarios.CLICKED_BACK, - destinationFmgPageValue: fmgPageValues.VEHICLE_MAKE, - }, - ], - }, - { - fmgPageValue: fmgPageValues.VEHICLE_STYLE, - maps: [ - { - scenario: navigationScenarios.SELECTED_STYLE, - destinationFmgPageValue: fmgPageValues.VEHICLE_DAMAGE, - }, - { - scenario: navigationScenarios.CLICKED_BACK, - destinationFmgPageValue: fmgPageValues.VEHICLE_MODEL, - }, - ], - }, - { - fmgPageValue: fmgPageValues.VEHICLE_DAMAGE, - maps: [ - { - scenario: navigationScenarios.CLICKED_BACK, - destinationFmgPageValue: fmgPageValues.VEHICLE_STYLE, - }, - { - scenario: navigationScenarios.CLICKED_FORWARD_WITH_VIN, - destinationFmgPageValue: fmgPageValues.VIN_LOOKUP, - }, - { - scenario: navigationScenarios.CLICKED_FORWARD_WITHOUT_VIN, - destinationFmgPageValue: fmgPageValues.ESTIMATE, - }, - ], - }, - { - fmgPageValue: fmgPageValues.VEHICLE_PARTS, - maps: [ - { - scenario: navigationScenarios.CLICKED_BACK, - destinationFmgPageValue: fmgPageValues.VIN_LOOKUP, - }, - { - scenario: navigationScenarios.SELECTED_PARTS, - destinationFmgPageValue: fmgPageValues.QUOTE, - }, - { - scenario: navigationScenarios.HAS_MOLDING_QUESTIONS, - destinationFmgPageValue: fmgPageValues.MOLDING_QUESTIONS - }, - ], - }, - { - fmgPageValue: fmgPageValues.REVEAL, - maps: [ - { - scenario: navigationScenarios.CLICKED_BACK, - destinationFmgPageValue: fmgPageValues.VEHICLE_DAMAGE, - }, - { - scenario: navigationScenarios.SELECTED_PARTS, - destinationFmgPageValue: fmgPageValues.VIN_LOOKUP, - }, - ], - }, - { - fmgPageValue: fmgPageValues.VIN_LOOKUP, - maps: [ - { - scenario: navigationScenarios.CLICKED_BACK, - destinationFmgPageValue: fmgPageValues.ESTIMATE, - }, - { - scenario: navigationScenarios.SELECTED_VIN_HAS_MISMATCHED_GLASS, - destinationFmgPageValue: fmgPageValues.VEHICLE_DAMAGE, - }, - { - scenario: navigationScenarios.CLICKED_BACK_WITH_VIN, - destinationFmgPageValue: fmgPageValues.VEHICLE_DAMAGE, - }, - { - scenario: navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, - destinationFmgPageValue: fmgPageValues.PART_QUESTIONS - }, - { - scenario: navigationScenarios.SELECTED_VIN_WITH_MULTIPLE_PARTS, - destinationFmgPageValue: fmgPageValues.VEHICLE_PARTS - }, - { - scenario: navigationScenarios.SELECTED_VIN_WITH_MOLDING_QUESTIONS, - destinationFmgPageValue: fmgPageValues.MOLDING_QUESTIONS - } - ], - }, - { - fmgPageValue: fmgPageValues.LICENSE_PLATE_LOOKUP, - maps: [ - { - scenario: navigationScenarios.CLICKED_BACK, - destinationFmgPageValue: fmgPageValues.ESTIMATE, - }, - { - scenario: navigationScenarios.CLICKED_FORWARD, - destinationFmgPageValue: fmgPageValues.VEHICLE_DAMAGE, - }, - { - scenario: navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, - destinationFmgPageValue: fmgPageValues.PART_QUESTIONS - }, - { - scenario: navigationScenarios.SELECTED_VIN_WITH_MULTIPLE_PARTS, - destinationFmgPageValue: fmgPageValues.VEHICLE_PARTS - }, - { - scenario: navigationScenarios.SELECTED_VIN_WITH_MOLDING_QUESTIONS, - destinationFmgPageValue: fmgPageValues.MOLDING_QUESTIONS - } - ], - }, - { - fmgPageValue: fmgPageValues.ADDRESS_LOOKUP, - maps: [ - { - scenario: navigationScenarios.CLICKED_BACK, - destinationFmgPageValue: fmgPageValues.ESTIMATE, - }, - { - scenario: navigationScenarios.CONTINUING_WITH_MULTIPLE_VEHICLES, - destinationFmgPageValue: fmgPageValues.ADDRESS_VEHICLES, - }, - { - scenario: navigationScenarios.SELECTED_VIN_HAS_MISMATCHED_GLASS, - destinationFmgPageValue: fmgPageValues.VEHICLE_DAMAGE, - }, - { - scenario: navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, - destinationFmgPageValue: fmgPageValues.PART_QUESTIONS - }, - { - scenario: navigationScenarios.SELECTED_VIN_WITH_MULTIPLE_PARTS, - destinationFmgPageValue: fmgPageValues.VEHICLE_PARTS - }, - { - scenario: navigationScenarios.SELECTED_VIN_WITH_MOLDING_QUESTIONS, - destinationFmgPageValue: fmgPageValues.MOLDING_QUESTIONS - } - ], - }, - { - fmgPageValue: fmgPageValues.ADDRESS_VEHICLES, - maps: [ - { - scenario: navigationScenarios.CLICKED_BACK, - destinationFmgPageValue: fmgPageValues.ADDRESS_LOOKUP, - }, - { - scenario: navigationScenarios.CLICKED_FORWARD, - destinationFmgPageValue: fmgPageValues.VEHICLE_DAMAGE, - }, - { - scenario: navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, - destinationFmgPageValue: fmgPageValues.PART_QUESTIONS - }, - { - scenario: navigationScenarios.SELECTED_VIN_WITH_MULTIPLE_PARTS, - destinationFmgPageValue: fmgPageValues.VEHICLE_PARTS - }, - { - scenario: navigationScenarios.SELECTED_PROVIDE_VIN_DIFFERENT_WAY, - destinationFmgPageValue: fmgPageValues.ESTIMATE - } - ], - }, - { - fmgPageValue: fmgPageValues.ESTIMATE, - maps: [ - { - scenario: navigationScenarios.CLICKED_BACK, - destinationFmgPageValue: fmgPageValues.VEHICLE_DAMAGE, - }, - { - scenario: navigationScenarios.SELECTED_MANUAL_VIN, - destinationFmgPageValue: fmgPageValues.VIN_LOOKUP, - }, - { - scenario: navigationScenarios.SELECTED_LICENSE_PLATE, - destinationFmgPageValue: fmgPageValues.LICENSE_PLATE_LOOKUP, - }, - { - scenario: navigationScenarios.SELECTED_HOME_ADDRESS, - destinationFmgPageValue: fmgPageValues.ADDRESS_LOOKUP, - }, - ], - }, - { - fmgPageValue: fmgPageValues.PART_QUESTIONS, - maps: [ - { - scenario: navigationScenarios.CLICKED_BACK, - destinationFmgPageValue: fmgPageValues.VIN_LOOKUP - }, - { - scenario: navigationScenarios.ANSWERED_QUESTIONS_WITH_MULTIPLE_PARTS, - destinationFmgPageValue: fmgPageValues.VEHICLE_PARTS - }, - { - scenario: navigationScenarios.HAS_MOLDING_QUESTIONS, - destinationFmgPageValue: fmgPageValues.MOLDING_QUESTIONS, - }, - { - scenario: navigationScenarios.ANSWERED_QUESTIONS_WITH_SINGLE_PART, - destinationFmgPageValue: fmgPageValues.QUOTE, - }, - ] - }, - { - fmgPageValue: fmgPageValues.MOLDING_QUESTIONS, - maps: [ - { - scenario: navigationScenarios.CLICKED_BACK, - destinationFmgPageValue: fmgPageValues.VEHICLE_PARTS - }, - ] - }, -]; +// Get store from router/index.js instead of importing it here to get updated values +const routingTable = function(store) { + return [ + { + fmgPageValue: fmgPageValues.VEHICLE_YEAR, + maps: [ + { + scenario: navigationScenarios.SELECTED_YEAR, + destinationFmgPageValue: "test1", + filter: store.getters.vehicle.year === 2010 + }, + { + scenario: navigationScenarios.SELECTED_YEAR, + destinationFmgPageValue: "test2", + filter: store.getters.vehicle.year < 1954 + }, + { + scenario: navigationScenarios.SELECTED_YEAR, + destinationFmgPageValue: fmgPageValues.VEHICLE_MAKE, + }, + ], + }, + { + fmgPageValue: fmgPageValues.VEHICLE_MAKE, + maps: [ + { + scenario: navigationScenarios.SELECTED_MAKE, + destinationFmgPageValue: fmgPageValues.VEHICLE_MODEL, + }, + { + scenario: navigationScenarios.CLICKED_BACK, + destinationFmgPageValue: fmgPageValues.VEHICLE_YEAR, + }, + ], + }, + { + fmgPageValue: fmgPageValues.VEHICLE_MODEL, + maps: [ + { + scenario: navigationScenarios.SELECTED_MODEL, + destinationFmgPageValue: fmgPageValues.VEHICLE_STYLE, + }, + { + scenario: navigationScenarios.CLICKED_BACK, + destinationFmgPageValue: fmgPageValues.VEHICLE_MAKE, + }, + ], + }, + { + fmgPageValue: fmgPageValues.VEHICLE_STYLE, + maps: [ + { + scenario: navigationScenarios.SELECTED_STYLE, + destinationFmgPageValue: fmgPageValues.VEHICLE_DAMAGE, + }, + { + scenario: navigationScenarios.CLICKED_BACK, + destinationFmgPageValue: fmgPageValues.VEHICLE_MODEL, + }, + ], + }, + { + fmgPageValue: fmgPageValues.VEHICLE_DAMAGE, + maps: [ + { + scenario: navigationScenarios.CLICKED_BACK, + destinationFmgPageValue: fmgPageValues.VEHICLE_STYLE, + }, + { + scenario: navigationScenarios.CLICKED_FORWARD_WITH_VIN, + destinationFmgPageValue: fmgPageValues.VIN_LOOKUP, + }, + { + scenario: navigationScenarios.CLICKED_FORWARD_WITHOUT_VIN, + destinationFmgPageValue: fmgPageValues.ESTIMATE, + }, + ], + }, + { + fmgPageValue: fmgPageValues.VEHICLE_PARTS, + maps: [ + { + scenario: navigationScenarios.CLICKED_BACK, + destinationFmgPageValue: fmgPageValues.VIN_LOOKUP, + }, + { + scenario: navigationScenarios.SELECTED_PARTS, + destinationFmgPageValue: fmgPageValues.QUOTE, + }, + { + scenario: navigationScenarios.CLICKED_FORWARD, + destinationFmgPageValue: fmgPageValues.REVEAL, + }, + ], + }, + { + fmgPageValue: fmgPageValues.REVEAL, + maps: [ + { + scenario: navigationScenarios.CLICKED_BACK, + destinationFmgPageValue: fmgPageValues.VEHICLE_DAMAGE, + }, + { + scenario: navigationScenarios.SELECTED_PARTS, + destinationFmgPageValue: fmgPageValues.VIN_LOOKUP, + }, + ], + }, + { + fmgPageValue: fmgPageValues.VIN_LOOKUP, + maps: [ + { + scenario: navigationScenarios.CLICKED_BACK, + destinationFmgPageValue: fmgPageValues.ESTIMATE, + }, + { + scenario: navigationScenarios.SELECTED_VIN_HAS_MISMATCHED_GLASS, + destinationFmgPageValue: fmgPageValues.VEHICLE_DAMAGE, + }, + { + scenario: navigationScenarios.CLICKED_BACK_WITH_VIN, + destinationFmgPageValue: fmgPageValues.VEHICLE_DAMAGE, + }, + { + scenario: navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, + destinationFmgPageValue: fmgPageValues.PART_QUESTIONS + }, + { + scenario: navigationScenarios.SELECTED_VIN_WITH_MULTIPLE_PARTS, + destinationFmgPageValue: fmgPageValues.VEHICLE_PARTS + }, + { + scenario: navigationScenarios.SELECTED_VIN_WITH_MOLDING_QUESTIONS, + destinationFmgPageValue: fmgPageValues.MOLDING_QUESTIONS + } + ], + }, + { + fmgPageValue: fmgPageValues.LICENSE_PLATE_LOOKUP, + maps: [ + { + scenario: navigationScenarios.CLICKED_BACK, + destinationFmgPageValue: fmgPageValues.ESTIMATE, + }, + { + scenario: navigationScenarios.CLICKED_FORWARD, + destinationFmgPageValue: fmgPageValues.VEHICLE_DAMAGE, + }, + { + scenario: navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, + destinationFmgPageValue: fmgPageValues.PART_QUESTIONS + }, + { + scenario: navigationScenarios.SELECTED_VIN_WITH_MULTIPLE_PARTS, + destinationFmgPageValue: fmgPageValues.VEHICLE_PARTS + }, + { + scenario: navigationScenarios.SELECTED_VIN_WITH_MOLDING_QUESTIONS, + destinationFmgPageValue: fmgPageValues.MOLDING_QUESTIONS + } + ], + }, + { + fmgPageValue: fmgPageValues.ADDRESS_LOOKUP, + maps: [ + { + scenario: navigationScenarios.CLICKED_BACK, + destinationFmgPageValue: fmgPageValues.ESTIMATE, + }, + { + scenario: navigationScenarios.CONTINUING_WITH_MULTIPLE_VEHICLES, + destinationFmgPageValue: fmgPageValues.ADDRESS_VEHICLES, + }, + { + scenario: navigationScenarios.SELECTED_VIN_HAS_MISMATCHED_GLASS, + destinationFmgPageValue: fmgPageValues.VEHICLE_DAMAGE, + }, + { + scenario: navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, + destinationFmgPageValue: fmgPageValues.PART_QUESTIONS + }, + { + scenario: navigationScenarios.SELECTED_VIN_WITH_MULTIPLE_PARTS, + destinationFmgPageValue: fmgPageValues.VEHICLE_PARTS + }, + { + scenario: navigationScenarios.SELECTED_VIN_WITH_MOLDING_QUESTIONS, + destinationFmgPageValue: fmgPageValues.MOLDING_QUESTIONS + } + ], + }, + { + fmgPageValue: fmgPageValues.ADDRESS_VEHICLES, + maps: [ + { + scenario: navigationScenarios.CLICKED_BACK, + destinationFmgPageValue: fmgPageValues.ADDRESS_LOOKUP, + }, + { + scenario: navigationScenarios.CLICKED_FORWARD, + destinationFmgPageValue: fmgPageValues.VEHICLE_DAMAGE, + }, + { + scenario: navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, + destinationFmgPageValue: fmgPageValues.PART_QUESTIONS + }, + { + scenario: navigationScenarios.SELECTED_VIN_WITH_MULTIPLE_PARTS, + destinationFmgPageValue: fmgPageValues.VEHICLE_PARTS + }, + { + scenario: navigationScenarios.SELECTED_PROVIDE_VIN_DIFFERENT_WAY, + destinationFmgPageValue: fmgPageValues.ESTIMATE + } + ], + }, + { + fmgPageValue: fmgPageValues.ESTIMATE, + maps: [ + { + scenario: navigationScenarios.CLICKED_BACK, + destinationFmgPageValue: fmgPageValues.VEHICLE_DAMAGE, + }, + { + scenario: navigationScenarios.SELECTED_MANUAL_VIN, + destinationFmgPageValue: fmgPageValues.VIN_LOOKUP, + }, + { + scenario: navigationScenarios.SELECTED_LICENSE_PLATE, + destinationFmgPageValue: fmgPageValues.LICENSE_PLATE_LOOKUP, + }, + { + scenario: navigationScenarios.SELECTED_HOME_ADDRESS, + destinationFmgPageValue: fmgPageValues.ADDRESS_LOOKUP, + }, + ], + }, + { + fmgPageValue: fmgPageValues.PART_QUESTIONS, + maps: [ + { + scenario: navigationScenarios.CLICKED_BACK, + destinationFmgPageValue: fmgPageValues.VIN_LOOKUP + }, + { + scenario: navigationScenarios.ANSWERED_QUESTIONS_WITH_MULTIPLE_PARTS, + destinationFmgPageValue: fmgPageValues.VEHICLE_PARTS + }, + { + scenario: navigationScenarios.HAS_MOLDING_QUESTIONS, + destinationFmgPageValue: fmgPageValues.MOLDING_QUESTIONS, + }, + { + scenario: navigationScenarios.ANSWERED_QUESTIONS_WITH_SINGLE_PART, + destinationFmgPageValue: fmgPageValues.QUOTE, + }, + ] + }, + { + fmgPageValue: fmgPageValues.MOLDING_QUESTIONS, + maps: [ + { + scenario: navigationScenarios.CLICKED_BACK, + destinationFmgPageValue: fmgPageValues.VEHICLE_PARTS + }, + ] + }, + ]; +} export { routingTable }; diff --git a/src/store/index.js b/src/store/index.js index 90932c8bb..64ba356e6 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -269,7 +269,9 @@ export const mutations = { resetState(state) { Object.assign(state, getDefaultState()); }, - + resetSaveOrderPromise(state) { + state.applicationUser.saveOrderPromise = null; + }, // Misc Mutations updateStateWithOrderInformation(state, orderInformation) { state.order.referralNumber = orderInformation.referralNumber; @@ -457,6 +459,9 @@ export const actions = { resetState(context) { context.commit(storeMutations.RESET_STATE); }, + resetSaveOrderPromise(context) { + context.commit(storeMutations.RESET_SAVE_ORDER_PROMISE); + }, // Content API Actions getRouteInfo(context, { pageName }) { @@ -701,7 +706,10 @@ export const actions = { accountNumber: accountNumber?.toString() }, }).then((response) => { - context.commit(storeMutations.RESET_STATE); + // clear the state if the existing referral number does not equal what is returned from loadOrder + if (context.state.order.referralNumber != response.data.referralNumber) { + context.commit(storeMutations.RESET_STATE); + } context.commit(storeMutations.UPDATE_STATE_WITH_ORDER_INFORMATION, response.data); return response; });