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
24 changes: 17 additions & 7 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,9 +209,14 @@ const actions: ActionTree<UserState, RootState> = {
/**
* update current shopify config id
*/
async setCurrentShopifyConfig({ commit, dispatch }, shopifyConfig) {
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, shopifyConfig ? shopifyConfig : {});
dispatch('job/clearJobState', null, { root: true });
async setCurrentShopifyConfig({ commit, dispatch, state }, payload) {
let currentShopifyConfig = payload.shopifyConfig;
if(!currentShopifyConfig) {
currentShopifyConfig = state.shopifyConfigs.find((configs: any) => configs.shopifyConfigId === payload.shopifyConfigId)
}

commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, currentShopifyConfig ? currentShopifyConfig : {});
dispatch('job/clearJobState', null, { root: true });
},

/**
Expand Down
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