diff --git a/src/helpers/heritage-integration/navigation-helper.js b/src/helpers/heritage-integration/navigation-helper.js index 7030ba193..6fa248c63 100644 --- a/src/helpers/heritage-integration/navigation-helper.js +++ b/src/helpers/heritage-integration/navigation-helper.js @@ -46,7 +46,7 @@ export async function getPageToRouteExistingOrderTo(toRoute = {}, existingHerita export async function navigateToHeritageFunnel({ shouldSaveSession = true, loadingModal }) { // Create the order (or save existing order) when navigating to Heritage Funnel. if (shouldSaveSession) { - await saveSession(); + await saveSession({ shouldAwaitSaveSessionQueue: true }); } if (loadingModal && loadingModal.showModal) { diff --git a/src/helpers/heritage-integration/order-helper.js b/src/helpers/heritage-integration/order-helper.js index 469f38b60..05b4c4dc4 100644 --- a/src/helpers/heritage-integration/order-helper.js +++ b/src/helpers/heritage-integration/order-helper.js @@ -50,9 +50,9 @@ export async function loadSessionIfPresent(isConceptInsurance) { /* Will call API to save existing order, or create new one depending where it's called from. This will also set Referral information in the store after saving, and then - update the cookie. + update the cookie. To force synchronous behavior pass in 'true' for shouldAwaitSaveSessionQueue */ -export async function saveSession() { +export async function saveSession({ shouldAwaitSaveSessionQueue = false }) { var saveSessionPromise; if (store.getters.applicationUser.saveSessionPromise) { // queue newest request after current saveSessionPromise resolves @@ -66,7 +66,9 @@ export async function saveSession() { } store.commit(storeMutations.UPDATE_SAVE_SESSION_PROMISE, saveSessionPromise); // await here to allow for a caller to await and make the function synchronous - await saveSessionPromise; + if (!store.getters.applicationUser.savedSessionId || shouldAwaitSaveSessionQueue) { + await saveSessionPromise; + } } // PRIVATE FUNCTIONS // diff --git a/src/helpers/heritage-integration/order-helper.spec.js b/src/helpers/heritage-integration/order-helper.spec.js index 74c911e05..97b162560 100644 --- a/src/helpers/heritage-integration/order-helper.spec.js +++ b/src/helpers/heritage-integration/order-helper.spec.js @@ -170,7 +170,7 @@ describe("saveSession", () => { const mocks = setupMocksForJsFiles(mockData); // Act - await saveSession(); + await saveSession({}); // Assert expect(mocks.baseMixin.methods.dispatchStoreAction).toHaveBeenCalledWith( @@ -231,7 +231,7 @@ describe("saveSession", () => { setupCookies({ funnelCookieValue: JSON.stringify(testCookieValue) }); // Act - await saveSession(); + await saveSession({}); // Assert expect(cookieHelper.getFunnelCookie().DidHeritageFunnelUpdateLast).toEqual(false); diff --git a/src/layouts/estimate/estimate.vue b/src/layouts/estimate/estimate.vue index f036277b7..dd16a479f 100644 --- a/src/layouts/estimate/estimate.vue +++ b/src/layouts/estimate/estimate.vue @@ -223,8 +223,8 @@ export default { } else if (this.$store.getters.order.referralNumber?.length === 6) { await this.navigateForwardWithSingleCarMatch(); } else if (this.isRepair) { - // call saveSession here - navigateWithSaving only saves asynchronously - await saveSession(); + // call saveSession here - navigateWithSaving saves too late in the flow + await saveSession({}); return this.$router.navigateWithoutSaving( this.navigationScenarios.CLICKED_FORWARD_WITH_NO_QUESTIONS, this.$route diff --git a/src/mixins/vin-pages-mixin.js b/src/mixins/vin-pages-mixin.js index 8815bc06d..cad998d38 100644 --- a/src/mixins/vin-pages-mixin.js +++ b/src/mixins/vin-pages-mixin.js @@ -8,7 +8,7 @@ export default { async navigateForwardWithSingleCarMatch() { // If we have not already saved a session, we need to save one now before the lengthy call to getPartsOrQuestions if (!store.getters.applicationUser.savedSessionId) { - await saveSession(); + await saveSession({}); } const result = await this.dispatchStoreAction(storeActions.GET_PARTS_OR_QUESTIONS); diff --git a/src/router/index.js b/src/router/index.js index 324cba3c7..30fc8583b 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -160,7 +160,7 @@ const router = createRouter({ //---------------------------------------------------------- Router Functions ---------------------------------------------------------- -router.afterEach((to, from) => { +router.afterEach(async (to, from) => { // Update lastPageVisited in the store store.commit(storeMutations.UPDATE_LAST_PAGE_VISITED, to.name); @@ -170,7 +170,7 @@ router.afterEach((to, from) => { store.getters.applicationUser.savedSessionId || store.getters.order.customer?.emailAddress ) { - saveSession(); + await saveSession({}); } }