From ba4191e8913e509763dd6d743700ccc7a4cb72de Mon Sep 17 00:00:00 2001 From: Jeremy Zimmerman Date: Thu, 3 Nov 2022 12:44:04 -0400 Subject: [PATCH] Updates --- src/global-methods.js | 4 +- .../heritage-integration/order-helper.js | 10 ++--- src/mixins/analytics-mixin.js | 4 +- src/mixins/analytics-mixin.spec.js | 2 +- src/mixins/base-mixin.js | 24 +++++++++-- src/router/index.js | 19 +++++---- src/store/index.js | 40 +++++++------------ 7 files changed, 60 insertions(+), 43 deletions(-) diff --git a/src/global-methods.js b/src/global-methods.js index cb111ce2..8e4c027c 100644 --- a/src/global-methods.js +++ b/src/global-methods.js @@ -1,5 +1,5 @@ import axios from "axios"; -import analyticsMixIn from "@/mixins/analytics-mixin.js"; +//import analyticsMixIn from "@/mixins/analytics-mixin.js"; import { applicationConfig } from "@/constants/application-config.js"; import { GaCategories, GaActions, GaLabels } from "@/constants/analytics"; @@ -25,12 +25,14 @@ export default { }) .then((response) => { if (logApiCall) { + /* analyticsMixIn.methods.pushEventToGA( GaCategories.API_RESPONSE, GaActions.RESULT, `${GaLabels.SUCCESS}_${endpoint}`, true ); + */ } return resolve(response); diff --git a/src/helpers/heritage-integration/order-helper.js b/src/helpers/heritage-integration/order-helper.js index db95e070..a34b7fd4 100644 --- a/src/helpers/heritage-integration/order-helper.js +++ b/src/helpers/heritage-integration/order-helper.js @@ -5,7 +5,7 @@ import { deleteFunnelCookie, } from "@/helpers/heritage-integration/cookie-helper.js"; import baseMixin from "@/mixins/base-mixin"; -import store from "@/store"; +import { useMainStore } from "@/store"; import { storeMutations } from "@/constants/store-mutations"; /* @@ -51,9 +51,9 @@ export async function loadSessionIfPresent() { */ export async function saveSession() { var saveSessionPromise; - if (store.getters.applicationUser.saveSessionPromise) { + if (useMainStore.getters.applicationUser.saveSessionPromise) { // queue newest request after current saveSessionPromise resolves - saveSessionPromise = store.getters.applicationUser.saveSessionPromise.then(() => { + saveSessionPromise = useMainStore.getters.applicationUser.saveSessionPromise.then(() => { // get a new saveSessionPromise return saveSessionHelper(); }); @@ -61,7 +61,7 @@ export async function saveSession() { // create an initial saveSessionPromise saveSessionPromise = saveSessionHelper(); } - store.commit(storeMutations.UPDATE_SAVE_SESSION_PROMISE, saveSessionPromise); + useMainStore.commit(storeMutations.UPDATE_SAVE_SESSION_PROMISE, saveSessionPromise); // await here to allow for a caller to await and make the function synchronous await saveSessionPromise; } @@ -74,7 +74,7 @@ export async function saveSession() { */ async function loadSession(referralNumber, referralDate, referralCorrelationId, accountNumber) { // await the saveSessionPromise in the store to make sure we're loading up to date information - await store.getters.applicationUser.saveSessionPromise; + await useMainStore.getters.applicationUser.saveSessionPromise; const response = await baseMixin.methods.dispatchStoreAction( storeActions.LOAD_SESSION, { diff --git a/src/mixins/analytics-mixin.js b/src/mixins/analytics-mixin.js index afadf42d..fa013c52 100644 --- a/src/mixins/analytics-mixin.js +++ b/src/mixins/analytics-mixin.js @@ -16,9 +16,10 @@ import { ValueToLogTypes, } from "@/constants/analytics"; import { cookieNames } from "@/constants/cookie-names"; -import { useMainStore } from "@/store"; +//import { useMainStore } from "@/store"; import baseMixin from "@/mixins/base-mixin"; +//import { mapStores } from "pinia"; export default { @@ -172,6 +173,7 @@ export default { }, }, computed: { + //...mapStores(useMainStore), analyticsPageEvents() { return analyticsPageEvents; }, diff --git a/src/mixins/analytics-mixin.spec.js b/src/mixins/analytics-mixin.spec.js index f421ddb6..a68c40b5 100644 --- a/src/mixins/analytics-mixin.spec.js +++ b/src/mixins/analytics-mixin.spec.js @@ -9,7 +9,7 @@ import { GaEvents, ValueToLogTypes, } from "@/constants/analytics"; -import { useMainStore } from "@/store"; +//import { useMainStore } from "@/store"; describe("analyticsMixin.js", () => { test("logPageView: calls dispatch with type and payload", () => { diff --git a/src/mixins/base-mixin.js b/src/mixins/base-mixin.js index 80e97ebc..d822046d 100644 --- a/src/mixins/base-mixin.js +++ b/src/mixins/base-mixin.js @@ -1,10 +1,11 @@ +import { useMainStore } from "@/store"; +import { mapActions, mapStores } from "pinia"; import { storeActions } from "@/constants/store-actions.js"; +import { storeMutations } from "@/constants/store-mutations.js"; import { navigationScenarios } from "@/router/router-constants/navigation-scenarios"; import { vehicleCategories } from "@/constants/vehicle-categories.js"; import { queryStrings } from "@/constants/query-strings"; import { dynamicStrings } from "@/constants/dynamic-strings"; -import { useMainStore } from "@/store"; -import { mapStores } from "pinia"; export default { data() { @@ -19,10 +20,27 @@ export default { getCmsContent(widgetName, fieldName) { return this.$root.cmsContentByWidget?.[widgetName]?.[fieldName] ? this.$root.cmsContentByWidget[widgetName][fieldName] : ''; }, + dispatchStoreAction(type, payload, encodePayload = true) { + + const store = useMainStore(); + // Encode the payload if required + if (encodePayload) { + encodeUriData(payload); + } + console.log(store); + console.log(type); + console.log(payload); + + return store[type](payload); + }, + savePageDataToStore(page, data) { + //this.mainStore.commit(storeMutations.UPDATE_PAGE_DATA, { page: page, data: data }); + }, }, computed: { // store will be accessible globally as its id + 'Store' ...mapStores(useMainStore), + storeActions() { return storeActions; }, @@ -51,4 +69,4 @@ function encodeUriData(payload) { payload[key] = encodeURIComponent(payload[key]); }); } -} +} \ No newline at end of file diff --git a/src/router/index.js b/src/router/index.js index 6c225c93..b8b4ff46 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,16 +1,20 @@ import { createWebHistory, createRouter } from "vue-router"; +import { storeActions } from "@/constants/store-actions"; +import { storeMutations } from "../constants/store-mutations"; import { lazyLoadComponent } from "@/router/dynamic-routing/component-loader"; import {issPageValues} from '@/router/router-constants/issPage-values'; import { routingTable } from "@/router/router-constants/routing-table"; import { useMainStore } from '@/store'; +import { loadSessionIfPresent, saveSession } from "@/helpers/heritage-integration/order-helper"; +import analyticsMixin from "@/mixins/analytics-mixin"; + const routes = [ { path: '/', name: 'root', async beforeEnter(to, from, next) { - try { - + try { to.query.issPage = !to.query.issPage ? issPageValues.VEHICLE_YEAR : to.query.issPage; if (router.hasRoute(to.query.issPage)) { @@ -50,9 +54,11 @@ const router = createRouter({ routes, }); -router.afterEach((to, from) => { +router.afterEach((to, from) => { + + const store = useMainStore(); // Update lastPageVisited in the store - store.commit(storeMutations.UPDATE_LAST_PAGE_VISITED, to.name); + store.updateLastPageVisited(to.name); // If saving on navigation is requested, check for saved SessionId or EmailAddress to determine if saving is appropriate if (eval(to.params.isSavingNavigation)) { @@ -71,11 +77,10 @@ router.afterEach((to, from) => { analyticsMixin.methods.pushExperimentsToDataLayer(); }); - - // 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 useMainStore().getRouteInfo(pageName); const jsonFromResponse = JSON.parse(response.data.Result); @@ -89,7 +94,7 @@ async function GetRouteInfoFromPageName(pageName) { component: lazyLoadComponent(jsonFromResponse[key].LayoutName), }); }); - + return routeData; }; diff --git a/src/store/index.js b/src/store/index.js index a97c22e9..057e845d 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -140,15 +140,13 @@ export const useMainStore = defineStore({ endpoint: endpoints.GetHomepageInfo.url(applicationConfig.APPLICATION_ABBREVIATION), }); }, - getPageData(context, { pageName }) { + + getPageData(pageName) { return globalMethods.callHttpClient({ - method: endpoints.GetPageData.method, - endpoint: endpoints.GetPageData.url( - applicationConfig.APPLICATION_ABBREVIATION, - pageName - ), - payload: {}, - }); + method: endpoints.GetPageData.method, + endpoint: endpoints.GetPageData.url(applicationConfig.APPLICATION_ABBREVIATION, pageName), + payload: {}, + }); }, // Vehicle API Actions @@ -222,7 +220,7 @@ export const useMainStore = defineStore({ }, // Analytics Actions - logExperimentExposure(context, { userId, sessionKey, pageName, experiment }) { + logExperimentExposure({ userId, sessionKey, pageName, experiment }) { return globalMethods.callHttpClient({ method: endpoints.LogExperimentExposureIfAssigned.method, endpoint: endpoints.LogExperimentExposureIfAssigned.url, @@ -245,19 +243,8 @@ export const useMainStore = defineStore({ }, }); }, - logPageView( - context, - { - userId, - sessionKey, - pageName, - sessionId, - action, - event, - shouldUseSessionId, - experimentsForUser, - } - ) { + logPageView({ userId, sessionKey, pageName, sessionId, action }) + { var payload = { userId: userId, sessionKey: sessionKey, @@ -268,8 +255,7 @@ export const useMainStore = defineStore({ event: event, shouldUseSessionId: shouldUseSessionId, experimentsForUser: experimentsForUser, - }; - + } return globalMethods.callHttpClient({ method: endpoints.LogPageView.method, endpoint: endpoints.LogPageView.url, @@ -333,7 +319,11 @@ export const useMainStore = defineStore({ }); }, - GetExperimentsByUser(context, { userId }) { + updateLastPageVisited(state, lastPageVisited) { + this.applicationUser.lastPageVisited = lastPageVisited; + }, + + GetExperimentsByUser(userId) { return globalMethods.callHttpClient({ method: endpoints.GetExperimentsByUser.method, endpoint: `${endpoints.GetExperimentsByUser.url}/${userId}`,