Remove calls to RouteInfo and GetHomePage in router.

This commit is contained in:
Chloe Herd 2023-12-18 15:25:38 -05:00
parent 438e63e780
commit 0998285fd8
2 changed files with 32 additions and 24 deletions

View file

@ -9,6 +9,7 @@ import { queryStrings } from "@/constants/query-strings";
import { getQuerystringParameter } from "@/helpers/querystring-helper"; import { getQuerystringParameter } from "@/helpers/querystring-helper";
import { getDeviceIdValue } from "@/helpers/heritage-integration/cookie-helper"; import { getDeviceIdValue } from "@/helpers/heritage-integration/cookie-helper";
import { showFmgLoadingModal } from "@/helpers/loading-modal-helper"; import { showFmgLoadingModal } from "@/helpers/loading-modal-helper";
import { fmgPageValues, homepageName } from "@/router/router-constants/fmgPage-values";
// Heritage integration // Heritage integration
import { isSavedSessionStillActive } from "@/helpers/heritage-integration/session-helper"; import { isSavedSessionStillActive } from "@/helpers/heritage-integration/session-helper";
@ -48,7 +49,7 @@ const routes = [
// If the saved session has timed out, clear the session, execute 404 logic. // If the saved session has timed out, clear the session, execute 404 logic.
if (getFunnelCookie() !== null && !isSavedSessionStillActive()) { if (getFunnelCookie() !== null && !isSavedSessionStillActive()) {
await baseMixin.methods.dispatchStoreAction(storeActions.RESET_STATE); await baseMixin.methods.dispatchStoreAction(storeActions.RESET_STATE);
await GoToFunnelStartOn404(next); GoToFunnelStartOn404(next);
} }
// Intercept all navigation if a submitted order exists in storage // Intercept all navigation if a submitted order exists in storage
@ -100,14 +101,18 @@ const routes = [
} }
if (!arePagePrerequisitesValid(component)) { if (!arePagePrerequisitesValid(component)) {
await GoToFunnelStartOn404(next); GoToFunnelStartOn404(next);
} }
return next({ name: to.query.fmgPage, query: to.query, params: to.params }); return next({ name: to.query.fmgPage, query: to.query, params: to.params });
} }
if (!isExistingFmgPageName(to.query.fmgPage)) {
GoToFunnelStartOn404(next);
}
// Get route info for the given url. Names will have a 1:1 relationship with names in the Cms. // Get route info for the given url. Names will have a 1:1 relationship with names in the Cms.
const routeData = await GetRouteInfoFromPageName(to.query.fmgPage); const routeData = GetRouteInfoFromPageName(to.query.fmgPage);
// Add our dynamic route. // Add our dynamic route.
router.addRoute({ router.addRoute({
@ -124,7 +129,7 @@ const routes = [
.components.default(); .components.default();
if (!arePagePrerequisitesValid(nextComponent)) { if (!arePagePrerequisitesValid(nextComponent)) {
await GoToFunnelStartOn404(next); GoToFunnelStartOn404(next);
} }
// Assign current query string parameters, as well as our fmgPage one. // Assign current query string parameters, as well as our fmgPage one.
@ -137,7 +142,7 @@ const routes = [
console.log(error); console.log(error);
// If we don't have a route, go to our 404 page. // If we don't have a route, go to our 404 page.
await GoToFunnelStartOn404(next); GoToFunnelStartOn404(next);
} }
}, },
}, },
@ -355,31 +360,26 @@ function navigateToUrl(url, optionalQuery = {}) {
} }
// Get route information by page name. // Get route information by page name.
// This will reach out to the Cms and there is a 1:1 relationship between page names and route names. // This will no longer reach out to the Cms. There is a 1:1 relationship between page names and route names and layouts.
async function GetRouteInfoFromPageName(pageName) { function GetRouteInfoFromPageName(pageName) {
const response = await store.dispatch(storeActions.GET_ROUTE_INFO_ACTION, { // check if pagename is a valid route/component
pageName: pageName, if (!isExistingFmgPageName(pageName)) {
}); return [];
const jsonFromResponse = JSON.parse(response.data.Result); }
let routeData = [];
// Add our route data and return our array. const routeData = [
Object.keys(jsonFromResponse).forEach((key) => { {
routeData.push({
path: "/", path: "/",
name: `${key}`, name: pageName,
component: lazyLoadComponent(jsonFromResponse[key].LayoutName), component: lazyLoadComponent(pageName),
}); },
}); ];
return routeData; return routeData;
} }
// Go to our start page on a 404. // Go to our start page on a 404.
async function GoToFunnelStartOn404(next) { function GoToFunnelStartOn404(next) {
const apiResponse = await store.dispatch(storeActions.GET_HOMEPAGE_NAME);
const homepageName = apiResponse.data.Result;
// Put item on the bus // Put item on the bus
eventBus.addEventToBus( eventBus.addEventToBus(
globalEvents.Categories.GLOBAL_ALERT, globalEvents.Categories.GLOBAL_ALERT,
@ -398,6 +398,12 @@ async function GoToFunnelStartOn404(next) {
}); });
} }
function isExistingFmgPageName(pageName) {
const names = Object.values(fmgPageValues);
return names.some((name) => name === pageName);
}
// Checks arePagePrerequisitesValid on the component passed in. // Checks arePagePrerequisitesValid on the component passed in.
function arePagePrerequisitesValid(component) { function arePagePrerequisitesValid(component) {
return component.default.methods.arePagePrerequisitesValid(); return component.default.methods.arePagePrerequisitesValid();

View file

@ -22,4 +22,6 @@ const fmgPageValues = {
CONFIRMATION: "confirmation", CONFIRMATION: "confirmation",
}; };
export { fmgPageValues }; const homepageName = fmgPageValues.VEHICLE;
export { fmgPageValues, homepageName };