Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored: setEcomStore and setShopifyConfig actions to accept ID. (#2tzh44d) #241

Merged
merged 11 commits into from
Oct 10, 2022
Merged
19 changes: 13 additions & 6 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,15 @@ const actions: ActionTree<UserState, RootState> = {
/**
* update current eComStore information
*/
async setEcomStore({ commit, dispatch }, payload) {
async setEcomStore({ commit, dispatch, state }, productStore) {
const currentEComStore = state.currentEComStore;
const productStoreId = typeof productStore === 'string' ? productStore : productStore.productStoreId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest we check if payload has productStoreId we find the productStore and if productStore we set it as is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sir, will change it as stated.

dispatch('job/clearJobState', null, { root: true });
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, payload.eComStore);
dispatch('getShopifyConfig', payload.eComStore.productStoreId);
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, currentEComStore);
dispatch('getShopifyConfig', productStoreId);
await UserService.setUserPreference({
'userPrefTypeId': 'SELECTED_BRAND',
'userPrefValue': payload.eComStore.productStoreId
'userPrefValue': productStoreId
});
},
/**
Expand Down Expand Up @@ -204,8 +206,13 @@ const actions: ActionTree<UserState, RootState> = {
/**
* update current shopify config id
*/
async setCurrentShopifyConfig({ commit, dispatch }, shopifyConfig) {
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, shopifyConfig ? shopifyConfig : {});
async setCurrentShopifyConfig({ commit, dispatch, state }, shopifyConfig) {
const shopifyConfigs = state.shopifyConfigs ? state.shopifyConfigs : {};
let currentShopifyConfig;
shopifyConfig.shopifyConfigId ?
currentShopifyConfig = shopifyConfigs.find((obj: any) => obj.shopifyConfig.shopifyConfigId === shopifyConfig.shopifyConfigId) :
currentShopifyConfig = shopifyConfigs.find((obj: any) => obj.shopifyConfigId === shopifyConfig);
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, currentShopifyConfig ? currentShopifyConfig : {});
dispatch('job/clearJobState', null, { root: true });
},

Expand Down
9 changes: 4 additions & 5 deletions src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,13 @@ export default defineComponent({
methods: {
setEComStore(store: any) {
if(this.userProfile) {
this.store.dispatch('user/setEcomStore', {
'eComStore': this.userProfile.stores.find((str: any) => str.productStoreId == store['detail'].value)
})
const productStore = this.userProfile.stores.find((str: any) => str.productStoreId === store['detail'].value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not find the product store here, we could just pass the productStoreId here and action should handle if id is provided it finds the product store & set it and if product store is provided it should set it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, sir, understood.

this.store.dispatch('user/setEcomStore', productStore ? productStore.productStoreId : {});
}
},
setShopifyConfig(event: any){
const shopifyConfig = this.shopifyConfigs.find((shopifyConfig: any) => shopifyConfig.shopifyConfigId === event.detail.value)
this.store.dispatch('user/setCurrentShopifyConfig', shopifyConfig);
const currentShopifyConfig = this.shopifyConfigs.find((shopifyConfig: any) => shopifyConfig.shopifyConfigId === event.detail.value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refer comments provided for the product store

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, sure.

this.store.dispatch('user/setCurrentShopifyConfig', currentShopifyConfig ? currentShopifyConfig.shopifyConfigId : {});
},
async changeTimeZone() {
const timeZoneModal = await modalController.create({
Expand Down