Merge branch 'release/cms-fix' into rlsmerge/cms-fix-to-2024.01.11
This commit is contained in:
commit
adc1f1cbb7
6 changed files with 35 additions and 87 deletions
|
|
@ -1,14 +1,4 @@
|
|||
const endpoints = {
|
||||
GetRouteInfo: {
|
||||
url: (applicationAbbreviation) =>
|
||||
`/content/api/v1/content/${applicationAbbreviation}/RouteInfo`,
|
||||
method: "POST",
|
||||
},
|
||||
GetHomepageInfo: {
|
||||
url: (applicationAbbreviation) =>
|
||||
`/content/api/v1/content/${applicationAbbreviation}/HomepageInfo`,
|
||||
method: "GET",
|
||||
},
|
||||
GetPageData: {
|
||||
url: (applicationAbbreviation, pageName) =>
|
||||
`/content/api/v1/content/${applicationAbbreviation}/${pageName}`,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
const storeActions = {
|
||||
// Content Actions
|
||||
GET_ROUTE_INFO_ACTION: "getRouteInfo",
|
||||
GET_HOMEPAGE_NAME: "getHomepageName",
|
||||
GET_PAGE_DATA: "getPageData",
|
||||
|
||||
// Vehicle Actions
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import { queryStrings } from "@/constants/query-strings";
|
|||
import { getQuerystringParameter } from "@/helpers/querystring-helper";
|
||||
import { getDeviceIdValue } from "@/helpers/heritage-integration/cookie-helper";
|
||||
import { showFmgLoadingModal } from "@/helpers/loading-modal-helper";
|
||||
import { fmgPageValues, homepageName } from "@/router/router-constants/fmgPage-values";
|
||||
|
||||
// Heritage integration
|
||||
import { isSavedSessionStillActive } from "@/helpers/heritage-integration/session-helper";
|
||||
|
|
@ -48,13 +49,13 @@ const routes = [
|
|||
// If the saved session has timed out, clear the session, execute 404 logic.
|
||||
if (getFunnelCookie() !== null && !isSavedSessionStillActive()) {
|
||||
await baseMixin.methods.dispatchStoreAction(storeActions.RESET_STATE);
|
||||
await GoToFunnelStartOn404(next);
|
||||
GoToFunnelStartOn404(next);
|
||||
}
|
||||
|
||||
// Intercept all navigation if a submitted order exists in storage
|
||||
if (store.getters.hasSubmittedOrder) {
|
||||
if (to.query.fmgPage !== "vehicle") {
|
||||
to.query.fmgPage = "confirmation";
|
||||
if (to.query.fmgPage !== homepageName) {
|
||||
to.query.fmgPage = fmgPageValues.CONFIRMATION;
|
||||
}
|
||||
}
|
||||
// On entering the funnel "fresh", read cookie information, decide what to do next.
|
||||
|
|
@ -100,14 +101,18 @@ const routes = [
|
|||
}
|
||||
|
||||
if (!arePagePrerequisitesValid(component)) {
|
||||
await GoToFunnelStartOn404(next);
|
||||
GoToFunnelStartOn404(next);
|
||||
}
|
||||
|
||||
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.
|
||||
const routeData = await GetRouteInfoFromPageName(to.query.fmgPage);
|
||||
const routeData = GetRouteInfoFromPageName(to.query.fmgPage);
|
||||
|
||||
// Add our dynamic route.
|
||||
router.addRoute({
|
||||
|
|
@ -124,7 +129,7 @@ const routes = [
|
|||
.components.default();
|
||||
|
||||
if (!arePagePrerequisitesValid(nextComponent)) {
|
||||
await GoToFunnelStartOn404(next);
|
||||
GoToFunnelStartOn404(next);
|
||||
}
|
||||
|
||||
// Assign current query string parameters, as well as our fmgPage one.
|
||||
|
|
@ -137,7 +142,7 @@ const routes = [
|
|||
console.log(error);
|
||||
|
||||
// If we don't have a route, go to our 404 page.
|
||||
await GoToFunnelStartOn404(next);
|
||||
GoToFunnelStartOn404(next);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
@ -175,7 +180,7 @@ router.beforeEach(async (to, from, next) => {
|
|||
// Refresh page if navigating to self to prevent locking.
|
||||
// For now only carved out for vehicle; all modals are opened through anchor tags at the moment,
|
||||
// which also self navigate, but relied on the page remaining the same on self-navigation.
|
||||
} else if (toQueryPage === fromQueryPage && toQueryPage === "vehicle") {
|
||||
} else if (toQueryPage === fromQueryPage && toQueryPage === homepageName) {
|
||||
router.go(0);
|
||||
} else {
|
||||
next();
|
||||
|
|
@ -355,31 +360,26 @@ function navigateToUrl(url, optionalQuery = {}) {
|
|||
}
|
||||
|
||||
// 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.
|
||||
async function GetRouteInfoFromPageName(pageName) {
|
||||
const response = await store.dispatch(storeActions.GET_ROUTE_INFO_ACTION, {
|
||||
pageName: pageName,
|
||||
});
|
||||
const jsonFromResponse = JSON.parse(response.data.Result);
|
||||
let routeData = [];
|
||||
// This will no longer reach out to the Cms. There is a 1:1 relationship between page names and route names and layouts.
|
||||
function GetRouteInfoFromPageName(pageName) {
|
||||
// check if pagename is a valid route/component
|
||||
if (!isExistingFmgPageName(pageName)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Add our route data and return our array.
|
||||
Object.keys(jsonFromResponse).forEach((key) => {
|
||||
routeData.push({
|
||||
const routeData = [
|
||||
{
|
||||
path: "/",
|
||||
name: `${key}`,
|
||||
component: lazyLoadComponent(jsonFromResponse[key].LayoutName),
|
||||
});
|
||||
});
|
||||
name: pageName,
|
||||
component: lazyLoadComponent(pageName),
|
||||
},
|
||||
];
|
||||
|
||||
return routeData;
|
||||
}
|
||||
|
||||
// Go to our start page on a 404.
|
||||
async function GoToFunnelStartOn404(next) {
|
||||
const apiResponse = await store.dispatch(storeActions.GET_HOMEPAGE_NAME);
|
||||
const homepageName = apiResponse.data.Result;
|
||||
|
||||
function GoToFunnelStartOn404(next) {
|
||||
// Put item on the bus
|
||||
eventBus.addEventToBus(
|
||||
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.
|
||||
function arePagePrerequisitesValid(component) {
|
||||
return component.default.methods.arePagePrerequisitesValid();
|
||||
|
|
|
|||
|
|
@ -22,4 +22,6 @@ const fmgPageValues = {
|
|||
CONFIRMATION: "confirmation",
|
||||
};
|
||||
|
||||
export { fmgPageValues };
|
||||
const homepageName = fmgPageValues.VEHICLE;
|
||||
|
||||
export { fmgPageValues, homepageName };
|
||||
|
|
|
|||
|
|
@ -956,26 +956,6 @@ export const actions = {
|
|||
context.commit(storeMutations.RESET_SAVE_SESSION_PROMISE);
|
||||
},
|
||||
|
||||
// Content API Actions
|
||||
getRouteInfo(context, { pageName }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetRouteInfo.method,
|
||||
endpoint: endpoints.GetRouteInfo.url(applicationConfig.APPLICATION_ABBREVIATION),
|
||||
payload: {
|
||||
pageName: pageName,
|
||||
},
|
||||
logApiCall: true,
|
||||
pageNameToLog: pageName,
|
||||
});
|
||||
},
|
||||
|
||||
getHomepageName(context) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetHomepageInfo.method,
|
||||
endpoint: endpoints.GetHomepageInfo.url(applicationConfig.APPLICATION_ABBREVIATION),
|
||||
});
|
||||
},
|
||||
|
||||
getPageData(context, { pageName }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetPageData.method,
|
||||
|
|
|
|||
|
|
@ -659,34 +659,6 @@ describe("Actions", () => {
|
|||
expect(commit).toBeCalledWith(storeMutations.RESET_STATE);
|
||||
});
|
||||
|
||||
it("getRouteInfo action, returns route info", async () => {
|
||||
// Arrange
|
||||
const context = state;
|
||||
|
||||
globalMethods.callHttpClient.mockImplementation(() => {
|
||||
return Promise.resolve({ data: { Widget: "Data" } });
|
||||
});
|
||||
|
||||
// Act
|
||||
const response = await actions.getRouteInfo(context, "vehicle-year");
|
||||
|
||||
expect(response.data).toEqual({ Widget: "Data" });
|
||||
});
|
||||
|
||||
it("getHomepageName action, returns homepage name", async () => {
|
||||
// Arrange
|
||||
const context = state;
|
||||
|
||||
globalMethods.callHttpClient.mockImplementation(() => {
|
||||
return Promise.resolve({ data: { Name: "vehicle-year" } });
|
||||
});
|
||||
|
||||
// Act
|
||||
const response = await actions.getHomepageName(context);
|
||||
|
||||
expect(response.data).toEqual({ Name: "vehicle-year" });
|
||||
});
|
||||
|
||||
it("getPageData action, returns page data", async () => {
|
||||
// Arrange
|
||||
const context = state;
|
||||
|
|
|
|||
Loading…
Reference in a new issue