CSR-706 | Re-work synchronicity of saveOrder
Allow multiple saveOrders to run synchronously Allow saveOrder to be awaited before navigating to heritage Allow saveOrder to run on routine navigation if an email address is present Add saveOrderPromise member to the store
This commit is contained in:
parent
f0748c4c0b
commit
972e02a5b2
4 changed files with 40 additions and 19 deletions
|
|
@ -46,7 +46,8 @@ const storeMutations = {
|
||||||
// OTHER MUTATIONS
|
// OTHER MUTATIONS
|
||||||
UPDATE_PAGE_DATA: "updatePageData",
|
UPDATE_PAGE_DATA: "updatePageData",
|
||||||
UPDATE_STATE_WITH_ORDER_INFORMATION: "updateStateWithOrderInformation",
|
UPDATE_STATE_WITH_ORDER_INFORMATION: "updateStateWithOrderInformation",
|
||||||
UPDATE_SERVICE_LOCATION_WITH_VEHICLE_REGISTRATION: "updateServiceLocationWithVehicleRegistration"
|
UPDATE_SERVICE_LOCATION_WITH_VEHICLE_REGISTRATION: "updateServiceLocationWithVehicleRegistration",
|
||||||
|
UPDATE_SAVE_ORDER_PROMISE: "updateSaveOrderPromise",
|
||||||
};
|
};
|
||||||
|
|
||||||
export { storeMutations };
|
export { storeMutations };
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
import { storeActions } from "@/constants/store-actions.js";
|
import { storeActions } from "@/constants/store-actions.js";
|
||||||
import { getFunnelCookie, updateOrCreateFunnelCookie, deleteFunnelCookie } from "@/helpers/heritage-integration/cookie-helper.js";
|
import { getFunnelCookie, updateOrCreateFunnelCookie, deleteFunnelCookie } from "@/helpers/heritage-integration/cookie-helper.js";
|
||||||
import baseMixin from "@/mixins/base-mixin";
|
import baseMixin from "@/mixins/base-mixin";
|
||||||
|
import store from "@/store";
|
||||||
|
import { storeMutations } from "@/constants/store-mutations";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Will call API and hydrate state with data from API if present. If there is no order present
|
Will call API and hydrate state with data from API if present. If there is no order present
|
||||||
|
|
@ -34,18 +36,20 @@ export async function loadOrderIfPresent() {
|
||||||
update the cookie.
|
update the cookie.
|
||||||
*/
|
*/
|
||||||
export async function saveOrder() {
|
export async function saveOrder() {
|
||||||
const savedOrderInfo = await baseMixin.methods.dispatchStoreAction(storeActions.SAVE_ORDER);
|
var saveOrderPromise;
|
||||||
|
if (store.getters.applicationUser.saveOrderPromise) {
|
||||||
// Save the referral information back from the store.
|
// queue newest request after current saveOrderPromise resolves
|
||||||
await baseMixin.methods.dispatchStoreAction(storeActions.SET_REFERRAL_INFORMATION, {
|
saveOrderPromise = store.getters.applicationUser.saveOrderPromise.then(() => {
|
||||||
referralNumber: savedOrderInfo.data.referralNumber.toString(),
|
// get a new saveOrderPromise
|
||||||
referralCorrelationId: savedOrderInfo.data.referralCorrelationId,
|
return saveOrderHelper();
|
||||||
referralDate: savedOrderInfo.data.referralDate,
|
});
|
||||||
accountNumber: savedOrderInfo.data.accountNumber.toString()
|
} else {
|
||||||
}, false);
|
// create an initial saveOrderPromise
|
||||||
|
saveOrderPromise = saveOrderHelper();
|
||||||
// Update the cookie with the referral information when saved.
|
}
|
||||||
updateOrCreateFunnelCookie();
|
store.commit(storeMutations.UPDATE_SAVE_ORDER_PROMISE, saveOrderPromise);
|
||||||
|
// await here to allow for a caller to await and make the function synchronous
|
||||||
|
await saveOrderPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -65,4 +69,17 @@ async function loadOrder(referralNumber, referralDate, referralCorrelationId, ac
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
}
|
||||||
|
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, {
|
||||||
|
referralNumber: savedOrderInfo.data.referralNumber.toString(),
|
||||||
|
referralCorrelationId: savedOrderInfo.data.referralCorrelationId,
|
||||||
|
referralDate: savedOrderInfo.data.referralDate,
|
||||||
|
accountNumber: savedOrderInfo.data.accountNumber.toString()
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
// Update the cookie with the referral information when saved.
|
||||||
|
updateOrCreateFunnelCookie();
|
||||||
}
|
}
|
||||||
|
|
@ -177,9 +177,9 @@ async function navigate(scenario, currentRoute, invalidateOnSave, optionalQuery
|
||||||
// Append page data to the store for the NEXT page, if any. It will be an empty object if none is provided.
|
// Append page data to the store for the NEXT page, if any. It will be an empty object if none is provided.
|
||||||
baseMixin.methods.savePageDataToStore(destinationFmgPageValue, optionalPageData);
|
baseMixin.methods.savePageDataToStore(destinationFmgPageValue, optionalPageData);
|
||||||
|
|
||||||
// if cookie and referralNumber/Date exists
|
// if cookie and referralNumber/Date exists OR an emailAddress has been saved
|
||||||
if (getFunnelCookie()?.ReferralNumber && getFunnelCookie()?.ReferralDate) {
|
if ((getFunnelCookie()?.ReferralNumber && getFunnelCookie()?.ReferralDate) || store.getters.customer.emailAddress) {
|
||||||
await saveOrder();
|
saveOrder();
|
||||||
}
|
}
|
||||||
|
|
||||||
router.push({
|
router.push({
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,8 @@ const getDefaultState = () => {
|
||||||
applicationUser: {
|
applicationUser: {
|
||||||
eventBus: [],
|
eventBus: [],
|
||||||
pageData: {},
|
pageData: {},
|
||||||
savedSessionTimeout: getDateForSavedSessionTimeout()
|
savedSessionTimeout: getDateForSavedSessionTimeout(),
|
||||||
|
saveOrderPromise: null,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -166,7 +167,6 @@ export const mutations = {
|
||||||
state.order.customer.emailAddress = customerEmailAddress;
|
state.order.customer.emailAddress = customerEmailAddress;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// EVENT BUS MUTATIONS
|
// EVENT BUS MUTATIONS
|
||||||
addEventToBus(state, event) {
|
addEventToBus(state, event) {
|
||||||
state.applicationUser.eventBus.push(event);
|
state.applicationUser.eventBus.push(event);
|
||||||
|
|
@ -269,7 +269,10 @@ export const mutations = {
|
||||||
state.order.serviceLocation.city = state.order.vehicle.registration.city;
|
state.order.serviceLocation.city = state.order.vehicle.registration.city;
|
||||||
state.order.serviceLocation.state = state.order.vehicle.registration.state;
|
state.order.serviceLocation.state = state.order.vehicle.registration.state;
|
||||||
state.order.serviceLocation.zipCode = state.order.vehicle.registration.zipCode;
|
state.order.serviceLocation.zipCode = state.order.vehicle.registration.zipCode;
|
||||||
}
|
},
|
||||||
|
updateSaveOrderPromise(state, saveOrderPromise){
|
||||||
|
state.applicationUser.saveOrderPromise = saveOrderPromise;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export Getters
|
// Export Getters
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue