Updated logic for initial savesession call to create referral. Move it to beforeEach to make it snchronous.
This commit is contained in:
parent
0eaf8ab2a8
commit
db1222a53e
3 changed files with 19 additions and 4 deletions
|
|
@ -26,6 +26,7 @@ export async function saveSession({ shouldAwaitSaveSessionQueue = false, submitA
|
||||||
|
|
||||||
// This should await anytime the referral number is not set, or the shouldAwaitSaveSessionQueue is set to true.
|
// This should await anytime the referral number is not set, or the shouldAwaitSaveSessionQueue is set to true.
|
||||||
if (!store.order.referralNumber || shouldAwaitSaveSessionQueue) {
|
if (!store.order.referralNumber || shouldAwaitSaveSessionQueue) {
|
||||||
|
console.log('Awaiting save session promise', store.order.referralNumber, shouldAwaitSaveSessionQueue);
|
||||||
await saveSessionPromise;
|
await saveSessionPromise;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -155,6 +155,19 @@ router.beforeEach(async (to, from) => {
|
||||||
showIssLoadingModal(true);
|
showIssLoadingModal(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const callSaveSession = (to.name === issPageValues.VEHICLE_SELECTION || to.name === issPageValues.POLICY_VEHICLES);
|
||||||
|
if ( callSaveSession ) {
|
||||||
|
// Forcing a synchronous savesession call here to create the referral for the first time.
|
||||||
|
// AfterEach does not support synchronous calls that block navigation. Which is why this is in the beforeEach method.
|
||||||
|
// This only needs to be called once in a certain location, all other saveession calls are async in afterEach (except the last one on order submission)
|
||||||
|
// NOTE: This call should be creating the referral number. After this point in the site flow, referral number is critical for several pieces of logic and logging.
|
||||||
|
// Thereforce, we want to force a bailout here if it errors out.
|
||||||
|
console.log('Saving session with waiting coming from duplicate check page.');
|
||||||
|
showIssLoadingModal(true);
|
||||||
|
await saveSession({ shouldAwaitSaveSessionQueue: true,bailoutOnError: true });
|
||||||
|
showIssLoadingModal(false);
|
||||||
|
}
|
||||||
|
|
||||||
const toQueryPage = to.query?.issPage;
|
const toQueryPage = to.query?.issPage;
|
||||||
const notToPayInAdvanceReturn = toQueryPage !== issPageValues.PAYMENT_RETURN;
|
const notToPayInAdvanceReturn = toQueryPage !== issPageValues.PAYMENT_RETURN;
|
||||||
const isInIframe = window !== window.top || fromQueryPage === issPageValues.PAYMENT_PAGE;
|
const isInIframe = window !== window.top || fromQueryPage === issPageValues.PAYMENT_PAGE;
|
||||||
|
|
@ -204,10 +217,11 @@ router.afterEach(async (to, from) => {
|
||||||
to.state?.[routerParams.SKIP_SAVE_SESSION]
|
to.state?.[routerParams.SKIP_SAVE_SESSION]
|
||||||
?? router.options.history.state?.[routerParams.SKIP_SAVE_SESSION]
|
?? router.options.history.state?.[routerParams.SKIP_SAVE_SESSION]
|
||||||
);
|
);
|
||||||
if (from.name !== undefined && !skipSaveSession && !store.hasSubmittedOrder()) {
|
|
||||||
await saveSession({ bailoutOnError: from.name === issPageValues.ENTRY_PAGE});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (from.name !== undefined && !skipSaveSession && !store.hasSubmittedOrder()) {
|
||||||
|
await saveSession({ bailoutOnError: false});
|
||||||
|
}
|
||||||
|
|
||||||
document.title = routerTitles[to.query.issPage] || 'Safelite Solutions®';
|
document.title = routerTitles[to.query.issPage] || 'Safelite Solutions®';
|
||||||
|
|
||||||
if (shouldRunExperiments) {
|
if (shouldRunExperiments) {
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,6 @@ describe('Router afterEach skipSaveSession', () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(saveSession).toHaveBeenCalledTimes(1);
|
expect(saveSession).toHaveBeenCalledTimes(1);
|
||||||
expect(saveSession).toHaveBeenCalledWith({ bailoutOnError: true });
|
expect(saveSession).toHaveBeenCalledWith({ bailoutOnError: false });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Loading…
Reference in a new issue