CSR-98 Refactor cookie code
This commit is contained in:
parent
f4a6cc66cf
commit
442125ed65
1 changed files with 24 additions and 12 deletions
|
|
@ -14,9 +14,12 @@ export function handleInfoFromHeritageFunnel() {
|
||||||
store.dispatch(storeActions.RESET_STATE);
|
store.dispatch(storeActions.RESET_STATE);
|
||||||
deleteHeritageCookie();
|
deleteHeritageCookie();
|
||||||
}
|
}
|
||||||
|
else if (orderInfo?.DidHeritageFunnelUpdateLast) {
|
||||||
if (orderInfo?.DidHeritageFunnelUpdateLast) {
|
|
||||||
// Load referral here
|
// Load referral here
|
||||||
|
|
||||||
|
// setHeritageCookieProperties({
|
||||||
|
// ShouldResetState: false
|
||||||
|
// })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,11 +45,13 @@ export async function saveOrder() {
|
||||||
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);
|
setHeritageCookieProperties({
|
||||||
|
DidHeritageFunnelUpdateLast: false
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start cookie related functions */
|
/* Start cookie related functions */
|
||||||
export function getHeritageCookieValue() {
|
function getHeritageCookieValue() {
|
||||||
var cookieJson = document.cookie
|
var cookieJson = document.cookie
|
||||||
?.split("; ")
|
?.split("; ")
|
||||||
?.find(row => row.startsWith(`${cookieNames.ORDER_INFO}=`))
|
?.find(row => row.startsWith(`${cookieNames.ORDER_INFO}=`))
|
||||||
|
|
@ -55,22 +60,29 @@ export function getHeritageCookieValue() {
|
||||||
return cookieJson == null ? null : JSON.parse(cookieJson);
|
return cookieJson == null ? null : JSON.parse(cookieJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteHeritageCookie() {
|
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) {
|
function setHeritageCookieValue(cookieValue) {
|
||||||
var cookieValueJson = JSON.stringify(cookieValue);
|
let cookieValueJson = cookieValue;
|
||||||
|
if (typeof cookieValue == "object")
|
||||||
|
cookieValueJson = JSON.stringify(cookieValue);
|
||||||
|
|
||||||
document.cookie = `${cookieNames.ORDER_INFO}=${cookieValueJson}; path=/`;
|
document.cookie = `${cookieNames.ORDER_INFO}=${cookieValueJson}; path=/`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setDidHeritageFunnelUpdateLastInHeritageCookie(didHeritageFunnelUpdateLast) {
|
function setHeritageCookieProperties(properties) {
|
||||||
var cookie = getHeritageCookieValue();
|
if (typeof properties == "object") {
|
||||||
|
let cookie = getHeritageCookieValue();
|
||||||
|
|
||||||
if (cookie != null) {
|
if (cookie != null) {
|
||||||
cookie.DidHeritageFunnelUpdateLast = false;
|
Object.keys(properties).forEach(key => {
|
||||||
|
cookie[key] = properties[key];
|
||||||
setHeritageCookieValue(cookie);
|
});
|
||||||
|
|
||||||
|
setHeritageCookieValue(cookie);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* End cookie related functions */
|
/* End cookie related functions */
|
||||||
Loading…
Reference in a new issue