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

Conversation

alsoK2maan
Copy link
Contributor

Related Issues

Closes #

Short Description and Why It's Useful

Refactored action setEcomStore and setShopifyConfig to accept ID as well as object, as initially the whole object was passed, posing unnecessary code.

Screenshots of Visual Changes before/after (If There Are Any)

IMPORTANT NOTICE - Remember to add changelog entry

Contribution and Currently Important Rules Acceptance

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.

}
},
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.

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.

this.store.dispatch('user/setEcomStore', {
'eComStore': this.userProfile.stores.find((str: any) => str.productStoreId == store['detail'].value)
'productStoreId' : productStoreId ? productStoreId : {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this is needed? We could just pass the productStoreId

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

Choose a reason for hiding this comment

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

Variable name should be shopifyConfigId
Why this is needed? We could just pass the shopifyConfigId

async setCurrentShopifyConfig({ commit, dispatch, state }, payload) {
const shopifyConfigs = state.shopifyConfigs ? state.shopifyConfigs : {};
let currentShopifyConfig;
payload.shopifyConfig.shopifyConfigId ?
Copy link
Contributor

Choose a reason for hiding this comment

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

If we are getting shopifyConfig, just set it as is, if not find and set. Same applied to productStore

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made the changes, sir, please review.

if(payload.productStore) {
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, payload.productStore);
} else {
productStore = getters.getUserProfile.stores.find((store: any) => store.productStoreId === payload.productStoreId);
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to use getter, I think we could directly access the state

let productStore;

if(payload.productStore) {
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, payload.productStore);
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 commit in both the cases, here we should assign productStore with payload.productStore

productStore = getters.getUserProfile.stores.find((store: any) => store.productStoreId === payload.productStoreId);
}

dispatch('getShopifyConfig', productStore ? productStore.productStoreId : payload.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.

Once we have productStore set for both the cases, we will not need this ternary operation we could use productStore.productStoreId for both the cases

await UserService.setUserPreference({
'userPrefTypeId': 'SELECTED_BRAND',
'userPrefValue': payload.eComStore.productStoreId
'userPrefValue': productStore ? productStore.productStoreId : payload.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.

Same here. refer my previous comment

Comment on lines 215 to 221
if(payload.shopifyConfig) {
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, payload.shopifyConfig);
} else {
const shopifyConfigs = state.shopifyConfigs;
const currentShopifyConfig = shopifyConfigs.find((configs: any) => configs.shopifyConfigId === payload.shopifyConfigId)
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, currentShopifyConfig);
}
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 following code for better readability

Suggested change
if(payload.shopifyConfig) {
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, payload.shopifyConfig);
} else {
const shopifyConfigs = state.shopifyConfigs;
const currentShopifyConfig = shopifyConfigs.find((configs: any) => configs.shopifyConfigId === payload.shopifyConfigId)
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, currentShopifyConfig);
}
let currentShopifyConfig = payload.shopifyConfig;
if(!currentShopifyConfig) {
currentShopifyConfig = state.shopifyConfigs.find((shopifyConfig: any) => shopifyConfig.shopifyConfigId === payload.shopifyConfigId)
}
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, currentShopifyConfig ? currentShopifyConfig : {});

Comment on lines 91 to 92
const productStoreId = store['detail'].value
this.store.dispatch('user/setEcomStore', { 'productStoreId': productStoreId })
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not?

Suggested change
const productStoreId = store['detail'].value
this.store.dispatch('user/setEcomStore', { 'productStoreId': productStoreId })
this.store.dispatch('user/setEcomStore', { '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.

Also, we could rename store to event like setShopifyConfig() method and access directly event.detail.value

}
},
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.

Remove unwanted code

Comment on lines 97 to 98
const shopifyConfigId = event.detail.value;
this.store.dispatch('user/setCurrentShopifyConfig', { 'shopifyConfigId': shopifyConfigId });
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not?

Suggested change
const shopifyConfigId = event.detail.value;
this.store.dispatch('user/setCurrentShopifyConfig', { 'shopifyConfigId': shopifyConfigId });
this.store.dispatch('user/setCurrentShopifyConfig', { 'shopifyConfigId': event.detail.value });

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented the changes, sir, please review.

@adityasharma7 adityasharma7 merged commit e9360e9 into hotwax:main Oct 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants