Added flag to 'navigate' method so that we can specify that the order by saved in the .afterEach method of the router. Added new 'navigateWithSaving' and 'navigateWithoutSaving' to allow us to control when the order is saved.

This commit is contained in:
Leah Schumann 2022-08-10 13:46:43 -04:00
parent 56c443ad1a
commit 00f5092dc1
17 changed files with 53 additions and 46 deletions

View file

@ -140,7 +140,7 @@ export default {
}, },
backButtonAction() { backButtonAction() {
// route to move backwards // route to move backwards
this.$router.navigate( this.$router.navigateWithoutSaving(
this.navigationScenarios.CLICKED_BACK, this.navigationScenarios.CLICKED_BACK,
this.$route this.$route
); );
@ -309,11 +309,11 @@ export default {
// If a different vehicle is found than the one entered and the selected glass is not available for that vehicle then navigate back to "vehicle-damage" // If a different vehicle is found than the one entered and the selected glass is not available for that vehicle then navigate back to "vehicle-damage"
// display vehicle changed alert on that page. // display vehicle changed alert on that page.
if (this.isCarIdDifferent && !this.isSelectedGlassAvailableForVehicle && matchingCars.length === 1) { if (this.isCarIdDifferent && !this.isSelectedGlassAvailableForVehicle && matchingCars.length === 1) {
this.$router.navigate(this.navigationScenarios.SELECTED_VIN_HAS_MISMATCHED_GLASS, this.$route, {}, {[routerParams.DISPLAY_VEHICLE_CHANGE_ALERT]: true}); this.$router.navigateWithSaving(this.navigationScenarios.SELECTED_VIN_HAS_MISMATCHED_GLASS, this.$route, {}, {[routerParams.DISPLAY_VEHICLE_CHANGE_ALERT]: true});
} else if (matchingCars.length === 1) { } else if (matchingCars.length === 1) {
await this.navigateForwardWithSingleCarMatch(); await this.navigateForwardWithSingleCarMatch();
} else { } else {
this.$router.navigate(this.navigationScenarios.CONTINUING_WITH_MULTIPLE_VEHICLES, this.$route, {}, {}, carsFound); this.$router.navigateWithSaving(this.navigationScenarios.CONTINUING_WITH_MULTIPLE_VEHICLES, this.$route, {}, {}, carsFound);
} }
}, },

View file

@ -162,7 +162,7 @@ export default {
return false; return false;
}, },
backButtonAction() { backButtonAction() {
this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route); this.$router.navigateWithoutSaving(this.navigationScenarios.CLICKED_BACK, this.$route);
}, },
async forwardButtonAction() { async forwardButtonAction() {
@ -184,7 +184,7 @@ export default {
}, },
async navigateForward() { async navigateForward() {
if (this.isCarIdDifferent && !this.isSelectedGlassAvailableForVehicle) { if (this.isCarIdDifferent && !this.isSelectedGlassAvailableForVehicle) {
this.$router.navigate(this.navigationScenarios.CLICKED_FORWARD,this.$route,{},{[routerParams.DISPLAY_VEHICLE_CHANGE_ALERT]: true },); this.$router.navigateWithSaving(this.navigationScenarios.CLICKED_FORWARD,this.$route,{},{[routerParams.DISPLAY_VEHICLE_CHANGE_ALERT]: true },);
} else { } else {
await this.navigateForwardWithSingleCarMatch(); await this.navigateForwardWithSingleCarMatch();
} }

View file

@ -122,7 +122,7 @@ export default {
}, },
backButtonAction() { backButtonAction() {
// route to move backwards // route to move backwards
this.$router.navigate( this.$router.navigateWithoutSaving(
this.navigationScenarios.CLICKED_BACK, this.navigationScenarios.CLICKED_BACK,
this.$route this.$route
); );

View file

@ -87,7 +87,7 @@ export default {
}, },
backButtonAction() { backButtonAction() {
// route to move backwards // route to move backwards
this.$router.navigate( this.$router.navigateWithoutSaving(
this.navigationScenarios.CLICKED_BACK, this.navigationScenarios.CLICKED_BACK,
this.$route this.$route
); );
@ -95,19 +95,19 @@ export default {
async forwardButtonAction() { async forwardButtonAction() {
if (this.selectedVinLookupMethod === vinLookupMethodSelections.MANUALVIN) { if (this.selectedVinLookupMethod === vinLookupMethodSelections.MANUALVIN) {
await this.dispatchStoreAction(storeActions.CLEAR_VIN); await this.dispatchStoreAction(storeActions.CLEAR_VIN);
return this.$router.navigate( return this.$router.navigateWithSaving(
this.navigationScenarios.SELECTED_MANUAL_VIN, this.navigationScenarios.SELECTED_MANUAL_VIN,
this.$route this.$route
); );
} }
if (this.selectedVinLookupMethod === vinLookupMethodSelections.LICENSEPLATE) { if (this.selectedVinLookupMethod === vinLookupMethodSelections.LICENSEPLATE) {
return this.$router.navigate( return this.$router.navigateWithSaving(
this.navigationScenarios.SELECTED_LICENSE_PLATE, this.navigationScenarios.SELECTED_LICENSE_PLATE,
this.$route this.$route
); );
} }
if (this.selectedVinLookupMethod === vinLookupMethodSelections.HOMEADDRESS) { if (this.selectedVinLookupMethod === vinLookupMethodSelections.HOMEADDRESS) {
return this.$router.navigate( return this.$router.navigateWithSaving(
this.navigationScenarios.SELECTED_HOME_ADDRESS, this.navigationScenarios.SELECTED_HOME_ADDRESS,
this.$route this.$route
); );

View file

@ -177,7 +177,7 @@ export default {
}, },
backButtonAction() { backButtonAction() {
// route to move backwards // route to move backwards
this.$router.navigate( this.$router.navigateWithoutSaving(
this.navigationScenarios.CLICKED_BACK, this.navigationScenarios.CLICKED_BACK,
this.$route this.$route
); );
@ -298,7 +298,7 @@ export default {
}, },
async navigateForward() { async navigateForward() {
if (this.isCarIdDifferent && !this.isSelectedGlassAvailableForVehicle) { if (this.isCarIdDifferent && !this.isSelectedGlassAvailableForVehicle) {
this.$router.navigate(this.navigationScenarios.CLICKED_FORWARD, this.$route, {}, { [routerParams.DISPLAY_VEHICLE_CHANGE_ALERT]: true }); this.$router.navigateWithSaving(this.navigationScenarios.CLICKED_FORWARD, this.$route, {}, { [routerParams.DISPLAY_VEHICLE_CHANGE_ALERT]: true });
} else { } else {
await this.navigateForwardWithSingleCarMatch(); await this.navigateForwardWithSingleCarMatch();
} }

View file

@ -125,7 +125,7 @@ export default {
}, },
backButtonAction() { backButtonAction() {
// route to move backwards // route to move backwards
this.$router.navigate( this.$router.navigateWithoutSaving(
this.navigationScenarios.CLICKED_BACK, this.navigationScenarios.CLICKED_BACK,
this.$route this.$route
); );
@ -156,7 +156,7 @@ export default {
if (hasCapabilityQuestions) { if (hasCapabilityQuestions) {
// if has capability questions // if has capability questions
// go to capability-questions page // go to capability-questions page
this.$router.navigate(this.navigationScenarios.HAS_CAPABILITY_QUESTIONS,this.$route,{},{},{partsOrQuestions: glassNameAndPartsForStore}); this.$router.navigateWithSaving(this.navigationScenarios.HAS_CAPABILITY_QUESTIONS,this.$route,{},{},{partsOrQuestions: glassNameAndPartsForStore});
} else { } else {
// if single parts only // if single parts only
const collectedGlassParts = this.reducedGlassPartsArray(glassNameAndPartsForStore); const collectedGlassParts = this.reducedGlassPartsArray(glassNameAndPartsForStore);

View file

@ -121,7 +121,7 @@ export default {
}, },
backButtonAction() { backButtonAction() {
// route to move backwards // route to move backwards
this.$router.navigate( this.$router.navigateWithoutSaving(
this.navigationScenarios.CLICKED_BACK, this.navigationScenarios.CLICKED_BACK,
this.$route this.$route
); );
@ -155,15 +155,15 @@ export default {
if (hasGlassLocationWithMultipleParts) { if (hasGlassLocationWithMultipleParts) {
// if multiple parts on any glass // if multiple parts on any glass
// go to vehicle-parts page and pass the partsData // go to vehicle-parts page and pass the partsData
this.$router.navigate(this.navigationScenarios.ANSWERED_QUESTIONS_WITH_MULTIPLE_PARTS,this.$route,{},{},{partsOrQuestions: glassNameAndPartsForStore}); this.$router.navigateWithSaving(this.navigationScenarios.ANSWERED_QUESTIONS_WITH_MULTIPLE_PARTS,this.$route,{},{},{partsOrQuestions: glassNameAndPartsForStore});
} else if (hasChildPartQuestions) { } else if (hasChildPartQuestions) {
// if any childpart questions // if any childpart questions
// go to molding-questions page and pass the partsData // go to molding-questions page and pass the partsData
this.$router.navigate(this.navigationScenarios.HAS_MOLDING_QUESTIONS,this.$route,{},{},{partsOrQuestions: glassNameAndPartsForStore}); this.$router.navigateWithSaving(this.navigationScenarios.HAS_MOLDING_QUESTIONS,this.$route,{},{},{partsOrQuestions: glassNameAndPartsForStore});
} else if (hasCapabilityQuestions) { } else if (hasCapabilityQuestions) {
// if has capability questions // if has capability questions
// go to capability-questions page and pass the partsData // go to capability-questions page and pass the partsData
this.$router.navigate(this.navigationScenarios.HAS_CAPABILITY_QUESTIONS,this.$route,{},{},{partsOrQuestions: glassNameAndPartsForStore}); this.$router.navigateWithSaving(this.navigationScenarios.HAS_CAPABILITY_QUESTIONS,this.$route,{},{},{partsOrQuestions: glassNameAndPartsForStore});
} else { } else {
// if single parts only // if single parts only
const collectedGlassParts = this.reducedGlassPartsArray(glassNameAndPartsForStore); const collectedGlassParts = this.reducedGlassPartsArray(glassNameAndPartsForStore);

View file

@ -40,7 +40,7 @@ export default {
methods: { methods: {
backButtonAction() { backButtonAction() {
// route to move backwards // route to move backwards
this.$router.navigate( this.$router.navigateWithoutSaving(
this.navigationScenarios.CLICKED_BACK, this.navigationScenarios.CLICKED_BACK,
this.$route this.$route
); );

View file

@ -170,7 +170,7 @@ export default {
backButtonAction() { backButtonAction() {
// route to move backwards // route to move backwards
this.$router.navigate( this.$router.navigateWithoutSaving(
this.navigationScenarios.CLICKED_BACK, this.navigationScenarios.CLICKED_BACK,
this.$route this.$route
); );
@ -293,10 +293,10 @@ export default {
// If vin already exists, navigate directly to vin-lookup // If vin already exists, navigate directly to vin-lookup
if(store.getters.vehicle.vin) { if(store.getters.vehicle.vin) {
this.$router.navigate(this.navigationScenarios.CLICKED_FORWARD_WITH_VIN, this.$route); this.$router.navigateWithSaving(this.navigationScenarios.CLICKED_FORWARD_WITH_VIN, this.$route);
} }
else { else {
this.$router.navigate(this.navigationScenarios.CLICKED_FORWARD_WITHOUT_VIN, this.$route); this.$router.navigateWithSaving(this.navigationScenarios.CLICKED_FORWARD_WITHOUT_VIN, this.$route);
} }
}, },

View file

@ -70,7 +70,7 @@ export default {
methods: { methods: {
backButtonAction() { backButtonAction() {
// route to move backwards // route to move backwards
this.$router.navigate( this.$router.navigateWithoutSaving(
this.navigationScenarios.CLICKED_BACK, this.navigationScenarios.CLICKED_BACK,
this.$route this.$route
); );
@ -86,7 +86,7 @@ export default {
watch: { watch: {
selectedMake(make) { selectedMake(make) {
this.dispatchStoreAction(storeActions.SAVE_VEHICLE_MAKE, make, false); this.dispatchStoreAction(storeActions.SAVE_VEHICLE_MAKE, make, false);
this.$router.navigate( this.$router.navigateWithSaving(
this.navigationScenarios.SELECTED_MAKE, this.navigationScenarios.SELECTED_MAKE,
this.$route this.$route
); );

View file

@ -71,7 +71,7 @@ export default {
methods: { methods: {
backButtonAction() { backButtonAction() {
// route to move backwards // route to move backwards
this.$router.navigate( this.$router.navigateWithoutSaving(
this.navigationScenarios.CLICKED_BACK, this.navigationScenarios.CLICKED_BACK,
this.$route this.$route
); );
@ -87,7 +87,7 @@ export default {
watch: { watch: {
selectedModel(model) { selectedModel(model) {
this.dispatchStoreAction(storeActions.SAVE_VEHICLE_MODEL, model, false); this.dispatchStoreAction(storeActions.SAVE_VEHICLE_MODEL, model, false);
this.$router.navigate( this.$router.navigateWithSaving(
this.navigationScenarios.SELECTED_MODEL, this.navigationScenarios.SELECTED_MODEL,
this.$route this.$route
); );

View file

@ -162,7 +162,7 @@ export default {
const hasPartQuestions = this.hasPartQuestions(this.$store.getters.pageData(fmgPageValues.PART_QUESTIONS)?.partsOrQuestions); const hasPartQuestions = this.hasPartQuestions(this.$store.getters.pageData(fmgPageValues.PART_QUESTIONS)?.partsOrQuestions);
const backNavigationScenario = hasPartQuestions ? this.navigationScenarios.CLICKED_BACK_WITH_PART_QUESTION_ANSWERS : this.navigationScenarios.CLICKED_BACK_WITHOUT_PART_QUESTION_ANSWERS; const backNavigationScenario = hasPartQuestions ? this.navigationScenarios.CLICKED_BACK_WITH_PART_QUESTION_ANSWERS : this.navigationScenarios.CLICKED_BACK_WITHOUT_PART_QUESTION_ANSWERS;
this.$router.navigate( this.$router.WithoutSaving(
backNavigationScenario, backNavigationScenario,
this.$route this.$route
); );
@ -203,7 +203,7 @@ export default {
// Navigate to the next page // Navigate to the next page
if (hasChildPartQuestions) { if (hasChildPartQuestions) {
this.$router.navigate( this.$router.navigateWithSaving(
this.navigationScenarios.HAS_MOLDING_QUESTIONS, this.navigationScenarios.HAS_MOLDING_QUESTIONS,
this.$route, this.$route,
{}, {},
@ -211,7 +211,7 @@ export default {
{partsOrQuestions: matchedParts} {partsOrQuestions: matchedParts}
); );
} else if (hasCapabilityQuestions) { } else if (hasCapabilityQuestions) {
this.$router.navigate( this.$router.navigateWithSaving(
this.navigationScenarios.HAS_CAPABILITY_QUESTIONS, this.navigationScenarios.HAS_CAPABILITY_QUESTIONS,
this.$route, this.$route,
{}, {},

View file

@ -71,7 +71,7 @@ export default {
methods: { methods: {
backButtonAction() { backButtonAction() {
// route to move backwards // route to move backwards
this.$router.navigate( this.$router.WithoutSaving(
this.navigationScenarios.CLICKED_BACK, this.navigationScenarios.CLICKED_BACK,
this.$route this.$route
); );
@ -99,7 +99,7 @@ export default {
selectedStyle(style) { selectedStyle(style) {
this.dispatchStoreAction(storeActions.SAVE_VEHICLE_STYLE, style, false); this.dispatchStoreAction(storeActions.SAVE_VEHICLE_STYLE, style, false);
this.setVehicle().then(() => { this.setVehicle().then(() => {
this.$router.navigate( this.$router.navigateWithSaving(
this.navigationScenarios.SELECTED_STYLE, this.navigationScenarios.SELECTED_STYLE,
this.$route this.$route
); );

View file

@ -88,7 +88,7 @@ export default {
selectedYear(year) { selectedYear(year) {
const parsedYear = parseInt(year); const parsedYear = parseInt(year);
this.dispatchStoreAction(storeActions.SAVE_VEHICLE_YEAR, parsedYear); this.dispatchStoreAction(storeActions.SAVE_VEHICLE_YEAR, parsedYear);
this.$router.navigate( this.$router.navigateWithSaving(
this.navigationScenarios.SELECTED_YEAR, this.navigationScenarios.SELECTED_YEAR,
this.$route this.$route
); );

View file

@ -211,10 +211,10 @@ export default {
}, },
backButtonAction() { backButtonAction() {
if (this.$store.getters.vehicle.vin) { if (this.$store.getters.vehicle.vin) {
this.$router.navigate(this.navigationScenarios.CLICKED_BACK_WITH_VIN, this.$route); this.$router.navigateWithoutSaving(this.navigationScenarios.CLICKED_BACK_WITH_VIN, this.$route);
} }
else { else {
this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route); this.$router.navigateWithoutSaving(this.navigationScenarios.CLICKED_BACK, this.$route);
} }
}, },
@ -331,7 +331,7 @@ export default {
}, },
async navigateForward(){ async navigateForward(){
if (this.isCarIdDifferent && !this.isSelectedGlassAvailableForVehicle) { if (this.isCarIdDifferent && !this.isSelectedGlassAvailableForVehicle) {
this.$router.navigate(this.navigationScenarios.SELECTED_VIN_HAS_MISMATCHED_GLASS, this.$route, {}, { [routerParams.DISPLAY_VEHICLE_CHANGE_ALERT]: true }); this.$router.navigateWithSaving(this.navigationScenarios.SELECTED_VIN_HAS_MISMATCHED_GLASS, this.$route, {}, { [routerParams.DISPLAY_VEHICLE_CHANGE_ALERT]: true });
} else { } else {
await this.navigateForwardWithSingleCarMatch(); await this.navigateForwardWithSingleCarMatch();
} }

View file

@ -17,16 +17,16 @@ export default {
const hasCapabilityQuestions = this.hasCapabilityQuestions(partsOrQuestions); const hasCapabilityQuestions = this.hasCapabilityQuestions(partsOrQuestions);
if (hasPartsQuestions) { if (hasPartsQuestions) {
this.$router.navigate(this.navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, this.$route, {}, {}, result.data); this.$router.navigateWithSaving(this.navigationScenarios.SELECTED_VIN_WITH_PART_QUESTIONS, this.$route, {}, {}, result.data);
} }
else if (hasGlassLocationWithMultipleParts) { else if (hasGlassLocationWithMultipleParts) {
this.$router.navigate(this.navigationScenarios.SELECTED_VIN_WITH_MULTIPLE_PARTS, this.$route, {}, {}, result.data); this.$router.navigateWithSaving(this.navigationScenarios.SELECTED_VIN_WITH_MULTIPLE_PARTS, this.$route, {}, {}, result.data);
} }
else if (hasChildPartQuestions) { else if (hasChildPartQuestions) {
this.$router.navigate(this.navigationScenarios.SELECTED_VIN_WITH_MOLDING_QUESTIONS, this.$route, {}, {}, result.data); this.$router.navigateWithSaving(this.navigationScenarios.SELECTED_VIN_WITH_MOLDING_QUESTIONS, this.$route, {}, {}, result.data);
} }
else if (hasCapabilityQuestions) { else if (hasCapabilityQuestions) {
this.$router.navigate(this.navigationScenarios.SELECTED_VIN_WITH_CAPABILITY_QUESTIONS, this.$route, {}, {}, result.data); this.$router.navigateWithSaving(this.navigationScenarios.SELECTED_VIN_WITH_CAPABILITY_QUESTIONS, this.$route, {}, {}, result.data);
} }
else { else {
// if single parts only // if single parts only

View file

@ -127,6 +127,13 @@ router.afterEach((to, from) => {
// Push page view to GA // Push page view to GA
analyticsMixin.methods.pushPageViewToGA(to.query[queryStrings.FMG_PAGE]); analyticsMixin.methods.pushPageViewToGA(to.query[queryStrings.FMG_PAGE]);
// If saving on navigation is requested, check for saved SessionId or EmailAddress to determine if saving is appropriate
if (eval(to.params.isSavingNavigation)) {
if (store.getters.applicationUser.savedSessionId || store.getters.order.customer?.emailAddress) {
saveOrder();
}
}
baseMixin.methods.dispatchStoreAction(storeActions.GET_EXPERIMENTS_BY_USER, { userId: getDeviceIdValue() }) baseMixin.methods.dispatchStoreAction(storeActions.GET_EXPERIMENTS_BY_USER, { userId: getDeviceIdValue() })
.then( (response) => { .then( (response) => {
analyticsMixin.methods.pushExperimentsToDataLayer(response.data); analyticsMixin.methods.pushExperimentsToDataLayer(response.data);
@ -134,10 +141,13 @@ router.afterEach((to, from) => {
}); });
router.navigate = (scenario, currentRoute, optionalQuery = {}, optionalParams = {}, optionalPageData) => { router.navigateWithoutSaving = (scenario, currentRoute, optionalQuery = {}, optionalParams = {}, optionalPageData = {}) => {
navigate(scenario, currentRoute, optionalQuery, optionalParams, optionalPageData); navigate(scenario, currentRoute, false, optionalQuery, optionalParams, optionalPageData);
} }
router.navigateWithSaving = (scenario, currentRoute, optionalQuery = {}, optionalParams = {}, optionalPageData = {}) => {
navigate(scenario, currentRoute, true, optionalQuery, optionalParams, optionalPageData);
}
router.navigateToExternalUrl = (url, optionalQuery = {}) => { router.navigateToExternalUrl = (url, optionalQuery = {}) => {
navigateToUrl(url, optionalQuery); navigateToUrl(url, optionalQuery);
@ -146,7 +156,7 @@ router.navigateToExternalUrl = (url, optionalQuery = {}) => {
// PRIVATE FUNCTIONS // PRIVATE FUNCTIONS
// Navigate to the next route, depending on the scenario. // Navigate to the next route, depending on the scenario.
async function navigate(scenario, currentRoute, optionalQuery = {}, optionalParams = {}, optionalPageData) { async function navigate(scenario, currentRoute, isSavingNavigation, 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;
@ -164,10 +174,7 @@ async function navigate(scenario, currentRoute, optionalQuery = {}, optionalPara
baseMixin.methods.savePageDataToStore(destinationFmgPageValue, optionalPageData); baseMixin.methods.savePageDataToStore(destinationFmgPageValue, optionalPageData);
} }
// if cookie and referralNumber/Date exists OR an emailAddress has been saved optionalParams.isSavingNavigation = isSavingNavigation;
if ((getFunnelCookie()?.ReferralNumber && getFunnelCookie()?.ReferralDate) || store.getters.order.customer?.emailAddress) {
saveOrder();
}
router.push({ router.push({
name: "root", name: "root",