From 9b75367894a99da601a44ce2fa85d61a231ab5fa Mon Sep 17 00:00:00 2001 From: Chloe Herd Date: Tue, 20 Jun 2023 15:09:00 -0400 Subject: [PATCH] Update with better cascading logic. --- src/constants/store-actions.js | 1 + src/store/index.js | 35 +++++++++++++++++----------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/constants/store-actions.js b/src/constants/store-actions.js index ebffdebde..392e7b59e 100644 --- a/src/constants/store-actions.js +++ b/src/constants/store-actions.js @@ -54,6 +54,7 @@ const storeActions = { RESET_DAMAGE_STATE_AND_DEPENDENCIES: "resetDamageAndDependencies", RESET_REGISTRATION_STATE_AND_DEPENDENCIES: "resetRegistrationAndDependencies", RESET_PARTS_STATE_AND_DEPENDENCIES: "resetPartsAndDependencies", + RESET_SERVICE_LOCATION_STATE_AND_DEPENDENCIES: "resetServiceLocationAndDependencies", RESET_STATE: "resetState", // SAVE COMPONENT STATE diff --git a/src/store/index.js b/src/store/index.js index 99a28e212..7ad5c4457 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -343,7 +343,7 @@ export const mutations = { //early bird fee used on schedule page also needs reset when schedule is reset const supportingItems = state.order.lineItems.supportingItems; - const removeEarlyBirdIndex = supportingItems.findIndex( + const removeEarlyBirdIndex = supportingItems?.findIndex( (item) => item.partType == PREMIUM_FEE_PART_TYPE ); @@ -726,6 +726,15 @@ export const actions = { resetPartsAndDependencies(context) { context.commit(storeMutations.RESET_GLASS_PARTS_STATE); context.commit(storeMutations.UPDATE_SUPPORTING_ITEMS, null); + + context.dispatch(storeActions.RESET_SERVICE_LOCATION_STATE_AND_DEPENDENCIES); + }, + + resetServiceLocationAndDependencies(context) { + context.commit(storeMutations.RESET_SERVICE_LOCATION_APPOINTMENT_TYPE); + context.commit(storeMutations.RESET_SERVICE_LOCATION_PROVIDER); + + context.commit(storeMutations.RESET_SCHEDULE); }, resetState(context) { @@ -1777,10 +1786,7 @@ export const actions = { saveSupportingItems(context, supportingItems) { if (!deepEqual(supportingItems, context.state.order.lineItems.supportingItems)) { - context.commit(storeMutations.RESET_SERVICE_LOCATION_APPOINTMENT_TYPE); - context.commit(storeMutations.RESET_SERVICE_LOCATION_PROVIDER); - - context.commit(storeMutations.RESET_SCHEDULE); + context.dispatch(storeActions.RESET_SERVICE_LOCATION_STATE_AND_DEPENDENCIES); } context.commit(storeMutations.UPDATE_SUPPORTING_ITEMS, supportingItems); @@ -1856,26 +1862,24 @@ export const actions = { context.state.order.serviceLocation && serviceZipCodeInfo.zipCode !== context.state.order.serviceLocation.zipCode ) { - context.commit(storeMutations.RESET_SERVICE_LOCATION_APPOINTMENT_TYPE); - context.commit(storeMutations.RESET_SERVICE_LOCATION_PROVIDER); - context.commit(storeMutations.RESET_SERVICE_LOCATION_MOBILE_ADDRESS); + context.dispatch(storeActions.RESET_SERVICE_LOCATION_STATE_AND_DEPENDENCIES); - context.commit(storeMutations.RESET_SCHEDULE); + context.commit(storeMutations.RESET_SERVICE_LOCATION_MOBILE_ADDRESS); } context.commit(storeMutations.UPDATE_SERVICE_LOCATION, serviceZipCodeInfo); }, saveServiceLocation(context, serviceLocationInfo) { - if (context.state.order.serviceLocationInfo) { + if (context.state.order.serviceLocation) { if ( - serviceLocationInfo.zipCode !== context.state.order.serviceLocationInfo.zipCode || + serviceLocationInfo.zipCode !== context.state.order.serviceLocation.zipCode || !deepEqual( serviceLocationInfo.provider, - context.state.order.serviceLocationInfo.provider + context.state.order.serviceLocation.provider ) || serviceLocationInfo.appointmentType !== - context.state.order.serviceLocationInfo.appointmentType + context.state.order.serviceLocation.appointmentType ) { context.commit(storeMutations.RESET_SCHEDULE); } @@ -1903,10 +1907,7 @@ export const actions = { saveGlassParts(context, parts) { if (!deepEqual(parts, context.state.order.lineItems.glassParts)) { - context.commit(storeMutations.RESET_SERVICE_LOCATION_APPOINTMENT_TYPE); - context.commit(storeMutations.RESET_SERVICE_LOCATION_PROVIDER); - - context.commit(storeMutations.RESET_SCHEDULE); + context.dispatch(storeActions.RESET_SERVICE_LOCATION_STATE_AND_DEPENDENCIES); } context.commit(storeMutations.UPDATE_GLASS_PARTS, parts);