From 53160a51196515f70d5a25c0c659849681725b46 Mon Sep 17 00:00:00 2001 From: Jason Wheeler Date: Fri, 11 Nov 2022 12:51:43 -0500 Subject: [PATCH] updated to clear the entire vehicle object. Additional store items can be added to resetVehicle method as they are added to the store. --- src/layouts/vehicle-make/vehicle-make.vue | 3 +- src/layouts/vehicle-model/vehicle-model.vue | 3 +- src/layouts/vehicle-style/vehicle-style.vue | 11 +++++++- src/layouts/vehicle-year/vehicle-year.vue | 2 +- src/store/index.js | 31 ++++++++++++++++++++- 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/layouts/vehicle-make/vehicle-make.vue b/src/layouts/vehicle-make/vehicle-make.vue index 9b92378f..3261ae92 100644 --- a/src/layouts/vehicle-make/vehicle-make.vue +++ b/src/layouts/vehicle-make/vehicle-make.vue @@ -92,7 +92,8 @@ selectedMake(make) { if(make != this.mainStore.order.vehicle.make) { - this.mainStore.updateVehicle({make, model: null, style: null}); + const vehicle = this.mainStore.order.vehicle; + this.mainStore.updateVehicle( { year: vehicle.year, make }, true ); } this.$router.navigate( this.navigationScenarios.SELECTED_MAKE, diff --git a/src/layouts/vehicle-model/vehicle-model.vue b/src/layouts/vehicle-model/vehicle-model.vue index 240656d9..443585ec 100644 --- a/src/layouts/vehicle-model/vehicle-model.vue +++ b/src/layouts/vehicle-model/vehicle-model.vue @@ -85,7 +85,8 @@ selectedModel(model) { if(model != this.mainStore.order.vehicle.model) { - this.mainStore.updateVehicle({model, style: null}); + const vehicle = this.mainStore.order.vehicle; + this.mainStore.updateVehicle( { year: vehicle.year, make: vehicle.make, model }, true ); } this.$router.navigate( this.navigationScenarios.SELECTED_MODEL, diff --git a/src/layouts/vehicle-style/vehicle-style.vue b/src/layouts/vehicle-style/vehicle-style.vue index 8beac5cc..225fae09 100644 --- a/src/layouts/vehicle-style/vehicle-style.vue +++ b/src/layouts/vehicle-style/vehicle-style.vue @@ -79,7 +79,16 @@ export default { selectedStyle(style) { if(style != this.mainStore.order.vehicle.style) { - this.mainStore.updateVehicle({style}); + const vehicle = this.mainStore.order.vehicle; + this.mainStore.updateVehicle( + { + year: vehicle.year, + make: vehicle.make, + model: vehicle.model, + style + }, + true + ); } this.mainStore.setVehicle().then(() => { diff --git a/src/layouts/vehicle-year/vehicle-year.vue b/src/layouts/vehicle-year/vehicle-year.vue index bf302812..1f0e7f5e 100644 --- a/src/layouts/vehicle-year/vehicle-year.vue +++ b/src/layouts/vehicle-year/vehicle-year.vue @@ -71,7 +71,7 @@ const parsedYear = parseInt(year); if(parsedYear != this.mainStore.order.vehicle.year) { - this.mainStore.updateVehicle({year: parsedYear, make: null, model: null, style: null}); + this.mainStore.updateVehicle( { year: parsedYear }, true ); } this.$router.navigate( diff --git a/src/store/index.js b/src/store/index.js index 2c733ed7..3fb78d66 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -131,10 +131,39 @@ export const useMainStore = defineStore({ }); }, - updateVehicle(vehicle) + updateVehicle(vehicle, reset = false) { + if(reset) + { + this.resetVehicle(); + } this.order.vehicle = { ...this.order.vehicle, ...vehicle }; }, + + resetVehicle() + { + this.order.vehicle = { + year: null, + make: null, + model: null, + style: null, + carId: null, + category: null, + vin: null, + imageUrl: null, + imageVifNumber: null, + imageColor: null, + registration: { + licensePlate: null, + address: null, + city: null, + state: null, + zipCode: null, + firstName: null, + lastName: null, + }, + } + }, addEventToBus (event) { this.applicationUser.eventBus.push(event);