From f4a6cc66cfc574b277a73e5d7dab8818199c77ad Mon Sep 17 00:00:00 2001 From: Katie Date: Thu, 17 Mar 2022 16:12:20 -0400 Subject: [PATCH] CSR-98 Check and edit cookie info as needed --- src/helpers/heritage-integration-helper.js | 37 ++++++++++++++++------ src/router/index.js | 4 +-- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/helpers/heritage-integration-helper.js b/src/helpers/heritage-integration-helper.js index 12cba038b..68cb2484e 100644 --- a/src/helpers/heritage-integration-helper.js +++ b/src/helpers/heritage-integration-helper.js @@ -8,18 +8,16 @@ 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); - } - else if (orderInfo != null) { - // should load referral here + deleteHeritageCookie(); } - // Delete cookie once state is loaded or reset - deleteHeritageCookie(); + if (orderInfo?.DidHeritageFunnelUpdateLast) { + // Load referral here + } } export function navigateToHeritageFunnel() { @@ -43,15 +41,36 @@ 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); + + setDidHeritageFunnelUpdateLastInHeritageCookie(false); } +/* Start cookie related functions */ export function getHeritageCookieValue() { - return document.cookie + var cookieJson = document.cookie ?.split("; ") ?.find(row => row.startsWith(`${cookieNames.ORDER_INFO}=`)) ?.split("=")[1]; + + return cookieJson == null ? null : JSON.parse(cookieJson); } export function deleteHeritageCookie() { document.cookie = `${cookieNames.ORDER_INFO}=; Max-Age=0; path=/; domain=${location.hostname}`; -} \ No newline at end of file +} + +function setHeritageCookieValue(cookieValue) { + var cookieValueJson = JSON.stringify(cookieValue); + document.cookie = `${cookieNames.ORDER_INFO}=${cookieValueJson}; path=/`; +} + +function setDidHeritageFunnelUpdateLastInHeritageCookie(didHeritageFunnelUpdateLast) { + var cookie = getHeritageCookieValue(); + + if (cookie != null) { + cookie.DidHeritageFunnelUpdateLast = false; + + setHeritageCookieValue(cookie); + } +} +/* End cookie related functions */ \ No newline at end of file diff --git a/src/router/index.js b/src/router/index.js index d9d03e213..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(); }