Skip to content

Commit

Permalink
Improved: util actions to not fetch the details again if already avai…
Browse files Browse the repository at this point in the history
…lable
  • Loading branch information
ymaheshwari1 committed Jan 29, 2024
1 parent 9d0a70a commit d66571a
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/store/modules/util/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ const actions: ActionTree<UtilState, RootState> = {
commit(types.UTIL_ENUMS_UPDATED, enums)
},

async fetchFacilities({ commit }) {
let facilities = {}
async fetchFacilities({ commit, state }) {
let facilities = JSON.parse(JSON.stringify(state.facilities))

// Do not fetch facilities if already available
if(Object.keys(facilities).length) {
return;
}

const payload = {
parentTypeId: "VIRTUAL_FACILITY"
Expand All @@ -59,8 +64,13 @@ const actions: ActionTree<UtilState, RootState> = {
commit(types.UTIL_FACILITIES_UPDATED, facilities)
},

async fetchShippingMethods({ commit }) {
let shippingMethods = {}
async fetchShippingMethods({ commit, state }) {
let shippingMethods = JSON.parse(JSON.stringify(state.shippingMethods))

// Do not fetch shipping methods if aleady available
if(Object.keys(shippingMethods).length) {
return;
}

const payload = {
productStoreId: store.state.user.currentEComStore.productStoreId
Expand All @@ -82,8 +92,13 @@ const actions: ActionTree<UtilState, RootState> = {
commit(types.UTIL_SHIPPING_METHOD_UPDATED, shippingMethods)
},

async fetchFacilityGroups({ commit }) {
let facilityGroups = {}
async fetchFacilityGroups({ commit, state }) {
let facilityGroups = JSON.parse(JSON.stringify(state.facilityGroups))

// Do not fetch groups again if already available
if(Object.keys(facilityGroups).length) {
return;
}

const payload = {
productStoreId: store.state.user.currentEComStore.productStoreId,
Expand Down

0 comments on commit d66571a

Please sign in to comment.