diff --git a/src/helpers/heritage-integration-helper.js b/src/helpers/heritage-integration-helper.js index 95ee7ef09..eda55a063 100644 --- a/src/helpers/heritage-integration-helper.js +++ b/src/helpers/heritage-integration-helper.js @@ -8,18 +8,19 @@ import baseMixin from "../mixins/base-mixin"; // Read info from heritage funnel and reset state or load referral export function handleInfoFromHeritageFunnel() { - var orderInfoJson = getHeritageCookieValue(); - var orderInfo = orderInfoJson == null ? null : JSON.parse(orderInfoJson); + var orderInfo = getHeritageCookieValue(); if (orderInfo?.ShouldResetState) { store.dispatch(storeActions.RESET_STATE); + deleteHeritageCookie(); } - else if (orderInfo != null) { - // should load referral here - } + else if (orderInfo?.DidHeritageFunnelUpdateLast) { + // Load referral here - // Delete cookie once state is loaded or reset - deleteHeritageCookie(); + // setHeritageCookieProperties({ + // ShouldResetState: false + // }) + } } export function navigateToHeritageFunnel() { @@ -33,7 +34,7 @@ export function navigateToHeritageFunnel() { src: "concept-funnel", // TODO CSR-98 REMOVE THIS cns: "all", - experiments: "ConceptFunnel=ConceptFunnel_V1=ConceptFunnel_TEST=true" + experiments: "RemoveServiceAreaPage=ServAreaRemoval_V7=ServAreaNoRemove_V7_TEST=true,ConceptFunnel=ConceptFunnel_V1=ConceptFunnel_TEST=true" } ); } @@ -43,15 +44,45 @@ export async function saveOrder() { 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); + + setHeritageCookieProperties({ + DidHeritageFunnelUpdateLast: false + }) } -export function getHeritageCookieValue() { - return document.cookie +/* Start cookie related functions */ +function getHeritageCookieValue() { + var cookieJson = document.cookie ?.split("; ") ?.find(row => row.startsWith(`${cookieNames.ORDER_INFO}=`)) ?.split("=")[1]; + + return cookieJson == null ? null : JSON.parse(cookieJson); } -export function deleteHeritageCookie() { +function deleteHeritageCookie() { document.cookie = `${cookieNames.ORDER_INFO}=; Max-Age=0; path=/; domain=${location.hostname}`; -} \ No newline at end of file +} + +function setHeritageCookieValue(cookieValue) { + let cookieValueJson = cookieValue; + if (typeof cookieValue == "object") + cookieValueJson = JSON.stringify(cookieValue); + + document.cookie = `${cookieNames.ORDER_INFO}=${cookieValueJson}; path=/`; +} + +function setHeritageCookieProperties(properties) { + if (typeof properties == "object") { + let cookie = getHeritageCookieValue(); + + if (cookie != null) { + Object.keys(properties).forEach(key => { + cookie[key] = properties[key]; + }); + + setHeritageCookieValue(cookie); + } + } +} +/* End cookie related functions */ \ No newline at end of file diff --git a/src/helpers/unit-test-helper.js b/src/helpers/unit-test-helper.js index 1509a4b16..561798629 100644 --- a/src/helpers/unit-test-helper.js +++ b/src/helpers/unit-test-helper.js @@ -49,7 +49,6 @@ export function getMountOptions(mockData) { mocks.$router = mockData.router; mocks.$route = mockData.route; - const global = { mocks: mocks, }; diff --git a/src/mixins/base-mixin.spec.js b/src/mixins/base-mixin.spec.js index 8c33a5774..da684af1b 100644 --- a/src/mixins/base-mixin.spec.js +++ b/src/mixins/base-mixin.spec.js @@ -101,9 +101,6 @@ function getMixInInstance({ isDispatchSuccess = true }) { baseMixIn.methods.$route = route; baseMixIn.methods.storeActions = storeActions; baseMixIn.methods.widgetNames = widgetNames; - baseMixin.document = { - cookie: "" - } store.dispatch = storeDispatch; store.commit = jest.fn(); diff --git a/src/router/index.js b/src/router/index.js index 6cd146588..c77285677 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -52,9 +52,9 @@ const routes = [ path: "/", name: "root", async beforeEnter(to, from, next) { - // TODO CSR-98 Also triggers on refresh... should it though? - // Entering the concept funnel + // On entering the concept funnel if (from.redirectedFrom === undefined) { + // Read cookie information, decide what to do next handleInfoFromHeritageFunnel(); } @@ -133,7 +133,7 @@ router.navigateAfterSave = (scenario, currentRoute, optionalQuery = {}, optional // PRIVATE FUNCTIONS // Navigate to the next route, depending on the scenario. -function navigate(scenario, currentRoute, invalidateOnSave, optionalQuery = {}, optionalParams = {}, optionalPageData = {}) { +async function navigate(scenario, currentRoute, invalidateOnSave, optionalQuery = {}, optionalParams = {}, optionalPageData = {}) { if (!scenario) { console.error("No scenario provided. Please review the routing table."); return; @@ -170,7 +170,7 @@ function navigate(scenario, currentRoute, invalidateOnSave, optionalQuery = {}, }); } else if (matchingScenarioMap.destinationUrl !== undefined) { if (matchingScenarioMap.shouldNavigateToHeritageFunnel) { - saveOrder(); + await saveOrder(); } navigateToUrl(matchingScenarioMap.destinationUrl, optionalQuery);