From d1fb7db451ffef37b840c62c06aebc7c37b86b7b Mon Sep 17 00:00:00 2001 From: Katie Date: Fri, 11 Mar 2022 12:22:35 -0500 Subject: [PATCH] CSR-98 Read cookie values and remove as needed --- src/constants/store-actions.js | 1 + src/constants/store-mutations.js | 1 + src/mixins/base-mixin.js | 25 ++++--- src/router/index.js | 24 ++++++- src/router/router-constants/routing-table.js | 5 +- src/store/index.js | 68 +++++++++++--------- 6 files changed, 80 insertions(+), 44 deletions(-) diff --git a/src/constants/store-actions.js b/src/constants/store-actions.js index e5d57cdf1..84ecf77e6 100644 --- a/src/constants/store-actions.js +++ b/src/constants/store-actions.js @@ -19,6 +19,7 @@ const storeActions = { RESET_DAMAGE_STATE_AND_DEPENDENCIES: "resetDamageAndDependencies", RESET_REGISTRATION_STATE_AND_DEPENDENCIES: "resetRegistrationAndDependencies", RESET_PARTS_STATE_AND_DEPENDENCIES: "resetPartsAndDependencies", + RESET_STATE: "resetState", }; export { storeActions }; diff --git a/src/constants/store-mutations.js b/src/constants/store-mutations.js index 838018590..d6ee3b321 100644 --- a/src/constants/store-mutations.js +++ b/src/constants/store-mutations.js @@ -29,6 +29,7 @@ const storeMutations = { RESET_DAMAGE_STATE: "resetDamageState", RESET_REGISTRATION_STATE: "resetRegistrationState", RESET_PARTS_STATE: "resetPartsState", + RESET_STATE: "resetState", // OTHER MUTATIONS UPDATE_PAGE_DATA: "updatePageData", diff --git a/src/mixins/base-mixin.js b/src/mixins/base-mixin.js index 47407c81f..5543c681c 100644 --- a/src/mixins/base-mixin.js +++ b/src/mixins/base-mixin.js @@ -5,7 +5,6 @@ import { storeMutations } from "@/constants/store-mutations.js"; import { navigationScenarios } from "@/router/router-constants/navigation-scenarios"; import { widgetNames } from "@/constants/widget-names.js"; import { vehicleCategories } from "@/constants/vehicle-categories.js"; -import { fmgPageValues } from "@/router/router-constants/fmgPage-values"; export default { data() { @@ -28,14 +27,21 @@ export default { store.commit(storeMutations.UPDATE_REFERRAL_NUMBER, savedOrderInfo.referralNumber); store.commit(storeMutations.UPDATE_REFERRAL_DATE, savedOrderInfo.referralDate); store.commit(storeMutations.UPDATE_REFERRAL_CORRELATION_ID, savedOrderInfo.referralCorrelationId); - - // console.log(router) - // console.log(router.currentRoute.value.name) - // if (router.currentRoute.value.name) - // this.navigateToHeritageFunnel() + }, + getCookieValue(cookieName) { + return document.cookie + ?.split("; ") + ?.find(row => row.startsWith(`${cookieName}=`)) + ?.split("=")[1]; + }, + setCookieValue(cookieName, cookieValue) { + document.cookie = `${cookieName}=${cookieValue}`; + }, + deleteCookie(cookieName) { + console.log("D") + document.cookie = `${cookieName}=; Max-Age=0; path=/; domain=${location.hostname}`; }, navigateToHeritageFunnel() { - console.log("Get estimate!") var referralCorrelationId = store.getters.referralCorrelationId; router.navigate( @@ -43,7 +49,10 @@ export default { router.currentRoute.value, { corid: referralCorrelationId, - src: "concept-funnel" + src: "concept-funnel", + // TODO CSR-98 REMOVE THIS + cns: "all", + experiments: "ConceptFunnel=ConceptFunnel_V1=ConceptFunnel_TEST=true" } ); } diff --git a/src/router/index.js b/src/router/index.js index 33b7190ad..ba1725bd3 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -50,6 +50,24 @@ const routes = [ path: "/", name: "root", async beforeEnter(to, from, next) { + // TODO CSR-98 Also triggers on refresh... should it though? + // Entering the concept funnel + if (from.redirectedFrom === undefined) { + // TODO CSR-98 Don't hardcode cookie name "OrderInfo" + var orderInfoJson = baseMixin.methods.getCookieValue("OrderInfo"); + var orderInfo = orderInfoJson == null ? null : JSON.parse(orderInfoJson); + + if (orderInfo?.ShouldResetState) { + store.dispatch(storeActions.RESET_STATE); + } + else { + // should load referral here + } + + // Delete cookie once state is loaded or reset + baseMixin.methods.deleteCookie("OrderInfo"); + } + // If we have no query string, or we don't have the FmgPage query string. if (to.query.fmgPage === undefined) { await GoToFunnelStartOn404(next); @@ -57,7 +75,6 @@ const routes = [ try { // If we already have our route, go to it. if (router.hasRoute(to.query.fmgPage)) { - // Since our route is already in scope, we can grab the component from it and call the arePagePrerequisitesValid function. let component = router.getRoutes().filter((x) => x.name === to.query.fmgPage)[0].components; @@ -152,8 +169,9 @@ function navigate(scenario, currentRoute, invalidateOnSave, optionalQuery = {}, baseMixin.methods.savePageDataToStore(matchingScenarioMap.destinationFmgPageValue, optionalPageData); // TODO CSR-98 don't hardcode this - if (currentRoute.name == "vehicle-damage") - baseMixin.methods.navigateToHeritageFunnel() + if (currentRoute.name == "vehicle-damage") { + baseMixin.methods.navigateToHeritageFunnel(); + } else { router.push({ name: "root", diff --git a/src/router/router-constants/routing-table.js b/src/router/router-constants/routing-table.js index 766f4f95a..e4c657a1d 100644 --- a/src/router/router-constants/routing-table.js +++ b/src/router/router-constants/routing-table.js @@ -85,15 +85,12 @@ const routingTable = [ }, { scenario: navigationScenarios.SELECTED_PARTS, -<<<<<<< HEAD destinationFmgPageValue: fmgPageValues.QUOTE, }, { scenario: navigationScenarios.CLICKED_FORWARD, - destinationUrl: externalUrls.HERITAGE_FUNNEL, -======= + // destinationUrl: externalUrls.HERITAGE_FUNNEL, destinationFmgPageValue: fmgPageValues.REVEAL, ->>>>>>> develop }, ], }, diff --git a/src/store/index.js b/src/store/index.js index 6097d5896..8e5e801c5 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -7,37 +7,41 @@ import globalMethods from "@/global-methods"; // Export State -export const state = { - order: { - vehicle: { - year: null, - make: null, - model: null, - style: null, - carId: null, - category: null, - imageUrl: null, - imageVifNumber: null, - imageColor: null, +const getDefaultState = () => { + return { + order: { + vehicle: { + year: null, + make: null, + model: null, + style: null, + carId: null, + category: null, + imageUrl: null, + imageVifNumber: null, + imageColor: null, + }, + damage: { + isRepair: null, + numberOfChips: null, + glassToReplace: null, + }, + lineItems:{ + glassParts: null, + otherParts: null + }, + referralNumber: null, + referralDate: null, + referralCorrelationId: null, }, - damage: { - isRepair: null, - numberOfChips: null, - glassToReplace: null, + applicationUser: { + eventBus: [], + pageData: {} }, - lineItems:{ - glassParts: null, - otherParts: null - }, - referralNumber: null, - referralDate: null, - referralCorrelationId: null, - }, - applicationUser: { - eventBus: [], - pageData: {} - }, -} + } +}; + +export const state = getDefaultState(); // Export Mutations export const mutations = { @@ -136,6 +140,9 @@ export const mutations = { resetPartsState(state) { state.order.lineItems.glassParts = null; state.order.lineItems.otherParts = null; + }, + resetState(state) { + Object.assign(state, getDefaultState()); } } @@ -249,6 +256,9 @@ export const actions = { resetPartsAndDependencies(context) { context.commit(storeMutations.RESET_PARTS_STATE); }, + resetState(context) { + context.commit(storeMutations.RESET_STATE); + }, // Content API Actions getRouteInfo(context, { pageName }) {