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);
|
||||
deleteHeritageCookie();
|
||||
}
|
||||
|
||||
if (orderInfo?.DidHeritageFunnelUpdateLast) {
|
||||
else if (orderInfo?.DidHeritageFunnelUpdateLast) {
|
||||
// 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_CORRELATION_ID, savedOrderInfo.referralCorrelationId);
|
||||
|
||||
setDidHeritageFunnelUpdateLastInHeritageCookie(false);
|
||||
setHeritageCookieProperties({
|
||||
DidHeritageFunnelUpdateLast: false
|
||||
})
|
||||
}
|
||||
|
||||
/* Start cookie related functions */
|
||||
export function getHeritageCookieValue() {
|
||||
function getHeritageCookieValue() {
|
||||
var cookieJson = document.cookie
|
||||
?.split("; ")
|
||||
?.find(row => row.startsWith(`${cookieNames.ORDER_INFO}=`))
|
||||
|
|
@ -55,22 +60,29 @@ export function getHeritageCookieValue() {
|
|||
return cookieJson == null ? null : JSON.parse(cookieJson);
|
||||
}
|
||||
|
||||
export function deleteHeritageCookie() {
|
||||
function deleteHeritageCookie() {
|
||||
document.cookie = `${cookieNames.ORDER_INFO}=; Max-Age=0; path=/; domain=${location.hostname}`;
|
||||
}
|
||||
|
||||
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=/`;
|
||||
}
|
||||
|
||||
function setDidHeritageFunnelUpdateLastInHeritageCookie(didHeritageFunnelUpdateLast) {
|
||||
var cookie = getHeritageCookieValue();
|
||||
function setHeritageCookieProperties(properties) {
|
||||
if (typeof properties == "object") {
|
||||
let cookie = getHeritageCookieValue();
|
||||
|
||||
if (cookie != null) {
|
||||
cookie.DidHeritageFunnelUpdateLast = false;
|
||||
|
||||
setHeritageCookieValue(cookie);
|
||||
if (cookie != null) {
|
||||
Object.keys(properties).forEach(key => {
|
||||
cookie[key] = properties[key];
|
||||
});
|
||||
|
||||
setHeritageCookieValue(cookie);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* End cookie related functions */
|
||||
Loading…
Reference in a new issue