This commit is contained in:
Jason Wheeler 2023-01-10 17:16:39 -05:00
parent 49dd239f53
commit c3d164cc2c
3 changed files with 141 additions and 53 deletions

View file

@ -75,6 +75,10 @@ const endpoints = {
url: "/experiments/api/v1/experiments/run",
method: "POST",
},
ValidateZip: {
url: "/location/api/v1/location/zip",
method: "GET",
},
};
export { endpoints };

View file

@ -111,7 +111,7 @@ defineRule(
export default {
name: "address-lookup",
//mixins: [vinPagesMixin],
mixins: [vinPagesMixin],
async beforeRouteEnter(to, from, next) {
// Call APIs
const cmsContentPromise = fetchCmsContentForPage(to.query.issPage);
@ -135,16 +135,16 @@ export default {
return {
customerQuestions: {
addressQuestions: {
streetAddress: this.getRegistrationAddressFromStore(),
city: this.getRegistrationCityFromStore(),
state: this.getRegistrationStateFromStore(),
zipCode: this.getRegistrationZipFromStore(),
streetAddress: this.registrationAddress,
city: this.registrationCity,
state: this.registrationState,
zipCode: this.registrationZip,
},
firstName: this.getRegistrationFirstNameFromStore(),
lastName: this.getRegistrationLastNameFromStore(),
emailAddress: this.getEmailFromStore(),
firstName: this.registrationFirstName,
lastName: this.registrationLastName,
emailAddress: this.getEmailFromStore,
},
serviceZipCode: this.getServiceZipFromStore(),
serviceZipCode: this.serviceZip,
displayNonServiceableZipAlert: false,
displayVinNotFoundAlert: false,
displayMatchedDifferentVehicleAlert: false,
@ -154,13 +154,39 @@ export default {
isSelectedGlassAvailableForVehicle: true,
customAlertData: {},
displayInvalidZipAlert: false,
showServiceZipField: this.getServiceZipFromStore(),
showServiceZipField: this.serviceZip,
isZipServiceable: false,
};
},
computed: {
registrationAddress() {
return this.mainStore.order.vehicle.registration.address;
},
registrationCity() {
return this.mainStore.order.vehicle.registration.city;
},
registrationState() {
return this.mainStore.order.vehicle.registration.state;
},
registrationZip() {
return this.mainStore.order.vehicle.registration.zipCode;
},
registrationFirstName() {
return this.mainStore.order.vehicle.registration.firstName;
},
registrationLastName() {
return this.mainStore.order.vehicle.registration.lastName;
},
getEmailFromStore() {
return this.mainStore.order.customer.emailAddress;
},
serviceZip() {
return this.mainStore.order.serviceLocation.zipCode;
}
},
methods: {
arePagePrerequisitesValid() {
return this.mainStore.order.vehicle.carId !== null;
return useMainStore().order.vehicle.carId !== null;
},
backButtonAction() {
// route to move backwards
@ -176,30 +202,7 @@ export default {
);
});
},
getRegistrationAddressFromStore() {
return useMainStore().order.vehicle.registration.address;
},
getRegistrationCityFromStore() {
return useMainStore().order.vehicle.registration.city;
},
getRegistrationStateFromStore() {
return useMainStore().order.vehicle.registration.state;
},
getRegistrationZipFromStore() {
return useMainStore().order.vehicle.registration.zipCode;
},
getRegistrationFirstNameFromStore() {
return useMainStore().order.vehicle.registration.firstName;
},
getRegistrationLastNameFromStore() {
return useMainStore().order.vehicle.registration.lastName;
},
getEmailFromStore() {
return useMainStore().order.customer.emailAddress;
},
getServiceZipFromStore() {
return useMainStore().order.serviceLocation.zipCode;
},
async forwardButtonAction() {
this.resetWarningsAndErrors();
@ -229,12 +232,8 @@ export default {
{
resultKey: "serviceZipValidationResponse",
promise: this.serviceZipCode
? this.dispatchStoreAction(storeActions.VALIDATE_ZIP, {
zip: this.serviceZipCode,
})
: this.dispatchStoreAction(storeActions.VALIDATE_ZIP, {
zip: this.customerQuestions.addressQuestions.zipCode,
}),
? useMainStore().validateZip({zip: this.serviceZipCode})
: useMainStore().validateZip({zip: this.customerQuestions.addressQuestions.zipCode})
},
];
@ -314,8 +313,7 @@ export default {
}
// Save vehicle, customer, service and registration information
await this.dispatchStoreAction(
storeActions.SAVE_REGISTRATION_ADDRESS_LOOKUP,
await useMainStore().saveRegistrationAddressLookup(
{
isSelectedGlassAvailableForVehicle: this.isSelectedGlassAvailableForVehicle,
vehicleInfo:
@ -334,13 +332,7 @@ export default {
false
);
await this.dispatchStoreAction(
storeActions.SAVE_EMAIL,
this.customerQuestions.emailAddress,
false
);
await this.dispatchStoreAction(
storeActions.SAVE_SERVICE_LOCATION,
await useMainStore().saveServiceLocation(
{
address: this.customerQuestions.addressQuestions.streetAddress,
city: this.customerQuestions.addressQuestions.city,
@ -416,7 +408,7 @@ export default {
},
AlertMatchedDifferentVehicleBody() {
const vinYmmFound = `${this.customAlertData?.vehicleInfo?.year} ${this.customAlertData?.vehicleInfo?.make} ${this.customAlertData?.vehicleInfo?.model}`;
const vinYmmExpected = `${useMainStore().order.vehicle.year} ${useMainStore().order.vehicle.make} ${useMainStore().order.vehicle.model}`;
const vinYmmExpected = `${this.mainStore.order.vehicle.year} ${this.mainStore.order.vehicle.make} ${this.mainStore.order.vehicle.model}`;
return this.getCmsContent("AlertMatchedDifferentVehicleWidget", "BodyText")
.replaceAll("{custom:glassText}", getDamageString())

View file

@ -49,10 +49,13 @@ const getDefaultState = () => {
city: null,
state: null,
zipCode: null,
zipCodeCtu: null
},
lineItems: {
glassParts: null,
otherParts: null
otherParts: null,
supportingItems: null,
vaps: null
},
payment: {
isInsurance: true,
@ -358,7 +361,43 @@ export const useMainStore = defineStore({
this.updateNumberOfChips(isWindshieldRepair ? parseInt(selectedWindshieldChipCount) : null);
this.updateGlassToReplace(selectedGlassToReplace);
}
},
},
updateRegistration(registrationInfo) {
this.order.vehicle.registration.licensePlate = registrationInfo?.licensePlate;
this.order.vehicle.registration.address = registrationInfo?.address;
this.order.vehicle.registration.city = registrationInfo?.city;
this.order.vehicle.registration.state = registrationInfo?.state;
this.order.vehicle.registration.zipCode = registrationInfo?.zipCode;
this.order.vehicle.registration.firstName = registrationInfo?.firstName;
this.order.vehicle.registration.lastName = registrationInfo?.lastName;
},
updateServiceLocation(serviceLocationInfo) {
this.order.serviceLocation.address = serviceLocationInfo.address;
this.order.serviceLocation.city = serviceLocationInfo.city;
this.order.serviceLocation.state = serviceLocationInfo.state;
this.order.serviceLocation.zipCode = serviceLocationInfo.zipCode;
this.order.serviceLocation.zipCodeCtu = serviceLocationInfo.zipCodeCtu;
},
resetRegistrationState() {
this.order.vehicle.registration.licensePlate = null;
this.order.vehicle.registration.address = null;
this.order.vehicle.registration.city = null;
this.order.vehicle.registration.state = null;
this.order.vehicle.registration.zipCode = null;
this.order.vehicle.registration.firstName = null;
this.order.vehicle.registration.lastName = null;
},
updateSupportingItems(partsData) {
this.order.lineItems.supportingItems = partsData;
},
updateVaps(partsData) {
this.order.lineItems.vaps = partsData;
},
updateVehicle(vehicle) {
this.order.vehicle.carId = vehicle.carId;
@ -697,6 +736,59 @@ export const useMainStore = defineStore({
this.updateExperiments(response.data.experiments);
},
async validateZip({ zip }) {
return await globalMethods.callHttpClient({
methods: endpoints.ValidateZip.method,
endpoint: `${endpoints.ValidateZip.url}/${zip}`,
});
},
saveServiceLocation(serviceLocationInfo) {
this.updateServiceLocation(serviceLocationInfo);
},
saveRegistrationAddressLookup({ isSelectedGlassAvailableForVehicle, vehicleInfo, registrationInfo }) {
//Reset dependent state when changing
if
(
registrationInfo?.address !== this.order.vehicle.registration?.address ||
registrationInfo?.city !== this.order.vehicle.registration?.city ||
registrationInfo?.state !== this.order.vehicle.registration?.state ||
registrationInfo?.zipCode !== this.order.vehicle.registration?.zipCode ||
registrationInfo?.firstName !== this.order.vehicle.registration?.firstName ||
registrationInfo?.lastName !== this.order.vehicle.registration?.lastName
)
{
this.resetRegistrationAndDependencies();
if (!isSelectedGlassAvailableForVehicle) {
this.resetDamageAndDependencies();
this.resetPartsAndDependencies();
}
//Save new values
this.updateVehicle(vehicleInfo);
this.updateRegistration(registrationInfo);
}
},
resetRegistrationAndDependencies() {
this.resetRegistrationState();
this.resetGlassPartsState();
this.updateSupportingItems(null);
},
resetDamageAndDependencies() {
this.resetDamageState();
this.resetGlassPartsState();
this.updateSupportingItems(null);
this.updateVaps(null);
},
resetPartsAndDependencies() {
this.resetGlassPartsState();
this.updateSupportingItems(null);
},
},
persist: true
});