From 3b8b86fe7e365d04c5b9e859db167e1bb945645e Mon Sep 17 00:00:00 2001 From: Scott Kiener Date: Wed, 29 Jun 2022 09:05:02 -0400 Subject: [PATCH] CSR-700 | Save response from SaveOrder to VueX Store --- src/constants/store-actions.js | 2 +- src/constants/store-mutations.js | 2 ++ .../heritage-integration/order-helper.js | 12 ++++++++--- src/router/index.js | 2 +- src/store/index.js | 20 +++++++++++++++---- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/constants/store-actions.js b/src/constants/store-actions.js index 0ac79ac28..a172e79cc 100644 --- a/src/constants/store-actions.js +++ b/src/constants/store-actions.js @@ -16,7 +16,7 @@ const storeActions = { GET_PARTS_OR_QUESTIONS: "getPartsOrQuestions", SAVE_ORDER: "saveOrder", LOAD_ORDER: "loadOrder", - SET_REFERRAL_INFORMATION: "setReferralInformation", + UPDATE_STORE_WITH_SAVE_ORDER_RESPONSE: "updateStoreWithSaveOrderResponse", VALIDATE_ZIP: "validateZip", LOG_EXPERIMENT_EXPOSURE: "logExperimentExposure", LOG_PAGE_VIEW: "logPageView", diff --git a/src/constants/store-mutations.js b/src/constants/store-mutations.js index bbd6fc818..188094177 100644 --- a/src/constants/store-mutations.js +++ b/src/constants/store-mutations.js @@ -31,6 +31,8 @@ const storeMutations = { UPDATE_REFERRAL_DATE: "updateReferralDate", UPDATE_REFERRAL_CORRELATION_ID: "updateReferralCorrelationId", UPDATE_PARENT_ACCT_NUMBER: "updateParentAcctNumber", + UPDATE_SAVE_QUOTE_ID: "updateSaveQuoteId", + UPDATE_CRM_CUSTOMER_ID: "updateCrmCustomerId", // EVENT BUS MUTATIONS ADD_EVENT_TO_BUS: "addEventToBus", diff --git a/src/helpers/heritage-integration/order-helper.js b/src/helpers/heritage-integration/order-helper.js index af672f7cd..9722744f0 100644 --- a/src/helpers/heritage-integration/order-helper.js +++ b/src/helpers/heritage-integration/order-helper.js @@ -70,14 +70,20 @@ async function loadOrder(referralNumber, referralDate, referralCorrelationId, ac return response; } + +/* + Encapsulates asynchronous Save Order logic inside a promise to allow for Save Order queuing +*/ async function saveOrderHelper() { const savedOrderInfo = await baseMixin.methods.dispatchStoreAction(storeActions.SAVE_ORDER); - // Save the referral information back from the store. - await baseMixin.methods.dispatchStoreAction(storeActions.SET_REFERRAL_INFORMATION, { + // Update the store with information received from the saveOrder response + await baseMixin.methods.dispatchStoreAction(storeActions.UPDATE_STORE_WITH_SAVE_ORDER_RESPONSE, { referralNumber: savedOrderInfo.data.referralNumber.toString(), referralCorrelationId: savedOrderInfo.data.referralCorrelationId, referralDate: savedOrderInfo.data.referralDate, - accountNumber: savedOrderInfo.data.accountNumber.toString() + accountNumber: savedOrderInfo.data.accountNumber.toString(), + saveQuoteId: savedOrderInfo.data.saveQuoteId, + crmCustomerId: savedOrderInfo.data.crmCustomerId.toString(), }, false); // Update the cookie with the referral information when saved. diff --git a/src/router/index.js b/src/router/index.js index e0b789f81..2d2019cd4 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -163,7 +163,7 @@ async function navigate(scenario, currentRoute, invalidateOnSave, optionalQuery baseMixin.methods.savePageDataToStore(destinationFmgPageValue, optionalPageData); // if cookie and referralNumber/Date exists OR an emailAddress has been saved - if ((getFunnelCookie()?.ReferralNumber && getFunnelCookie()?.ReferralDate) || store.getters.customer.emailAddress) { + if ((getFunnelCookie()?.ReferralNumber && getFunnelCookie()?.ReferralDate) || store.getters.order.customer?.emailAddress) { saveOrder(); } diff --git a/src/store/index.js b/src/store/index.js index 52b373aaa..c0e67a1e6 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -64,6 +64,8 @@ const getDefaultState = () => { pageData: {}, savedSessionTimeout: getDateForSavedSessionTimeout(), saveOrderPromise: null, + saveQuoteId: null, + crmCustomerId: null }, } }; @@ -167,6 +169,16 @@ export const mutations = { state.order.customer.emailAddress = customerEmailAddress; }, + // applicationUser MUTATIONS + updateSaveOrderPromise(state, saveOrderPromise){ + state.applicationUser.saveOrderPromise = saveOrderPromise; + }, + updateSaveQuoteId(state, saveQuoteId) { + state.applicationUser.saveQuoteId = saveQuoteId; + }, + updateCrmCustomerId(state, crmCustomerId) { + state.applicationUser.crmCustomerId = crmCustomerId; + }, // EVENT BUS MUTATIONS addEventToBus(state, event) { state.applicationUser.eventBus.push(event); @@ -270,9 +282,6 @@ export const mutations = { state.order.serviceLocation.state = state.order.vehicle.registration.state; state.order.serviceLocation.zipCode = state.order.vehicle.registration.zipCode; }, - updateSaveOrderPromise(state, saveOrderPromise){ - state.applicationUser.saveOrderPromise = saveOrderPromise; - }, } // Export Getters @@ -447,10 +456,13 @@ export const actions = { }, // Misc Actions - setReferralInformation(context, { referralNumber, referralDate, referralCorrelationId }) { + updateStoreWithSaveOrderResponse(context, { referralNumber, referralDate, referralCorrelationId, accountNumber, saveQuoteId, crmCustomerId }) { context.commit(storeMutations.UPDATE_REFERRAL_NUMBER, referralNumber); context.commit(storeMutations.UPDATE_REFERRAL_DATE, referralDate); context.commit(storeMutations.UPDATE_REFERRAL_CORRELATION_ID, referralCorrelationId); + context.commit(storeMutations.UPDATE_PARENT_ACCT_NUMBER, accountNumber); + context.commit(storeMutations.UPDATE_SAVE_QUOTE_ID, saveQuoteId); + context.commit(storeMutations.UPDATE_CRM_CUSTOMER_ID, crmCustomerId); }, updateServiceLocationWithVehicleRegistration(context) { context.commit(storeMutations.UPDATE_SERVICE_LOCATION_WITH_VEHICLE_REGISTRATION);