Merge remote-tracking branch 'origin/feature/CSR-98' into feature/CSR-99

This commit is contained in:
FrankRua 2022-03-18 16:18:35 -04:00
commit 2faf1f51e2
4 changed files with 47 additions and 20 deletions

View file

@ -8,18 +8,19 @@ 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) { else if (orderInfo?.DidHeritageFunnelUpdateLast) {
// should load referral here // Load referral here
}
// Delete cookie once state is loaded or reset // setHeritageCookieProperties({
deleteHeritageCookie(); // ShouldResetState: false
// })
}
} }
export function navigateToHeritageFunnel() { export function navigateToHeritageFunnel() {
@ -33,7 +34,7 @@ export function navigateToHeritageFunnel() {
src: "concept-funnel", src: "concept-funnel",
// TODO CSR-98 REMOVE THIS // TODO CSR-98 REMOVE THIS
cns: "all", cns: "all",
experiments: "ConceptFunnel=ConceptFunnel_V1=ConceptFunnel_TEST=true" experiments: "RemoveServiceAreaPage=ServAreaRemoval_V7=ServAreaNoRemove_V7_TEST=true,ConceptFunnel=ConceptFunnel_V1=ConceptFunnel_TEST=true"
} }
); );
} }
@ -43,15 +44,45 @@ 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);
setHeritageCookieProperties({
DidHeritageFunnelUpdateLast: false
})
} }
export function getHeritageCookieValue() { /* Start cookie related functions */
return document.cookie function getHeritageCookieValue() {
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() { 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) {
let cookieValueJson = cookieValue;
if (typeof cookieValue == "object")
cookieValueJson = JSON.stringify(cookieValue);
document.cookie = `${cookieNames.ORDER_INFO}=${cookieValueJson}; path=/`;
}
function setHeritageCookieProperties(properties) {
if (typeof properties == "object") {
let cookie = getHeritageCookieValue();
if (cookie != null) {
Object.keys(properties).forEach(key => {
cookie[key] = properties[key];
});
setHeritageCookieValue(cookie);
}
}
}
/* End cookie related functions */

View file

@ -49,7 +49,6 @@ export function getMountOptions(mockData) {
mocks.$router = mockData.router; mocks.$router = mockData.router;
mocks.$route = mockData.route; mocks.$route = mockData.route;
const global = { const global = {
mocks: mocks, mocks: mocks,
}; };

View file

@ -101,9 +101,6 @@ function getMixInInstance({ isDispatchSuccess = true }) {
baseMixIn.methods.$route = route; baseMixIn.methods.$route = route;
baseMixIn.methods.storeActions = storeActions; baseMixIn.methods.storeActions = storeActions;
baseMixIn.methods.widgetNames = widgetNames; baseMixIn.methods.widgetNames = widgetNames;
baseMixin.document = {
cookie: ""
}
store.dispatch = storeDispatch; store.dispatch = storeDispatch;
store.commit = jest.fn(); store.commit = jest.fn();

View file

@ -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();
} }
@ -133,7 +133,7 @@ router.navigateAfterSave = (scenario, currentRoute, optionalQuery = {}, optional
// PRIVATE FUNCTIONS // PRIVATE FUNCTIONS
// Navigate to the next route, depending on the scenario. // Navigate to the next route, depending on the scenario.
function navigate(scenario, currentRoute, invalidateOnSave, optionalQuery = {}, optionalParams = {}, optionalPageData = {}) { async function navigate(scenario, currentRoute, invalidateOnSave, optionalQuery = {}, optionalParams = {}, optionalPageData = {}) {
if (!scenario) { if (!scenario) {
console.error("No scenario provided. Please review the routing table."); console.error("No scenario provided. Please review the routing table.");
return; return;
@ -170,7 +170,7 @@ function navigate(scenario, currentRoute, invalidateOnSave, optionalQuery = {},
}); });
} else if (matchingScenarioMap.destinationUrl !== undefined) { } else if (matchingScenarioMap.destinationUrl !== undefined) {
if (matchingScenarioMap.shouldNavigateToHeritageFunnel) { if (matchingScenarioMap.shouldNavigateToHeritageFunnel) {
saveOrder(); await saveOrder();
} }
navigateToUrl(matchingScenarioMap.destinationUrl, optionalQuery); navigateToUrl(matchingScenarioMap.destinationUrl, optionalQuery);