CSR-98 Check and edit cookie info as needed
This commit is contained in:
parent
04bd941d03
commit
f4a6cc66cf
2 changed files with 30 additions and 11 deletions
|
|
@ -8,18 +8,16 @@ import baseMixin from "../mixins/base-mixin";
|
||||||
|
|
||||||
// Read info from heritage funnel and reset state or load referral
|
// Read info from heritage funnel and reset state or load referral
|
||||||
export function handleInfoFromHeritageFunnel() {
|
export function handleInfoFromHeritageFunnel() {
|
||||||
var orderInfoJson = getHeritageCookieValue();
|
var orderInfo = getHeritageCookieValue();
|
||||||
var orderInfo = orderInfoJson == null ? null : JSON.parse(orderInfoJson);
|
|
||||||
|
|
||||||
if (orderInfo?.ShouldResetState) {
|
if (orderInfo?.ShouldResetState) {
|
||||||
store.dispatch(storeActions.RESET_STATE);
|
store.dispatch(storeActions.RESET_STATE);
|
||||||
}
|
deleteHeritageCookie();
|
||||||
else if (orderInfo != null) {
|
|
||||||
// should load referral here
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete cookie once state is loaded or reset
|
if (orderInfo?.DidHeritageFunnelUpdateLast) {
|
||||||
deleteHeritageCookie();
|
// Load referral here
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function navigateToHeritageFunnel() {
|
export function navigateToHeritageFunnel() {
|
||||||
|
|
@ -43,15 +41,36 @@ export async function saveOrder() {
|
||||||
store.commit(storeMutations.UPDATE_REFERRAL_NUMBER, savedOrderInfo.referralNumber);
|
store.commit(storeMutations.UPDATE_REFERRAL_NUMBER, savedOrderInfo.referralNumber);
|
||||||
store.commit(storeMutations.UPDATE_REFERRAL_DATE, savedOrderInfo.referralDate);
|
store.commit(storeMutations.UPDATE_REFERRAL_DATE, savedOrderInfo.referralDate);
|
||||||
store.commit(storeMutations.UPDATE_REFERRAL_CORRELATION_ID, savedOrderInfo.referralCorrelationId);
|
store.commit(storeMutations.UPDATE_REFERRAL_CORRELATION_ID, savedOrderInfo.referralCorrelationId);
|
||||||
|
|
||||||
|
setDidHeritageFunnelUpdateLastInHeritageCookie(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Start cookie related functions */
|
||||||
export function getHeritageCookieValue() {
|
export function getHeritageCookieValue() {
|
||||||
return document.cookie
|
var cookieJson = document.cookie
|
||||||
?.split("; ")
|
?.split("; ")
|
||||||
?.find(row => row.startsWith(`${cookieNames.ORDER_INFO}=`))
|
?.find(row => row.startsWith(`${cookieNames.ORDER_INFO}=`))
|
||||||
?.split("=")[1];
|
?.split("=")[1];
|
||||||
|
|
||||||
|
return cookieJson == null ? null : JSON.parse(cookieJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteHeritageCookie() {
|
export function deleteHeritageCookie() {
|
||||||
document.cookie = `${cookieNames.ORDER_INFO}=; Max-Age=0; path=/; domain=${location.hostname}`;
|
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 */
|
||||||
|
|
@ -52,9 +52,9 @@ const routes = [
|
||||||
path: "/",
|
path: "/",
|
||||||
name: "root",
|
name: "root",
|
||||||
async beforeEnter(to, from, next) {
|
async beforeEnter(to, from, next) {
|
||||||
// TODO CSR-98 Also triggers on refresh... should it though?
|
// On entering the concept funnel
|
||||||
// Entering the concept funnel
|
|
||||||
if (from.redirectedFrom === undefined) {
|
if (from.redirectedFrom === undefined) {
|
||||||
|
// Read cookie information, decide what to do next
|
||||||
handleInfoFromHeritageFunnel();
|
handleInfoFromHeritageFunnel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue