update to account for session

This commit is contained in:
FrankRua 2022-03-23 12:55:04 -04:00
parent 5eedfb9ce6
commit 8e21ccec6c
10 changed files with 297 additions and 241 deletions

View file

@ -1,14 +1,13 @@
import { storeActions } from "@/constants/store-actions.js"; import { storeActions } from "@/constants/store-actions.js";
import { cookieNames } from "@/constants/cookie-names"; import { cookieNames } from "@/constants/cookie-names";
import { navigationScenarios } from "@/router/router-constants/navigation-scenarios"; import { externalUrls } from "@/router/router-constants/externalUrl-values";
import { applicationConfig } from "@/constants/application-config"; import { applicationConfig } from "@/constants/application-config";
import { lazyLoadComponent } from "@/router/dynamic-routing/component-loader.js";
import store from "@/store"; import store from "@/store";
import router from "@/router"; import router from "@/router";
import baseMixin from "../mixins/base-mixin"; import baseMixin from "../mixins/base-mixin";
// Saves Referral if one is available and commits referral details to state.
export async function saveOrder() { export async function saveOrder() {
console.log("saving order..."); console.log("saving order...");
const savedOrderInfo = await baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.SAVE_ORDER); const savedOrderInfo = await baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.SAVE_ORDER);
@ -24,23 +23,14 @@ export async function saveOrder() {
updateOrCreateConceptCookie(); updateOrCreateConceptCookie();
} }
// Loads order based on referral data in cookie, also loads the referral information into state. export async function loadOrderIfPresent() {
export async function loadOrder(referralNumber, referralDate, correlationId) {
console.log("loading order...", referralNumber, referralDate, correlationId);
await baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.LOAD_ORDER,
{ referralNumber: referralNumber.toString(), referralDate: referralDate, correlationId: correlationId }
, false);
}
// Read info from heritage funnel and reset state or load referral
export async function loadReferralIfPresent() {
console.log("attempting to load referral...."); console.log("attempting to load referral....");
const conceptCookie = getConceptCookie(); const conceptCookie = getConceptCookie();
// Do nothing if there is no cookie or no correlation id. // Do nothing if there is no cookie or no correlation id.
if (conceptCookie === null || conceptCookie.ReferralCorrelationId === null) { if (conceptCookie === null || conceptCookie.ReferralCorrelationId === null) {
console.log("No referral found"); console.log("No referral found");
return; return null;
} }
// Reset state if cookie says to. // Reset state if cookie says to.
@ -48,12 +38,32 @@ export async function loadReferralIfPresent() {
console.log("Resetting state..."); console.log("Resetting state...");
baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.RESET_STATE); baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.RESET_STATE);
deleteConceptCookie(); deleteConceptCookie();
return; return null;
} }
console.log("calling load order from loadReferralIfPresent()..."); console.log("calling load order from loadOrderIfPresent()...");
// Load referral if there is a cookie, and it doesn't indicate it needs a state reset. // Load referral if there is a cookie, and it doesn't indicate it needs a state reset.
await loadOrder(conceptCookie.ReferralNumber, conceptCookie.ReferralDate, conceptCookie.ReferralCorrelationId); return (await loadOrder(conceptCookie.ReferralNumber, conceptCookie.ReferralDate, conceptCookie.ReferralCorrelationId)).data;
}
export async function getPageToRouteExistingOrderTo() {
const vehicleMakeComponent = (await lazyLoadComponent('vehicle-make')()).default;
const vehicleModelComponent = (await lazyLoadComponent('vehicle-model')()).default;
const vehicleStyleComponent = (await lazyLoadComponent('vehicle-style')()).default;
const vehicleDamageComponent = (await lazyLoadComponent('vehicle-damage')()).default;
if (!vehicleMakeComponent.methods.arePagePrerequisitesValid()) {
return "vehicle-year";
} else if (!vehicleModelComponent.methods.arePagePrerequisitesValid()) {
return "vehicle-make";
} else if (!vehicleStyleComponent.methods.arePagePrerequisitesValid()) {
return "vehicle-model";
} else if (!vehicleDamageComponent.methods.arePagePrerequisitesValid()) {
return "vehicle-style";
}else {
return "vehicle-damage";
}
} }
export function updateOrCreateConceptCookie() { export function updateOrCreateConceptCookie() {
@ -96,16 +106,13 @@ export function isConceptSessionStillActive() {
} }
} }
// 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() { export async function navigateToHeritageFunnel() {
// Create the order (or save existing order) when navigating to Heritage Funnel. // Create the order (or save existing order) when navigating to Heritage Funnel.
await saveOrder(); await saveOrder();
router.navigate( router.navigateToExternalUrl(
navigationScenarios.MOVE_TO_HERITAGE_FUNNEL, externalUrls.HERITAGE_FUNNEL,
router.currentRoute.value,
{ {
corid: store.state.order.referralCorrelationId, corid: store.state.order.referralCorrelationId,
src: "concept-funnel", src: "concept-funnel",
@ -115,7 +122,6 @@ export async function navigateToHeritageFunnel() {
); );
} }
/* Start cookie related functions */
export function getConceptCookie() { export function getConceptCookie() {
const cookieJson = document.cookie const cookieJson = document.cookie
?.split("; ") ?.split("; ")
@ -129,7 +135,27 @@ export function getConceptCookie() {
} }
} }
// --------- PRIVATE FUNCTIONS --------- // --------- PRIVATE FUNCTIONS ---------
async function loadOrder(referralNumber, referralDate, correlationId) {
console.log("loading order...", referralNumber, referralDate, correlationId);
try {
const response = await baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.LOAD_ORDER,
{
referralNumber: referralNumber.toString(),
referralDate: referralDate,
correlationId: correlationId
}, false);
return response;
} catch (e) {
console.log("error loading order:", e);
}
}
function setConceptCookieProperties(properties) { function setConceptCookieProperties(properties) {
if (typeof properties == "object") { if (typeof properties == "object") {
@ -154,4 +180,3 @@ function deleteConceptCookie() {
} }
/* End cookie related functions */

View file

@ -19,7 +19,7 @@ describe("saveOrder", () => {
} }
} }
describe("loadReferralIfPresent", () => { describe("loadOrderIfPresent", () => {
// test("ShouldResetState == true => heritage cookie is deleted", () => { // test("ShouldResetState == true => heritage cookie is deleted", () => {
// // Arrange // // Arrange
// // TODO CSR-98 Can we not mock this?? // // TODO CSR-98 Can we not mock this??
@ -42,7 +42,7 @@ describe("saveOrder", () => {
// console.log(document.cookie) // console.log(document.cookie)
// // Act // // Act
// helper.loadReferralIfPresent(); // helper.loadOrderIfPresent();
// // Assert // // Assert
// console.log(document.cookie) // console.log(document.cookie)
@ -54,7 +54,7 @@ describe("saveOrder", () => {
// helper.getHeritageCookieValue = jest.fn(x => x.ShouldResetState = false); // helper.getHeritageCookieValue = jest.fn(x => x.ShouldResetState = false);
// // Act // // Act
// helper.loadReferralIfPresent(); // helper.loadOrderIfPresent();
// // Assert // // Assert
// expect(helper.getHeritageCookieValue).toHaveBeenCalled(); // expect(helper.getHeritageCookieValue).toHaveBeenCalled();
@ -65,7 +65,7 @@ describe("saveOrder", () => {
// helper.getHeritageCookieValue = jest.fn(x => x.ShouldResetState = true); // helper.getHeritageCookieValue = jest.fn(x => x.ShouldResetState = true);
// // Act // // Act
// helper.loadReferralIfPresent(); // helper.loadOrderIfPresent();
// // Assert // // Assert
// expect(helper.getHeritageCookieValue).toHaveBeenCalled(); // expect(helper.getHeritageCookieValue).toHaveBeenCalled();

View file

@ -70,8 +70,6 @@ import alert from "@/ux-components/alert/alert";
import { fetchCmsContentForPage } from "@/helpers/cms-content-helper"; import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
import { settleAllPromises } from "@/helpers/layout-helper"; import { settleAllPromises } from "@/helpers/layout-helper";
import { storeActions } from "@/constants/store-actions"; import { storeActions } from "@/constants/store-actions";
import store from "@/store";
import baseMixin from "@/mixins/base-mixin";
import { Form, defineRule } from "vee-validate"; import { Form, defineRule } from "vee-validate";
import { required } from "@/helpers/validation-rules"; import { required } from "@/helpers/validation-rules";
import { errorMessages } from "@/constants/error-messages"; import { errorMessages } from "@/constants/error-messages";
@ -79,6 +77,9 @@ import { damageLocationsCms } from "@/constants/damage-locations-cms.js";
import { damageLocationsSelected } from "@/constants/damage-locations-selected.js"; import { damageLocationsSelected } from "@/constants/damage-locations-selected.js";
import { navigateToHeritageFunnel } from "@/helpers/heritage-integration-helper"; import { navigateToHeritageFunnel } from "@/helpers/heritage-integration-helper";
import store from "@/store";
import baseMixin from "@/mixins/base-mixin";
// DEFINE VALIDATION RULES // DEFINE VALIDATION RULES
defineRule("replace-options-required", required(errorMessages.REPLACE_OPTIONS_REQUIRED)); defineRule("replace-options-required", required(errorMessages.REPLACE_OPTIONS_REQUIRED));
@ -150,7 +151,10 @@ export default {
}, },
methods: { methods: {
arePagePrerequisitesValid() { arePagePrerequisitesValid() {
return store.getters.vehicle.carId !== null; if(store.getters.vehicle.carId){
return true;
}
return false;
}, },
resetDependentState() { resetDependentState() {
store.dispatch(storeActions.RESET_PARTS_STATE_AND_DEPENDENCIES); store.dispatch(storeActions.RESET_PARTS_STATE_AND_DEPENDENCIES);

View file

@ -84,7 +84,10 @@ export default {
); );
}, },
arePagePrerequisitesValid() { arePagePrerequisitesValid() {
return store.getters.vehicle.year !== null; if (store.getters.vehicle.year){
return true;
}
return false;
}, },
resetDependentState() { resetDependentState() {
// Set // Set

View file

@ -85,7 +85,10 @@ export default {
); );
}, },
arePagePrerequisitesValid() { arePagePrerequisitesValid() {
return store.getters.vehicle.make !== null; if(store.getters.vehicle.make){
return true;
}
return false;
}, },
resetDependentState() { resetDependentState() {
// Set // Set

View file

@ -6,7 +6,13 @@
<div class="container-fluid prevent-squish my-5"> <div class="container-fluid prevent-squish my-5">
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<alert class="rounded border-0 shadow-sm" alertClass="alert-warning" :alertHeadline="alertWidgetData.headline" :alertCopy="alertWidgetData.copy" :isDismissible="false" /> <alert
class="rounded border-0 shadow-sm"
alertClass="alert-warning"
:alertHeadline="alertWidgetData.headline"
:alertCopy="alertWidgetData.copy"
:isDismissible="false"
/>
</div> </div>
</div> </div>
</div> </div>
@ -17,9 +23,19 @@
<hr v-if="i > 0" /> <hr v-if="i > 0" />
</div> </div>
<glassPartQuestion :ref="`${RefPrefix}-${item.glassLocation}-${item.glassName}`" v-model="glassParts[item.glassLocation + '-' + item.glassName]" :glassLocation="item.glassLocation" :glassName="item.glassName" :colorAnswers="item.colorAnswers" /> <glassPartQuestion
:ref="`${RefPrefix}-${item.glassLocation}-${item.glassName}`"
v-model="glassParts[item.glassLocation + '-' + item.glassName]"
:glassLocation="item.glassLocation"
:glassName="item.glassName"
:colorAnswers="item.colorAnswers"
/>
</div> </div>
<funnelFooter ref="funnelFooter" @back-clicked="backButtonAction" @ForwardClicked="forwardButtonAction" /> <funnelFooter
ref="funnelFooter"
@back-clicked="backButtonAction"
@ForwardClicked="forwardButtonAction"
/>
</div> </div>
</template> </template>
@ -32,18 +48,10 @@ import funnelSubHeader from "@/common-components/funnel-sub-header/funnel-sub-he
import funnelFooter from "@/common-components/funnel-footer/funnel-footer"; import funnelFooter from "@/common-components/funnel-footer/funnel-footer";
import alert from "@/ux-components/alert/alert"; import alert from "@/ux-components/alert/alert";
// Supporting Files // Supporting Files
import { import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
fetchCmsContentForPage import { settleAllPromises } from "@/helpers/layout-helper";
} from "@/helpers/cms-content-helper"; import { fmgPageValues } from "@/router/router-constants/fmgPage-values";
import { import { storeMutations } from "@/constants/store-mutations";
settleAllPromises
} from "@/helpers/layout-helper";
import {
fmgPageValues
} from "@/router/router-constants/fmgPage-values";
import {
storeMutations
} from "@/constants/store-mutations";
import store from "@/store"; import store from "@/store";
export default { export default {
@ -52,10 +60,12 @@ export default {
// Call APIs // Call APIs
const cmsContentPromise = fetchCmsContentForPage(to.query.fmgPage); const cmsContentPromise = fetchCmsContentForPage(to.query.fmgPage);
// Settle promises and get results // Settle promises and get results
const promiseResultMap = [{ const promiseResultMap = [
{
resultKey: "cmsContent", resultKey: "cmsContent",
promise: cmsContentPromise, promise: cmsContentPromise,
}, ]; },
];
const resultMap = await settleAllPromises(promiseResultMap); const resultMap = await settleAllPromises(promiseResultMap);
// Call the "next" function to complete the transition to this page. // Call the "next" function to complete the transition to this page.
next((vm) => { next((vm) => {
@ -111,17 +121,19 @@ export default {
// Map API result data, to vehicle-parts data structure // Map API result data, to vehicle-parts data structure
const mappedData = partsData.partsOrQuestions.map((g) => { const mappedData = partsData.partsOrQuestions.map((g) => {
return { return {
glassName: g.glassName, glassName: g.glassName,
glassLocation: g.glassLocation, glassLocation: g.glassLocation,
colorAnswers: g.parts.reduce((arr, p) => { colorAnswers: g.parts.reduce((arr, p) => {
arr.push({ arr.push({
ColorAnswerText: p.color, ColorAnswerText: p.color,
FeatureAnswers: [{ FeatureAnswers: [
FeatureAnswerText: p.description === "" ? p.color : p.description, {
FeatureAnswerText:
p.description === "" ? p.color : p.description,
PartNumber: p.partNumber, PartNumber: p.partNumber,
}, ], },
],
}); });
return arr; return arr;
}, []), }, []),
@ -143,7 +155,7 @@ export default {
arePagePrerequisitesValid() { arePagePrerequisitesValid() {
// Check if isRepair is populated and if the pageData we need is here (Parts data) // Check if isRepair is populated and if the pageData we need is here (Parts data)
if ( if (
store.getters.damage.isRepair !== null && (store.getters.damage.isRepair) &&
Object.keys(store.getters.pageData(fmgPageValues.VEHICLE_PARTS)) Object.keys(store.getters.pageData(fmgPageValues.VEHICLE_PARTS))
.length !== 0 .length !== 0
) { ) {
@ -205,8 +217,9 @@ export default {
LoadInitialPartsData() { LoadInitialPartsData() {
const partsData = this.PartsFromApi; const partsData = this.PartsFromApi;
const alreadyPopulatedPartsData = const alreadyPopulatedPartsData =
this.$store.getters.lineItems.glassParts === null ? {} : this.$store.getters.lineItems.glassParts === null
this.$store.getters.lineItems.glassParts; ? {}
: this.$store.getters.lineItems.glassParts;
partsData.partsOrQuestions.map((g) => { partsData.partsOrQuestions.map((g) => {
// If the part is already populated, use the value from the store and populate the v-model. // If the part is already populated, use the value from the store and populate the v-model.
@ -221,10 +234,10 @@ export default {
}); });
}); });
}); });
} },
}, },
mounted() { mounted() {
this.LoadInitialPartsData(); this.LoadInitialPartsData();
} },
}; };
</script> </script>

View file

@ -96,7 +96,10 @@ export default {
); );
}, },
arePagePrerequisitesValid() { arePagePrerequisitesValid() {
return store.getters.vehicle.model !== null; if(store.getters.vehicle.model){
return true;
}
return false;
}, },
resetDependentState() { resetDependentState() {
// Invokes // Invokes

View file

@ -35,8 +35,7 @@ const routes = [
} else { } else {
try { try {
// Check our 'Session' is still good. // Check our 'Session' is still good. If not, reset state and go back to the start.
// If not, reset state and go back to the start.
if (!integrationHelper.isConceptSessionStillActive()) { if (!integrationHelper.isConceptSessionStillActive()) {
baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.RESET_STATE); baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.RESET_STATE);
await GoToFunnelStartOn404(next); await GoToFunnelStartOn404(next);
@ -47,7 +46,14 @@ const routes = [
// On entering the concept funnel "fresh", read cookie information, decide what to do next. // On entering the concept funnel "fresh", read cookie information, decide what to do next.
if (from.redirectedFrom === undefined) { if (from.redirectedFrom === undefined) {
await integrationHelper.loadReferralIfPresent(); await integrationHelper.loadOrderIfPresent();
const pageToRedirectTo = await integrationHelper.getPageToRouteExistingOrderTo();
// Assign our fmgPage so it will load normally like the other pages.
to.query.fmgPage = pageToRedirectTo;
console.log("Page to redirect to: ", pageToRedirectTo);
} }
// If we already have our route, go to it. // If we already have our route, go to it.
@ -117,6 +123,10 @@ router.navigateAfterSave = (scenario, currentRoute, optionalQuery = {}, optional
navigate(scenario, currentRoute, true, optionalQuery, optionalParams, optionalPageData); navigate(scenario, currentRoute, true, optionalQuery, optionalParams, optionalPageData);
} }
router.navigateToExternalUrl = (url, optionalQuery = {}) => {
navigateToUrl(url, optionalQuery);
}
// PRIVATE FUNCTIONS // PRIVATE FUNCTIONS
// Navigate to the next route, depending on the scenario. // Navigate to the next route, depending on the scenario.

View file

@ -1,5 +1,4 @@
import { fmgPageValues } from "@/router/router-constants/fmgPage-values"; import { fmgPageValues } from "@/router/router-constants/fmgPage-values";
import { externalUrls } from "@/router/router-constants/externalUrl-values";
import { navigationScenarios } from "@/router/router-constants/navigation-scenarios"; import { navigationScenarios } from "@/router/router-constants/navigation-scenarios";
const routingTable = [ const routingTable = [
@ -58,10 +57,6 @@ const routingTable = [
scenario: navigationScenarios.CLICKED_BACK, scenario: navigationScenarios.CLICKED_BACK,
destinationFmgPageValue: fmgPageValues.VEHICLE_STYLE, destinationFmgPageValue: fmgPageValues.VEHICLE_STYLE,
}, },
{
scenario: navigationScenarios.MOVE_TO_HERITAGE_FUNNEL,
destinationUrl: externalUrls.HERITAGE_FUNNEL,
},
{ {
scenario: navigationScenarios.SELECTED_DAMAGE_WITH_SINGLE_PART, scenario: navigationScenarios.SELECTED_DAMAGE_WITH_SINGLE_PART,
destinationFmgPageValue: fmgPageValues.REVEAL destinationFmgPageValue: fmgPageValues.REVEAL

View file

@ -152,15 +152,15 @@ export const mutations = {
state.order.referralDate = orderInformation.referralDate; state.order.referralDate = orderInformation.referralDate;
state.order.referralCorrelationId = orderInformation.correlationId; state.order.referralCorrelationId = orderInformation.correlationId;
state.order.vehicle = { state.order.vehicle = {
year: orderInformation.vehicle.year, year: orderInformation.vehicle?.year,
make: orderInformation.vehicle.make, make: orderInformation.vehicle?.make,
model: orderInformation.vehicle.model, model: orderInformation.vehicle?.model,
style: orderInformation.vehicle.style, style: orderInformation.vehicle?.style,
carId: orderInformation.vehicle.carId, carId: orderInformation.vehicle?.carId,
category: orderInformation.vehicle.category, category: orderInformation.vehicle?.category,
imageUrl: orderInformation.vehicle.imageUrl, imageUrl: orderInformation.vehicle?.imageUrl,
imageVifNumber: orderInformation.vehicle.imageVifNumber, imageVifNumber: orderInformation.vehicle?.imageVifNumber,
imageColor: orderInformation.vehicle.imageVifColor imageColor: orderInformation.vehicle?.imageVifColor
}; };
state.order.damage.glassToReplace = orderInformation.glassToReplace; state.order.damage.glassToReplace = orderInformation.glassToReplace;
state.order.damage.isRepair = orderInformation.isRepair; state.order.damage.isRepair = orderInformation.isRepair;