CSR-98 Check and edit cookie info as needed

This commit is contained in:
Katie 2022-03-17 16:12:20 -04:00
parent 04bd941d03
commit f4a6cc66cf
2 changed files with 30 additions and 11 deletions

View file

@ -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}`;
}
}
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 */

View file

@ -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();
}