From b3edba964dcc6425c6f9b3e4237fa21f85801a5b Mon Sep 17 00:00:00 2001 From: CarlNation Date: Tue, 17 Jan 2023 10:19:54 -0500 Subject: [PATCH] CSR-1086 Recover from old saved sessions and errors --- .../heritage-integration/order-helper.js | 2 +- src/store/index.js | 38 ++++++++++++------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/helpers/heritage-integration/order-helper.js b/src/helpers/heritage-integration/order-helper.js index 05b4c4dc4..7cf3cc12b 100644 --- a/src/helpers/heritage-integration/order-helper.js +++ b/src/helpers/heritage-integration/order-helper.js @@ -44,7 +44,7 @@ export async function loadSessionIfPresent(isConceptInsurance) { funnelCookie.ReferralCorrelationId, isConceptInsurance ) - ).data; + )?.data; } /* diff --git a/src/store/index.js b/src/store/index.js index c41f38ddf..d2634dd10 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -10,6 +10,7 @@ import { experimentTriggers } from "@/constants/experiments"; import { damageLocationsSelected } from "@/constants/damage-locations-selected"; import { fmgPageValues } from "@/router/router-constants/fmgPage-values"; import router from "@/router"; +import { deleteFunnelCookie } from "@/helpers/heritage-integration/cookie-helper.js"; // Export State const getDefaultState = () => { @@ -1059,23 +1060,32 @@ export const actions = { referralCorrelationId: referralCorrelationId, }, }) - .then((response) => { - // Flatten location and name properties - response.data.order.damage?.glassToReplace?.map((glass) => { - glass.glassLocation = glass.location; - glass.glassName = glass.name; - delete glass.location; - delete glass.name; - return glass; - }); + .then( + (response) => { + // Flatten location and name properties + response.data.order.damage?.glassToReplace?.map((glass) => { + glass.glassLocation = glass.location; + glass.glassName = glass.name; + delete glass.location; + delete glass.name; + return glass; + }); - // clear the state if the existing EON does not equal what is returned from loadSession - if (context.state.order.eon && context.state.order.eon != response.data.eon) { + // clear the state if the existing EON does not equal what is returned from loadSession + if (context.state.order.eon && context.state.order.eon != response.data.eon) { + context.commit(storeMutations.RESET_STATE); + } + context.commit( + storeMutations.UPDATE_STATE_WITH_ORDER_INFORMATION, + response.data + ); + return response; + }, + (error) => { + deleteFunnelCookie(); context.commit(storeMutations.RESET_STATE); } - context.commit(storeMutations.UPDATE_STATE_WITH_ORDER_INFORMATION, response.data); - return response; - }); + ); }, // Business domain actions