navigation from license-plate-lookup

This commit is contained in:
Kroell 2023-01-16 14:27:14 -05:00
parent 49db6154b7
commit 775f461170

View file

@ -50,6 +50,8 @@ import { useMainStore } from '@/store';
import { errorMessages } from "@/constants/error-messages"; import { errorMessages } from "@/constants/error-messages";
import { required, regex } from "@/helpers/validation-rules"; import { required, regex } from "@/helpers/validation-rules";
import { defineRule } from "vee-validate"; import { defineRule } from "vee-validate";
import { isGlassAvailableForCarId } from '@/helpers/damage-helper.js';
import { routerParams } from '@/router/router-params.js'
// Import Component // Import Component
import baseFormMixin from '@/mixins/base-form-mixin'; import baseFormMixin from '@/mixins/base-form-mixin';
@ -77,6 +79,7 @@ export default {
vehicleBanner, vehicleBanner,
textboxQuestion, textboxQuestion,
licensePlateLookupAlerts, licensePlateLookupAlerts,
isGlassAvailableForCarId
}, },
setup() { setup() {
const mainStore = useMainStore(); const mainStore = useMainStore();
@ -86,10 +89,10 @@ export default {
data() { data() {
return { return {
activeVehicleLookupAlertType: null, activeVehicleLookupAlertType: null,
needToLookupVehicle: true,
vehicleFromLookup: null, vehicleFromLookup: null,
licensePlate: null, licensePlate: null,
registrationZipCode: null, registrationZipCode: null,
isCarIdDifferent: false,
}; };
}, },
provide() { provide() {
@ -114,6 +117,14 @@ export default {
vm.setCmsContent(resultMap.cmsContent); vm.setCmsContent(resultMap.cmsContent);
}); });
}, },
computed: {
isCarIdDifferentFromTheStore() {
return (
this.vehicleFromLookup !== null
&& this.vehicleFromLookup.carId !== this.mainStore.vehicle.carId
);
}
},
methods: { methods: {
arePagePrerequisitesValid() { arePagePrerequisitesValid() {
if (this.mainStore.order.vehicle.carId) { if (this.mainStore.order.vehicle.carId) {
@ -127,33 +138,33 @@ export default {
*/ */
this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route); this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route);
}, },
// NOTE: If form is not valid, this method is not called when 'Continue' button is clicked
async forwardButtonAction() { async forwardButtonAction() {
this.resetActiveAlert(); this.resetActiveAlert();
// NOTE: If form is not valid, this method is not called when 'Continue' button is clicked if (this.needToLookupVehicle) {
const vehicleLookupResponse = await this.mainStore.lookupVinByPlate(this.licensePlate); const vehicleLookupResponse = await this.mainStore.lookupVinByPlate(this.licensePlate);
if (vehicleLookupResponse.error) { if (vehicleLookupResponse.error) {
this.activeVehicleLookupAlertType = vehicleLookupAlertTypes.NOT_FOUND; this.activeVehicleLookupAlertType = vehicleLookupAlertTypes.NOT_FOUND;
this.resetVehicleFromLookup(); this.resetVehicleFromLookup();
this.$refs.siteFooter.removeLoader(); this.$refs.siteFooter.removeLoader();
return; return;
} }
}
this.vehicleFromLookup = vehicleLookupResponse.data.vehicle; this.vehicleFromLookup = vehicleLookupResponse.data.vehicle;
if (this.vehicleFromLookup.carId !== this.mainStore.vehicle.carId) {
if (this.needToLookupVehicle && this.isCarIdDifferentFromTheStore) {
this.activeVehicleLookupAlertType = vehicleLookupAlertTypes.NOT_MATCHED; this.activeVehicleLookupAlertType = vehicleLookupAlertTypes.NOT_MATCHED;
this.isCarIdDifferent = true;
const vehicleYearMakeModel = `${this.vehicleFromLookup.year} ${this.vehicleFromLookup.make} ${this.vehicleFromLookup.model}`; const vehicleYearMakeModel = `${this.vehicleFromLookup.year} ${this.vehicleFromLookup.make} ${this.vehicleFromLookup.model}`;
this.$refs.siteFooter.updateButtonText(`Continue with ${vehicleYearMakeModel}`); this.$refs.siteFooter.updateButtonText(`Continue with ${vehicleYearMakeModel}`);
this.$refs.siteFooter.removeLoader(); this.$refs.siteFooter.removeLoader();
this.needToLookupVehicle = false;
} }
// Continue if (this.isCarIdDifferentFromTheStore && !this.isSelectedGlassAvailableForVehicle) {
},
async navigateForward() {
if (this.isCarIdDifferent && !this.isSelectedGlassAvailableForVehicle) {
this.$router.navigate( this.$router.navigate(
this.navigationScenarios.CLICKED_FORWARD, this.navigationScenarios.CLICKED_FORWARD,
this.$route, this.$route,
@ -161,10 +172,13 @@ export default {
{ [routerParams.DISPLAY_VEHICLE_CHANGE_ALERT]: true } { [routerParams.DISPLAY_VEHICLE_CHANGE_ALERT]: true }
); );
} else { } else {
await this.navigateForwardWithSingleCarMatch(); await this.$router.navigate(
this.navigationScenarios.CLICKED_FORWARD_WITH_NO_MORE_QUESTIONS,
this.$route
);
} }
// Continue
}, },
resetActiveAlert() { resetActiveAlert() {
this.activeVehicleLookupAlertType = null; this.activeVehicleLookupAlertType = null;
}, },