conditional logging in router

conditional logging in router
This commit is contained in:
CarlNation 2024-11-14 15:49:08 -05:00
parent 3928fac0d0
commit 870a4ea45a

View file

@ -50,15 +50,32 @@ const routes = [
async beforeEnter(to, from, next) {
// If we have no query string, or we don't have the FmgPage query string.
try {
const log = getQuerystringParameter(queryStrings.LOG);
if (eval(log)) {
// prettier-ignore
console.log("------------- router index.js beforeEnter start -----------------");
console.log(new Date() + " --to: " + JSON.stringify(to));
console.log(new Date() + " --from: " + JSON.stringify(from));
console.log(new Date() + " --next: " + JSON.stringify(next));
console.log(new Date() + " --cookie: " + JSON.stringify(getFunnelCookie()));
}
await analyticsMixin.methods.validateSession();
if (getFunnelCookie()?.SuppressConceptFunnel) {
if (eval(log)) {
console.log(new Date() + " --go to heritage suppressConceptFunnel: ");
}
await navigateToHeritageFunnel({ shouldSaveSession: false });
return next(false);
}
// If the saved session has timed out, clear the session, execute 404 logic.
if (getFunnelCookie() !== null && !isSavedSessionStillActive()) {
if (eval(log)) {
console.log(new Date() + " --save session timeout go to start");
}
await baseMixin.methods.dispatchStoreAction(storeActions.RESET_STATE);
deleteFunnelCookie();
GoToFunnelStartOn404(next);
@ -68,6 +85,9 @@ const routes = [
if (window.sessionStorage.getItem("submittedOrder") !== null) {
if (to.query.fmgPage !== funnelStartPageName) {
to.query.fmgPage = fmgPageValues.CONFIRMATION;
if (eval(log)) {
console.log(new Date() + " --has submittedOrder go to confirmation");
}
}
}
// On entering the funnel "fresh", read cookie information, decide what to do next.
@ -130,12 +150,20 @@ const routes = [
// This logic may determine that the user should be sent to heritage -- if so, do that here.
if (pageToRedirectTo === fmgPageValues.HERITAGE) {
if (eval(log)) {
// prettier-ignore
console.log(new Date() + " --go to heritage pageToRedirectTo " + JSON.stringify(pageToRedirectTo));
}
await navigateToHeritageFunnel({ shouldSaveSession: false });
return next(false);
}
// Assign our fmgPage so it will load normally like the other pages.
to.query.fmgPage = pageToRedirectTo;
if (eval(log)) {
// prettier-ignore
console.log(new Date() + " --assign to: " + JSON.stringify(pageToRedirectTo));
}
}
}
@ -150,6 +178,10 @@ const routes = [
to.query.fmgPage === fmgPageValues.INSURANCE_COMPANY
) {
// Push to heritage if going to quote & integrated.
if (eval(log)) {
// prettier-ignore
console.log(new Date() + " --block quote for integrated - go to heritage");
}
await navigateToHeritageFunnel({ shouldSaveSession: false });
return next(false);
}
@ -183,6 +215,9 @@ const routes = [
GoToFunnelStartOn404(next);
}
if (eval(log)) {
console.log(new Date() + " --has route:" + to.query.fmgPage);
}
return next({ name: to.query.fmgPage, query: to.query, params: to.params });
}
@ -216,6 +251,10 @@ const routes = [
GoToFunnelStartOn404(next);
}
if (eval(log)) {
console.log("------------- router index.js beforeEnter end -----------------");
}
// Assign current query string parameters, as well as our fmgPage one.
next({
name: routeData[0].name,
@ -230,6 +269,8 @@ const routes = [
await baseMixin.methods.dispatchStoreAction(storeActions.RESET_STATE);
}
console.log(new Date() + " Exception in beforeEnter:" + JSON.stringify(error));
// If we don't have a route, go to our 404 page.
GoToFunnelStartOn404(next);
}
@ -443,6 +484,17 @@ async function navigate(
const pageError = getQuerystringParameter(queryStrings.PAGE_ERROR);
const log = getQuerystringParameter(queryStrings.LOG);
if (eval(log)) {
console.log("------------- router index.js navigate start -----------------");
console.log(new Date() + " --scenario: " + scenario);
console.log(new Date() + " --currentRoute: " + JSON.stringify(currentRoute));
console.log(new Date() + " --isSavingNavigation: " + isSavingNavigation);
console.log(new Date() + " --optionalQuery: " + JSON.stringify(optionalQuery));
console.log(new Date() + " --optionalParams: " + JSON.stringify(optionalParams));
console.log(new Date() + " --optionalPageData: " + JSON.stringify(optionalPageData));
console.log(new Date() + " --nextPageName: " + nextPageName);
}
if (
hasZip &&
(store.getters.order.serviceLocation.zipCode === undefined ||
@ -465,6 +517,11 @@ async function navigate(
queryStringsObject[queryStrings.LOG] = log;
}
if (eval(log)) {
console.log(new Date() + "querystrings: " + JSON.stringify(queryStringsObject));
console.log("------------- router index.js navigate end -----------------");
}
router.push({
name: "root",
query: Object.assign(optionalQuery, queryStringsObject),