Navigation Logic Refactor
This commit is contained in:
parent
abcfa1d11a
commit
3945113287
1 changed files with 63 additions and 117 deletions
|
|
@ -12,38 +12,74 @@ import { includesWindshieldReplacement } from "@/helpers/damage-helper";
|
||||||
import store from "@/store";
|
import store from "@/store";
|
||||||
import router from "@/router";
|
import router from "@/router";
|
||||||
|
|
||||||
/*
|
|
||||||
If the user has visited the funnel before this method will determine the bets place to
|
|
||||||
drop them so they don't start at the beginning again. This method will return 'heritage' if
|
|
||||||
the user has an existing order and they come back in from the Safelite.com CTA.
|
|
||||||
*/
|
|
||||||
export async function getPageToRouteExistingOrderTo(toRoute = {}) {
|
export async function getPageToRouteExistingOrderTo(toRoute = {}) {
|
||||||
const fmgPage = getQuerystringParameter(queryStrings.FMG_PAGE.toLowerCase());
|
const fmgQueryPage = toRoute.query[queryStrings.FMG_PAGE];
|
||||||
if (fmgPage && fmgPage === fmgPageValues.SERVICE_LOCATION) {
|
const hasFmgQueryPage = !!fmgQueryPage;
|
||||||
const serviceLocationComponent = await getLazyLoadedComponent(
|
|
||||||
fmgPageValues.SERVICE_LOCATION
|
if (hasFmgQueryPage) {
|
||||||
);
|
return await getDirectNavigation(toRoute);
|
||||||
if (serviceLocationComponent.methods.arePagePrerequisitesValid()) {
|
} else {
|
||||||
return fmgPageValues.SERVICE_LOCATION;
|
return await getImplicitNavigation(toRoute);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Send the user to the specified page, except in specific scenarios.
|
||||||
|
*/
|
||||||
|
async function getDirectNavigation(toRoute) {
|
||||||
|
const fmgPageValue = toRoute.query[queryStrings.FMG_PAGE];
|
||||||
|
|
||||||
|
// Override if Verified Insurance & Trying to go to vehicle
|
||||||
|
// so vehicle info cannot be overriden.
|
||||||
|
if (
|
||||||
|
store.getters.payment.insuranceCoverage.isVerified &&
|
||||||
|
fmgPageValue === fmgPageValues.VEHICLE
|
||||||
|
) {
|
||||||
|
return fmgPageValues.VEHICLE_DAMAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the user is coming in via the Safelite.Com CTA
|
// Otherwise, respect navigation from query string.
|
||||||
if (toRoute.query[queryStrings.START_TYPE] === "fmg") {
|
return fmgPageValue;
|
||||||
const latestPageRoute = await getLatestPageForRedirection();
|
}
|
||||||
return latestPageRoute;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If navigating to a specific page, and that page is not part of the vin pages.
|
/*
|
||||||
// Return that page, so that it can navigate like normal.
|
* Determine which page in the flow the user should be sent to, based on their current order.
|
||||||
if (toRoute.query[queryStrings.FMG_PAGE] !== undefined && !isVinRelatedPage(toRoute)) {
|
* General strategy: run through pages in reverse order, and select first where prerequisites are valid.
|
||||||
return overrideYmmsDirectionIfNeeded(toRoute);
|
* QUOTE is the latest page to send to.
|
||||||
}
|
*/
|
||||||
|
async function getImplicitNavigation(toRoute) {
|
||||||
|
const vehicleDamageComponent = await getLazyLoadedComponent(fmgPageValues.VEHICLE_DAMAGE);
|
||||||
|
const estimateComponent = await getLazyLoadedComponent(fmgPageValues.ESTIMATE);
|
||||||
|
const vinLookupComponent = await getLazyLoadedComponent(fmgPageValues.VIN_LOOKUP);
|
||||||
|
const partQuestionsComponent = await getLazyLoadedComponent(fmgPageValues.PART_QUESTIONS);
|
||||||
|
const vehiclePartsComponent = await getLazyLoadedComponent(fmgPageValues.VEHICLE_PARTS);
|
||||||
|
const moldingQuestionsComponent = await getLazyLoadedComponent(fmgPageValues.MOLDING_QUESTIONS);
|
||||||
|
const capabilityQuestionsComponent = await getLazyLoadedComponent(
|
||||||
|
fmgPageValues.CAPABILITY_QUESTIONS
|
||||||
|
);
|
||||||
|
const quoteComponent = await getLazyLoadedComponent(fmgPageValues.QUOTE);
|
||||||
|
|
||||||
// If this is not a direct link to a page using fmgPage, not from Safelite.com CTA or this is a vin related page.
|
const skipVin = await skipVinLookup();
|
||||||
// Get the latest page for redirection.
|
|
||||||
const latestPageRoute = await getLatestPageForRedirection();
|
if (quoteComponent.methods.arePagePrerequisitesValid()) {
|
||||||
return latestPageRoute;
|
return fmgPageValues.QUOTE;
|
||||||
|
} else if (capabilityQuestionsComponent.methods.arePagePrerequisitesValid()) {
|
||||||
|
return fmgPageValues.CAPABILITY_QUESTIONS;
|
||||||
|
} else if (moldingQuestionsComponent.methods.arePagePrerequisitesValid()) {
|
||||||
|
return fmgPageValues.MOLDING_QUESTIONS;
|
||||||
|
} else if (vehiclePartsComponent.methods.arePagePrerequisitesValid()) {
|
||||||
|
return fmgPageValues.VEHICLE_PARTS;
|
||||||
|
} else if (partQuestionsComponent.methods.arePagePrerequisitesValid()) {
|
||||||
|
return fmgPageValues.PART_QUESTIONS;
|
||||||
|
} else if (vinLookupComponent.methods.arePagePrerequisitesValid() && !skipVin) {
|
||||||
|
return fmgPageValues.VIN_LOOKUP;
|
||||||
|
} else if (estimateComponent.methods.arePagePrerequisitesValid()) {
|
||||||
|
return fmgPageValues.ESTIMATE;
|
||||||
|
} else if (vehicleDamageComponent.methods.arePagePrerequisitesValid()) {
|
||||||
|
return fmgPageValues.VEHICLE_DAMAGE;
|
||||||
|
} else {
|
||||||
|
return fmgPageValues.VEHICLE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -114,96 +150,6 @@ export async function skipVinLookupNotRepair() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Logic for getting the last "valid" page a user visited.
|
|
||||||
*/
|
|
||||||
async function getLatestPageForRedirection() {
|
|
||||||
// If this is a non-CTA navigation, determine where to send the user based on page prerequisites.
|
|
||||||
// This also works if a user has a 'fmg' start_type query string but no current order.
|
|
||||||
// That shouldn't happen, but it's possible.
|
|
||||||
const vehicleDamageComponent = await getLazyLoadedComponent(fmgPageValues.VEHICLE_DAMAGE);
|
|
||||||
const estimateComponent = await getLazyLoadedComponent(fmgPageValues.ESTIMATE);
|
|
||||||
const vinLookupComponent = await getLazyLoadedComponent(fmgPageValues.VIN_LOOKUP);
|
|
||||||
const partQuestionsComponent = await getLazyLoadedComponent(fmgPageValues.PART_QUESTIONS);
|
|
||||||
const vehiclePartsComponent = await getLazyLoadedComponent(fmgPageValues.VEHICLE_PARTS);
|
|
||||||
const moldingQuestionsComponent = await getLazyLoadedComponent(fmgPageValues.MOLDING_QUESTIONS);
|
|
||||||
const capabilityQuestionsComponent = await getLazyLoadedComponent(
|
|
||||||
fmgPageValues.CAPABILITY_QUESTIONS
|
|
||||||
);
|
|
||||||
const quoteComponent = await getLazyLoadedComponent(fmgPageValues.QUOTE);
|
|
||||||
const serviceLocationComponent = await getLazyLoadedComponent(fmgPageValues.SERVICE_LOCATION);
|
|
||||||
const scheduleComponent = await getLazyLoadedComponent(fmgPageValues.SCHEDULE);
|
|
||||||
|
|
||||||
const skipVin = await skipVinLookup();
|
|
||||||
|
|
||||||
if (!vehicleDamageComponent.methods.arePagePrerequisitesValid()) {
|
|
||||||
return fmgPageValues.VEHICLE;
|
|
||||||
} else if (!estimateComponent.methods.arePagePrerequisitesValid()) {
|
|
||||||
return fmgPageValues.VEHICLE_DAMAGE;
|
|
||||||
} else {
|
|
||||||
if (quoteComponent.methods.arePagePrerequisitesValid()) {
|
|
||||||
return fmgPageValues.QUOTE;
|
|
||||||
} else if (capabilityQuestionsComponent.methods.arePagePrerequisitesValid()) {
|
|
||||||
return fmgPageValues.CAPABILITY_QUESTIONS;
|
|
||||||
} else if (moldingQuestionsComponent.methods.arePagePrerequisitesValid()) {
|
|
||||||
return fmgPageValues.MOLDING_QUESTIONS;
|
|
||||||
} else if (vehiclePartsComponent.methods.arePagePrerequisitesValid()) {
|
|
||||||
return fmgPageValues.VEHICLE_PARTS;
|
|
||||||
} else if (partQuestionsComponent.methods.arePagePrerequisitesValid()) {
|
|
||||||
return fmgPageValues.PART_QUESTIONS;
|
|
||||||
} else if (
|
|
||||||
// capture vin
|
|
||||||
vinLookupComponent.methods.arePagePrerequisitesValid() &&
|
|
||||||
!skipVin
|
|
||||||
) {
|
|
||||||
return fmgPageValues.VIN_LOOKUP;
|
|
||||||
} else {
|
|
||||||
// do not capture vin
|
|
||||||
return fmgPageValues.ESTIMATE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Overrides functionality to go to the YMMS pages in certain cases.
|
|
||||||
If this is not one of the cases, it returns the 'to' fmgPage value.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* istanbul ignore next */
|
|
||||||
function overrideYmmsDirectionIfNeeded(toRoute) {
|
|
||||||
const fmgPageValue = toRoute.query[queryStrings.FMG_PAGE];
|
|
||||||
|
|
||||||
if (store.getters.payment.insuranceCoverage.isVerified) {
|
|
||||||
switch (fmgPageValue) {
|
|
||||||
case fmgPageValues.VEHICLE: {
|
|
||||||
return fmgPageValues.VEHICLE_DAMAGE;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
return fmgPageValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return fmgPageValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Determine if the page is a vin related page.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* istanbul ignore next */
|
|
||||||
function isVinRelatedPage(toRoute) {
|
|
||||||
const fmgPageValue = toRoute.query[queryStrings.FMG_PAGE];
|
|
||||||
|
|
||||||
return (
|
|
||||||
fmgPageValue === fmgPageValues.VIN_LOOKUP ||
|
|
||||||
fmgPageValue === fmgPageValues.LICENSE_PLATE_LOOKUP ||
|
|
||||||
fmgPageValue === fmgPageValues.ADDRESS_LOOKUP ||
|
|
||||||
fmgPageValue === fmgPageValues.ADDRESS_VEHICLES ||
|
|
||||||
fmgPageValue === fmgPageValues.ESTIMATE
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getLazyLoadedComponent(pageName) {
|
async function getLazyLoadedComponent(pageName) {
|
||||||
return (await lazyLoadComponent(pageName)()).default;
|
return (await lazyLoadComponent(pageName)()).default;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue