-
Notifications
You must be signed in to change notification settings - Fork 32
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
Conversation
…date and time, instead of using minDateTime
…t ID as parameter (##2tzh44d)
src/views/Settings.vue
Outdated
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, sir, understood.
src/views/Settings.vue
Outdated
} | ||
}, | ||
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, sure.
src/store/modules/user/actions.ts
Outdated
async setEcomStore({ commit, dispatch }, payload) { | ||
async setEcomStore({ commit, dispatch, state }, productStore) { | ||
const currentEComStore = state.currentEComStore; | ||
const productStoreId = typeof productStore === 'string' ? productStore : productStore.productStoreId; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
src/views/Settings.vue
Outdated
this.store.dispatch('user/setEcomStore', { | ||
'eComStore': this.userProfile.stores.find((str: any) => str.productStoreId == store['detail'].value) | ||
'productStoreId' : productStoreId ? productStoreId : {} |
There was a problem hiding this comment.
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
src/views/Settings.vue
Outdated
// 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 : {} |
There was a problem hiding this comment.
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
src/store/modules/user/actions.ts
Outdated
async setCurrentShopifyConfig({ commit, dispatch, state }, payload) { | ||
const shopifyConfigs = state.shopifyConfigs ? state.shopifyConfigs : {}; | ||
let currentShopifyConfig; | ||
payload.shopifyConfig.shopifyConfigId ? |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
src/store/modules/user/actions.ts
Outdated
if(payload.productStore) { | ||
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, payload.productStore); | ||
} else { | ||
productStore = getters.getUserProfile.stores.find((store: any) => store.productStoreId === payload.productStoreId); |
There was a problem hiding this comment.
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
src/store/modules/user/actions.ts
Outdated
let productStore; | ||
|
||
if(payload.productStore) { | ||
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, payload.productStore); |
There was a problem hiding this comment.
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
src/store/modules/user/actions.ts
Outdated
productStore = getters.getUserProfile.stores.find((store: any) => store.productStoreId === payload.productStoreId); | ||
} | ||
|
||
dispatch('getShopifyConfig', productStore ? productStore.productStoreId : payload.productStore.productStoreId); |
There was a problem hiding this comment.
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
src/store/modules/user/actions.ts
Outdated
await UserService.setUserPreference({ | ||
'userPrefTypeId': 'SELECTED_BRAND', | ||
'userPrefValue': payload.eComStore.productStoreId | ||
'userPrefValue': productStore ? productStore.productStoreId : payload.productStore.productStoreId |
There was a problem hiding this comment.
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
src/store/modules/user/actions.ts
Outdated
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); | ||
} |
There was a problem hiding this comment.
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
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 : {}); |
src/views/Settings.vue
Outdated
const productStoreId = store['detail'].value | ||
this.store.dispatch('user/setEcomStore', { 'productStoreId': productStoreId }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not?
const productStoreId = store['detail'].value | |
this.store.dispatch('user/setEcomStore', { 'productStoreId': productStoreId }) | |
this.store.dispatch('user/setEcomStore', { 'productStoreId': store['detail'].value }) |
There was a problem hiding this comment.
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
src/views/Settings.vue
Outdated
} | ||
}, | ||
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unwanted code
src/views/Settings.vue
Outdated
const shopifyConfigId = event.detail.value; | ||
this.store.dispatch('user/setCurrentShopifyConfig', { 'shopifyConfigId': shopifyConfigId }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not?
const shopifyConfigId = event.detail.value; | |
this.store.dispatch('user/setCurrentShopifyConfig', { 'shopifyConfigId': shopifyConfigId }); | |
this.store.dispatch('user/setCurrentShopifyConfig', { 'shopifyConfigId': event.detail.value }); |
There was a problem hiding this comment.
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.
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