cleanup, setup state for referrals
This commit is contained in:
parent
a279c9d011
commit
f7ddb5ff6c
4 changed files with 55 additions and 57 deletions
|
|
@ -9,8 +9,8 @@ import baseMixin from "../mixins/base-mixin";
|
|||
export async function loadReferralFromHeritageFunnelIfPresent() {
|
||||
const orderInfo = getHeritageCookieValue();
|
||||
|
||||
// Do nothing if there is no cookie.
|
||||
if(orderInfo === null){
|
||||
// Do nothing if there is no cookie or no correlation id.
|
||||
if (orderInfo === null || orderInfo.ReferralCorrelationId === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -22,12 +22,14 @@ export async function loadReferralFromHeritageFunnelIfPresent() {
|
|||
}
|
||||
|
||||
// Load referral if there is a cookie, and it doesn't indicate it needs a state reset.
|
||||
await loadOrder();
|
||||
await loadOrder(orderInfo.ReferralNumber, orderInfo.ReferralDate, orderInfo.ReferralCorrelationId);
|
||||
}
|
||||
|
||||
// Navigate to Heritage Funnel with the proper URL format.
|
||||
// Will Save the referral if there is one in state, or create a new one if one is not in state.
|
||||
export async function navigateToHeritageFunnel() {
|
||||
await saveOrder();
|
||||
const referralCorrelationId = store.getters.referralCorrelationId;
|
||||
const referralCorrelationId = store.state.order.referralCorrelationId;
|
||||
|
||||
router.navigate(
|
||||
navigationScenarios.MOVE_TO_HERITAGE_FUNNEL,
|
||||
|
|
@ -42,42 +44,44 @@ export async function navigateToHeritageFunnel() {
|
|||
);
|
||||
}
|
||||
|
||||
// Saves Referral if one is available and commits referral details to state.
|
||||
// Also sets cookie properties.
|
||||
export async function saveOrder() {
|
||||
const savedOrderInfo = (await baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.SAVE_ORDER)).data;
|
||||
const savedOrderInfo = await baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.SAVE_ORDER);
|
||||
|
||||
// Save the referral information back from the store.
|
||||
await baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.SET_REFERRAL_INFORMATION, {
|
||||
referralNumber: savedOrderInfo.referralNumber,
|
||||
correlationId: savedOrderInfo.referralCorrelationId,
|
||||
referralDate: savedOrderInfo.referralDate,
|
||||
})
|
||||
referralNumber: savedOrderInfo.data.referralNumber,
|
||||
correlationId: savedOrderInfo.data.referralCorrelationId,
|
||||
referralDate: savedOrderInfo.data.referralDate,
|
||||
}, false);
|
||||
|
||||
// Set cookie properties.
|
||||
setHeritageCookieProperties({
|
||||
DidHeritageFunnelUpdateLast: false
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
export async function loadOrder() {
|
||||
const loadOrderInfo = (await baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.LOAD_ORDER)).data;
|
||||
|
||||
// Save the data from the loaded order to state.
|
||||
await baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.SET_LOAD_ORDER_DATA, { loadOrderInfo });
|
||||
// Loads order based on referral data in cookie, also loads the referral information into state.
|
||||
export async function loadOrder(referralNumber, referralDate, correlationId) {
|
||||
const loadOrderResponse = await baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.LOAD_ORDER,
|
||||
{ referralNumber: referralNumber, referralDate: referralDate, correlationId: correlationId }
|
||||
, false);
|
||||
}
|
||||
|
||||
// --------- PRIVATE FUNCTIONS ---------
|
||||
|
||||
/* Start cookie related functions */
|
||||
export function getHeritageCookieValue() {
|
||||
console.log("A")
|
||||
console.log("getHeritageCookieValue called");
|
||||
const cookieJson = document.cookie
|
||||
?.split("; ")
|
||||
?.find(row => row.startsWith(`${cookieNames.ORDER_INFO}=`))
|
||||
?.split("=")[1];
|
||||
|
||||
|
||||
try {
|
||||
return JSON.parse(cookieJson);
|
||||
} catch(error) {
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import { storeActions } from "@/constants/store-actions";
|
|||
import { lazyLoadComponent } from "@/router/dynamic-routing/component-loader.js";
|
||||
import { routingTable } from "@/router/router-constants/routing-table.js";
|
||||
import { globalEvents, globalEventTypes } from "@/constants/events";
|
||||
import { routerParameterKeys } from '@/router/router-constants/router-parameter-keys'
|
||||
import { loadReferralFromHeritageFunnelIfPresent, saveOrder, getHeritageCookieValue } from "@/helpers/heritage-integration-helper";
|
||||
|
||||
import baseMixin from "@/mixins/base-mixin";
|
||||
|
|
@ -30,17 +29,17 @@ const routes = [
|
|||
path: "/",
|
||||
name: "root",
|
||||
async beforeEnter(to, from, next) {
|
||||
// On entering the concept funnel
|
||||
if (from.redirectedFrom === undefined) {
|
||||
// Read cookie information, decide what to do next
|
||||
loadReferralFromHeritageFunnelIfPresent();
|
||||
}
|
||||
|
||||
// If we have no query string, or we don't have the FmgPage query string.
|
||||
if (to.query.fmgPage === undefined) {
|
||||
await GoToFunnelStartOn404(next);
|
||||
} else {
|
||||
try {
|
||||
|
||||
// On entering the concept funnel "fresh", read cookie information, decide what to do next.
|
||||
if (from.redirectedFrom === undefined) {
|
||||
await loadReferralFromHeritageFunnelIfPresent();
|
||||
}
|
||||
|
||||
// If we already have our route, go to it.
|
||||
if (router.hasRoute(to.query.fmgPage)) {
|
||||
// Since our route is already in scope, we can grab the component from it and call the arePagePrerequisitesValid function.
|
||||
|
|
@ -135,15 +134,16 @@ async function navigate(scenario, currentRoute, invalidateOnSave, optionalQuery
|
|||
baseMixin.methods.savePageDataToStore(destinationFmgPageValue, optionalPageData);
|
||||
|
||||
// if cookie and referralNumber exists
|
||||
if (getHeritageCookieValue()?.ReferralNumber)
|
||||
saveOrder();
|
||||
if (getHeritageCookieValue()?.ReferralNumber) {
|
||||
await saveOrder();
|
||||
}
|
||||
|
||||
router.push({
|
||||
name: "root",
|
||||
query: Object.assign(optionalQuery, {
|
||||
fmgPage: destinationFmgPageValue,
|
||||
}),
|
||||
params: Object.assign(optionalParams, {[routerParameterKeys.FROM_ROUTER_NAVIGATE]: true})
|
||||
params: optionalParams
|
||||
});
|
||||
} else if (matchingScenarioMap.destinationUrl !== undefined) {
|
||||
navigateToUrl(matchingScenarioMap.destinationUrl, optionalQuery);
|
||||
|
|
@ -152,7 +152,6 @@ async function navigate(scenario, currentRoute, invalidateOnSave, optionalQuery
|
|||
|
||||
// Get navigation map depending on the scenario and the current 'page' you're on.
|
||||
function getNavigationMap(scenario, currentRoute) {
|
||||
console.log("A")
|
||||
const fmgPageValue = currentRoute.query.fmgPage;
|
||||
const matchedQueryValue = routingTable
|
||||
.filter(
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
const routerParameterKeys = {
|
||||
FROM_ROUTER_NAVIGATE: 'fromRouterNavigate',
|
||||
};
|
||||
const routerParameterKeys = { };
|
||||
|
||||
export { routerParameterKeys };
|
||||
|
|
@ -148,25 +148,25 @@ export const mutations = {
|
|||
|
||||
// Misc Mutations
|
||||
setLoadOrderInformation(state, orderInformation) {
|
||||
state.order.referralNumber = orderInformation.ReferralNumber;
|
||||
state.order.referralDate = orderInformation.ReferralDate;
|
||||
state.order.referralCorrelationId = orderInformation.CorrelationId;
|
||||
state.order.referralNumber = orderInformation.referralNumber;
|
||||
state.order.referralDate = orderInformation.referralDate;
|
||||
state.order.referralCorrelationId = orderInformation.correlationId;
|
||||
state.order.vehicle = {
|
||||
year: orderInformation.Year,
|
||||
make: orderInformation.Make,
|
||||
model: orderInformation.Model,
|
||||
style: orderInformation.Style,
|
||||
carId: orderInformation.CarId,
|
||||
category: orderInformation.Category,
|
||||
imageUrl: orderInformation.ImageUrl,
|
||||
imageVifNumber: orderInformation.ImageVifNumber,
|
||||
imageColor: orderInformation.ImageColor
|
||||
year: orderInformation.vehicle.year,
|
||||
make: orderInformation.vehicle.make,
|
||||
model: orderInformation.vehicle.model,
|
||||
style: orderInformation.vehicle.style,
|
||||
carId: orderInformation.vehicle.carId,
|
||||
category: orderInformation.vehicle.category,
|
||||
imageUrl: orderInformation.vehicle.imageUrl,
|
||||
imageVifNumber: orderInformation.vehicle.imageVifNumber,
|
||||
imageColor: orderInformation.vehicle.imageVifColor
|
||||
};
|
||||
state.order.damage.glassToReplace = orderInformation.GlassToReplace;
|
||||
state.order.damage.isRepair = orderInformation.IsRepair;
|
||||
state.order.damage.numberOfChips = orderInformation.NumberOfChips;
|
||||
state.order.lineItems.glassParts = orderInformation.Parts;
|
||||
state.order.parentAccountNumber = orderInformation.ParentAccountNumber;
|
||||
state.order.damage.glassToReplace = orderInformation.glassToReplace;
|
||||
state.order.damage.isRepair = orderInformation.isRepair;
|
||||
state.order.damage.numberOfChips = orderInformation.numberOfChips;
|
||||
state.order.lineItems.glassParts = orderInformation.parts;
|
||||
state.order.parentAccountNumber = orderInformation.parentAccountNumber;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -184,9 +184,6 @@ export const getters = {
|
|||
eventBus: (state) => state.applicationUser.eventBus,
|
||||
damage: (state) => state.order.damage,
|
||||
lineItems: (state) => state.order.lineItems,
|
||||
referralNumber: (state) => state.order.referralNumber,
|
||||
referralDate: (state) => state.order.referralDate,
|
||||
referralCorrelationId: (state) => state.order.referralCorrelationId,
|
||||
pageData: (state) => (page) => {
|
||||
return state.applicationUser.pageData[page];
|
||||
}
|
||||
|
|
@ -321,9 +318,6 @@ export const actions = {
|
|||
context.commit(storeMutations.UPDATE_REFERRAL_DATE, referralDate);
|
||||
context.commit(storeMutations.UPDATE_REFERRAL_CORRELATION_ID, correlationId);
|
||||
},
|
||||
setLoadOrderData(context, { loadOrderData }) {
|
||||
|
||||
},
|
||||
|
||||
// Parts API Actions
|
||||
getPartsOrQuestions(context, { carId, glassArray, zipCode, vin = '' }) {
|
||||
|
|
@ -357,8 +351,8 @@ export const actions = {
|
|||
},
|
||||
numberOfChips: damage.numberOfChips,
|
||||
glassToReplace: damage.glassToReplace,
|
||||
referralNumber: context.getters.referralNumber,
|
||||
referralDate: context.getters.referralDate
|
||||
referralNumber: context.state.order.referralNumber,
|
||||
referralDate: context.state.order.referralDate
|
||||
},
|
||||
});
|
||||
},
|
||||
|
|
@ -372,6 +366,9 @@ export const actions = {
|
|||
referralDate: referralDate,
|
||||
correlationId: correlationId
|
||||
},
|
||||
}).then( (response) => {
|
||||
context.commit(storeMutations.SET_LOAD_ORDER_INFO, response.data);
|
||||
return response;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue