From 4b4ebd18184762d3f4b90506ea1603365f629076 Mon Sep 17 00:00:00 2001 From: k2maan Date: Thu, 30 Nov 2023 12:46:34 +0530 Subject: [PATCH 1/2] Improved: code by updating facilities state on updation instead of refetching --- src/store/modules/facility/actions.ts | 4 ++++ src/views/FindFacilities.vue | 22 ++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/store/modules/facility/actions.ts b/src/store/modules/facility/actions.ts index e614c4be..39dcf171 100644 --- a/src/store/modules/facility/actions.ts +++ b/src/store/modules/facility/actions.ts @@ -117,6 +117,10 @@ const actions: ActionTree = { } }, + updateFacilities({ commit }, facilities) { + commit(types.FACILITY_LIST_UPDATED, { facilities, total: facilities.length }) + }, + async fetchFacilityAdditionalInformation({ commit, state }) { const facility = JSON.parse(JSON.stringify(state.current)) diff --git a/src/views/FindFacilities.vue b/src/views/FindFacilities.vue index d8caf059..76f0db59 100644 --- a/src/views/FindFacilities.vue +++ b/src/views/FindFacilities.vue @@ -239,7 +239,6 @@ export default defineComponent({ // Note: here result.data returns 0 in some cases that's why it is compared with 'undefined'. if(result.data != undefined && result.data !== facility.maximumOrderLimit) { await this.updateFacility(result.data, facility) - await this.fetchFacilities() } }, async updateFacility(maximumOrderLimit: number | string, facility: any) { @@ -251,8 +250,16 @@ export default defineComponent({ maximumOrderLimit }) - if(!hasError(resp)) { - facility.maximumOrderLimit = maximumOrderLimit === "" ? null : maximumOrderLimit + if (!hasError(resp)) { + // updating the facilities state instead of refetching + const updatedFacilities = JSON.parse(JSON.stringify(this.facilities)).map((fac: any) => { + if (facility.facilityId === fac.facilityId) { + fac.maximumOrderLimit = maximumOrderLimit === "" ? null : maximumOrderLimit + fac.orderLimitType = fac.maximumOrderLimit === null ? 'unlimited' : (fac.maximumOrderLimit === 0 ? 'no-capacity' : 'custom') + } + return fac + }) + this.store.dispatch('facility/updateFacilities', updatedFacilities) showToast(translate('Fulfillment capacity updated successfully for ', { facilityName: facility.facilityName })) } else { throw resp.data @@ -281,8 +288,15 @@ export default defineComponent({ } if (!hasError(resp)) { + // updating the facilities state instead of refetching + const updatedFacilities = JSON.parse(JSON.stringify(this.facilities)).map((fac: any) => { + if (facility.facilityId === fac.facilityId) { + fac.sellOnline = !facility.sellOnline + } + return fac + }) + this.store.dispatch('facility/updateFacilities', updatedFacilities) showToast(translate('Fulfillment setting updated successfully')) - await this.fetchFacilities(); } else { throw resp.data } From 15c65660c3201321cf6cbc3ce243a63d00a28b22 Mon Sep 17 00:00:00 2001 From: k2maan Date: Thu, 30 Nov 2023 12:57:56 +0530 Subject: [PATCH 2/2] Removed: unused imports --- src/store/modules/facility/actions.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/store/modules/facility/actions.ts b/src/store/modules/facility/actions.ts index 120cd449..5eb1dd97 100644 --- a/src/store/modules/facility/actions.ts +++ b/src/store/modules/facility/actions.ts @@ -6,8 +6,6 @@ import { FacilityService } from '@/services/FacilityService' import { hasError } from '@/adapter' import * as types from './mutation-types' import logger from '@/logger' -import { showToast } from '@/utils' -import { translate } from '@hotwax/dxp-components' const actions: ActionTree = { async fetchFacilitiesAdditionalInformation({ commit, state }, payload = { viewIndex: 0 }) {