diff --git a/src/store/modules/facility/actions.ts b/src/store/modules/facility/actions.ts index d0a30b82..e62249b4 100644 --- a/src/store/modules/facility/actions.ts +++ b/src/store/modules/facility/actions.ts @@ -177,11 +177,20 @@ const actions: ActionTree = { commit(types.FACILITY_CURRENT_UPDATED, facility) }, - async fetchCurrentFacility({ commit, dispatch, state }, payload) { + async fetchCurrentFacility({ commit, dispatch, rootGetters, state }, payload) { // checking that if the list contains basic information for facility then not fetching the same information again const cachedFacilities = JSON.parse(JSON.stringify(state.facilities.list)) const current = cachedFacilities.find((facility: any) => facility.facilityId === payload.facilityId) if(current?.facilityId && !payload.skipState) { + // As inventory channels are fetched while fetching additional facility info + // But here we already have additional facility info, so just getting and adding inventory groups to current. + const inventoryGroups = rootGetters['util/getInventoryGroups']; + // Creating a key called 'isChecked' for inventory groups already associated with current facility. + inventoryGroups.forEach((group: any) => { + const isChecked = (current.facilityGroupInfo?.some((facilityGroup: any) => facilityGroup?.facilityGroupId === group.facilityGroupId)) + group.isChecked = isChecked ? isChecked : false; + }); + current.inventoryGroups = inventoryGroups; commit(types.FACILITY_CURRENT_UPDATED, current); return; }