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

Implemented support to store user preference for selected product store (#2f2h8hu) #197

Merged
merged 2 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
11 changes: 10 additions & 1 deletion src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ 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]);
const userPref = await UserService.getUserPreference({
Copy link
Contributor

Choose a reason for hiding this comment

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

Handle case if there is an error from API

'userPrefTypeId': 'SELECTED_BRAND'
});
const stores = resp.data.stores
const userPrefStore = stores.find((store: any) => store.productStoreId === userPref.data.userPrefValue)
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, userPrefStore ? userPrefStore : stores ? stores[0]: {});
commit(types.USER_INFO_UPDATED, resp.data);
}
},
Expand All @@ -93,6 +98,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