diff --git a/src/store/index.js b/src/store/index.js index 03dda415..f29b2a4e 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -5,6 +5,7 @@ import globalMethods from "@/global-methods"; import { experimentTriggers } from "@/constants/experiments"; import { applicationConfig } from "@/constants/application-config"; import { issPageValues } from "@/router/router-constants/issPage-values"; +import { damageLocationsSelected } from "@/constants/damage-locations-selected"; const storeId = 'main'; @@ -43,6 +44,12 @@ const getDefaultState = () => { lineItems: { glassParts: null, }, + payment: { + isInsurance: true, + insuranceCoverage: { + isVerified: false, + }, + }, serviceLocation: { address: null, city: null, @@ -92,39 +99,37 @@ export const useMainStore = defineStore({ }, experimentOrder: (state) => { return { - funnelVehicleYear: state.order.vehicle.year, - funnelVehicleMake: state.order.vehicle.make, - funnelVehicleModel: state.order.vehicle.model, - funnelVehicleStyle: state.order.vehicle.style, - funnelIsRepair: state.order.damage.isRepair, - funnelNumberOfChips: state.order.damage.numberOfChips, - funnelCarId: state.order.vehicle.carId, - funnelServiceCity: state.order.serviceLocation.city, - funnelServiceState: state.order.serviceLocation.state, - funnelServiceZipCode: state.order.serviceLocation.zipCode, - funnelParentAccountNumber: state.order.accountNumber, - //funnelIsCoverageVerified: state.order.payment.insuranceCoverage.isVerified, - //funnelHasRecalibrationPart: getHasRecalibrationPart(state), - funnelSelectedMultiGlass: state.order.damage.glassToReplace?.length > 1, - /* - funnelSelectedWindshieldGlass: getNonFalseValuesOfPropertyInArrayOfObjects( + issVehicleYear: state.order.vehicle.year, + issVehicleMake: state.order.vehicle.make, + issVehicleModel: state.order.vehicle.model, + issVehicleStyle: state.order.vehicle.style, + issIsRepair: state.order.damage.isRepair, + issNumberOfChips: state.order.damage.numberOfChips, + issCarId: state.order.vehicle.carId, + issServiceCity: state.order.serviceLocation.city, + issServiceState: state.order.serviceLocation.state, + issServiceZipCode: state.order.serviceLocation.zipCode, + issParentAccountNumber: state.order.accountNumber, + issIsCoverageVerified: state.order.payment.insuranceCoverage.isVerified, + issHasRecalibrationPart: getHasRecalibrationPart(state), + issSelectedMultiGlass: state.order.damage.glassToReplace?.length > 1, + issSelectedWindshieldGlass: getNonFalseValuesOfPropertyInArrayOfObjects( state.order.damage.glassToReplace, "glassLocation" ).includes(damageLocationsSelected.WINDSHIELD), - funnelSelectedBackGlass: getNonFalseValuesOfPropertyInArrayOfObjects( + issSelectedBackGlass: getNonFalseValuesOfPropertyInArrayOfObjects( state.order.damage.glassToReplace, "glassLocation" ).includes(damageLocationsSelected.REAR), - funnelSelectedDriverSideGlass: getNonFalseValuesOfPropertyInArrayOfObjects( + issSelectedDriverSideGlass: getNonFalseValuesOfPropertyInArrayOfObjects( state.order.damage.glassToReplace, "glassLocation" ).includes(damageLocationsSelected.DRIVER), - funnelSelectedPassengerSideGlass: getNonFalseValuesOfPropertyInArrayOfObjects( + issSelectedPassengerSideGlass: getNonFalseValuesOfPropertyInArrayOfObjects( state.order.damage.glassToReplace, "glassLocation" ).includes(damageLocationsSelected.PASSENGER), - */ - funnelOrderPartNumbers: [ + issOrderPartNumbers: [ ...getNonFalseValuesOfPropertyInArrayOfObjects( state.order.lineItems.glassParts, "partNumber" @@ -135,7 +140,7 @@ export const useMainStore = defineStore({ ), ], - funnelOrderPartTypes: [ + issOrderPartTypes: [ ...getNonFalseValuesOfPropertyInArrayOfObjects( state.order.lineItems.glassParts, "recalibrationType" @@ -532,6 +537,40 @@ export const useMainStore = defineStore({ persist: true }); + +// Private Functions + +function getHasRecalibrationPart(state) { + var hasRequiresRecalibration = + getNonFalseValuesOfPropertyInArrayOfObjects( + state.order.lineItems.glassParts, + "requiresRecalibration" + )?.length > 0; + var hasRecalibrationType = + getNonFalseValuesOfPropertyInArrayOfObjects( + state.order.lineItems.glassParts, + "recalibrationType" + )?.length > 0; + + if (hasRequiresRecalibration) { + if (hasRecalibrationType) { + // Has both 'requiresRecalibration' and 'recalibrationType' and 'recalibrationType' + return ( + getNonFalseValuesOfPropertyInArrayOfObjects( + state.order.lineItems.glassParts, + "recalibrationType" + )[0].toLowerCase() != "unknown" + ); + } else { + // Has 'requiresRecalibration' but no 'recalibrationType' at all + return true; + } + } else { + // Does not have 'requiresRecalibration' + return false; + } +} + function getNonFalseValuesOfPropertyInArrayOfObjects(array, propertyName) { return (array ?? []).map((x) => x[propertyName]).filter((x) => x); }