Skip to content

Commit

Permalink
Merge pull request #219 from shashwatbangar/#2f2h8hu
Browse files Browse the repository at this point in the history
Implemented support to store user preference for selected product store (#2f2h8hu)
  • Loading branch information
adityasharma7 authored Aug 17, 2022
2 parents 1dfe7eb + 30fcfa6 commit 6aa79ca
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
21 changes: 20 additions & 1 deletion src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@ const associatePinnedJobPrefToUser = async (payload: any): Promise<any> => {
});
}

const setUserPreference = async (payload: any): Promise<any> => {
return api({
url: "service/setUserPreference",
method: "post",
data: payload
});
}

const getUserPreference = async (payload: any): Promise<any> => {
return api({
url: "service/getUserPreference",
//TODO Due to security reasons service model of OMS 1.0 does not support sending parameters in get request that's why we use post here
method: "post",
data: payload,
});
}

export const UserService = {
createPinnedJobPref,
login,
Expand All @@ -90,5 +107,7 @@ export const UserService = {
getPinnedJobs,
associatePinnedJobPrefToUser,
setUserTimeZone,
updatePinnedJobPref
updatePinnedJobPref,
setUserPreference,
getUserPreference
}
18 changes: 16 additions & 2 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,18 @@ const actions: ActionTree<UserState, RootState> = {
if (resp.data.userTimeZone) {
Settings.defaultZone = resp.data.userTimeZone;
}
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, resp.data?.stores[0]);
commit(types.USER_INFO_UPDATED, resp.data);
const stores = resp.data.stores
const userPrefResponse = await UserService.getUserPreference({
'userPrefTypeId': 'SELECTED_BRAND'
});
if(userPrefResponse.status === 200 && !hasError(userPrefResponse)) {
const userPrefStore = stores.find((store: any) => store.productStoreId === userPrefResponse.data.userPrefValue)
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, userPrefStore ? userPrefStore : stores ? stores[0]: {});
commit(types.USER_INFO_UPDATED, resp.data);
} else {
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, stores ? stores[0]: {});
commit(types.USER_INFO_UPDATED, resp.data);
}
}
},

Expand All @@ -93,6 +103,10 @@ const actions: ActionTree<UserState, RootState> = {
dispatch('job/clearJobState', null, { root: true });
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, payload.eComStore);
dispatch('getShopifyConfig', payload.eComStore.productStoreId);
await UserService.setUserPreference({
'userPrefTypeId': 'SELECTED_BRAND',
'userPrefValue': payload.eComStore.productStoreId
});
},
/**
* Update user timeZone
Expand Down

0 comments on commit 6aa79ca

Please sign in to comment.