Skip to content

Commit

Permalink
Merge pull request #241 from k2maan/#2tzh44d
Browse files Browse the repository at this point in the history
Refactored: setEcomStore and setShopifyConfig actions to accept ID. (#2tzh44d)
  • Loading branch information
adityasharma7 authored Oct 10, 2022
2 parents 3db5f61 + e5385f1 commit e9360e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
22 changes: 16 additions & 6 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,18 @@ const actions: ActionTree<UserState, RootState> = {
/**
* update current eComStore information
*/
async setEcomStore({ commit, dispatch }, payload) {
async setEcomStore({ state, commit, dispatch }, payload) {
dispatch('job/clearJobState', null, { root: true });
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, payload.eComStore);
dispatch('getShopifyConfig', payload.eComStore.productStoreId);
let productStore = payload.productStore;
if(!productStore) {
productStore = this.state.user.current.stores.find((store: any) => store.productStoreId === payload.productStoreId);
}

commit(types.USER_CURRENT_ECOM_STORE_UPDATED, productStore);
dispatch('getShopifyConfig', productStore.productStoreId);
await UserService.setUserPreference({
'userPrefTypeId': 'SELECTED_BRAND',
'userPrefValue': payload.eComStore.productStoreId
'userPrefValue': productStore.productStoreId
});
},
/**
Expand Down Expand Up @@ -204,7 +209,12 @@ const actions: ActionTree<UserState, RootState> = {
/**
* update current shopify config id
*/
async setCurrentShopifyConfig({ commit, dispatch }, shopifyConfig) {
async setCurrentShopifyConfig({ commit, dispatch, state }, payload) {
let shopifyConfig = payload.shopifyConfig;
if(!shopifyConfig) {
shopifyConfig = state.shopifyConfigs.find((configs: any) => configs.shopifyConfigId === payload.shopifyConfigId)
}

commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, shopifyConfig ? shopifyConfig : {});
dispatch('job/clearJobState', null, { root: true });
},
Expand Down Expand Up @@ -297,4 +307,4 @@ const actions: ActionTree<UserState, RootState> = {
}
}

export default actions;
export default actions;
9 changes: 3 additions & 6 deletions src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,13 @@ export default defineComponent({
})
},
methods: {
setEComStore(store: any) {
setEComStore(event: any) {
if(this.userProfile) {
this.store.dispatch('user/setEcomStore', {
'eComStore': this.userProfile.stores.find((str: any) => str.productStoreId == store['detail'].value)
})
this.store.dispatch('user/setEcomStore', { 'productStoreId': event.detail.value })
}
},
setShopifyConfig(event: any){
const shopifyConfig = this.shopifyConfigs.find((shopifyConfig: any) => shopifyConfig.shopifyConfigId === event.detail.value)
this.store.dispatch('user/setCurrentShopifyConfig', shopifyConfig);
this.store.dispatch('user/setCurrentShopifyConfig', { 'shopifyConfigId': event.detail.value });
},
async changeTimeZone() {
const timeZoneModal = await modalController.create({
Expand Down

0 comments on commit e9360e9

Please sign in to comment.