Merge pull request #1652 from Safelite/rlsmerge/cms-fix-to-2024.01.11

Rlsmerge/cms fix to 2024.01.11
This commit is contained in:
chloeherdsafelite 2023-12-20 13:03:22 -05:00 committed by GitHub
commit 3ccca9bde9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 87 deletions

View file

@ -1,14 +1,4 @@
const endpoints = { 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: { GetPageData: {
url: (applicationAbbreviation, pageName) => url: (applicationAbbreviation, pageName) =>
`/content/api/v1/content/${applicationAbbreviation}/${pageName}`, `/content/api/v1/content/${applicationAbbreviation}/${pageName}`,

View file

@ -1,7 +1,5 @@
const storeActions = { const storeActions = {
// Content Actions // Content Actions
GET_ROUTE_INFO_ACTION: "getRouteInfo",
GET_HOMEPAGE_NAME: "getHomepageName",
GET_PAGE_DATA: "getPageData", GET_PAGE_DATA: "getPageData",
// Vehicle Actions // Vehicle Actions

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,13 +49,13 @@ 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
if (store.getters.hasSubmittedOrder) { if (store.getters.hasSubmittedOrder) {
if (to.query.fmgPage !== "vehicle") { if (to.query.fmgPage !== homepageName) {
to.query.fmgPage = "confirmation"; to.query.fmgPage = fmgPageValues.CONFIRMATION;
} }
} }
// On entering the funnel "fresh", read cookie information, decide what to do next. // On entering the funnel "fresh", read cookie information, decide what to do next.
@ -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);
} }
}, },
}, },
@ -175,7 +180,7 @@ router.beforeEach(async (to, from, next) => {
// Refresh page if navigating to self to prevent locking. // 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, // 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. // 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); router.go(0);
} else { } else {
next(); 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 };

View file

@ -956,26 +956,6 @@ export const actions = {
context.commit(storeMutations.RESET_SAVE_SESSION_PROMISE); 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 }) { getPageData(context, { pageName }) {
return globalMethods.callHttpClient({ return globalMethods.callHttpClient({
method: endpoints.GetPageData.method, method: endpoints.GetPageData.method,

View file

@ -659,34 +659,6 @@ describe("Actions", () => {
expect(commit).toBeCalledWith(storeMutations.RESET_STATE); 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 () => { it("getPageData action, returns page data", async () => {
// Arrange // Arrange
const context = state; const context = state;