Skip to content

Commit

Permalink
Implemented: support for getting respective maarg url and token for t…
Browse files Browse the repository at this point in the history
…he loggedIn oms (hotwax#734)
  • Loading branch information
amansinghbais committed Oct 17, 2024
1 parent e325ec4 commit 50cbd0b
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 652 deletions.
716 changes: 68 additions & 648 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@casl/ability": "^6.0.0",
"@hotwax/app-version-info": "^1.0.0",
"@hotwax/apps-theme": "^1.2.6",
"@hotwax/dxp-components": "1.13.0",
"@hotwax/dxp-components": "1.15.3",
"@hotwax/oms-api": "1.14.0",
"@ionic/core": "^7.6.0",
"@ionic/vue": "^7.6.0",
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@
"Skip once": "Skip once",
"Skipping will run this job at the next occurrence based on the temporal expression.": "Skipping will run this job at the next occurrence based on the temporal expression.",
"Some jobs have slow frequency type, hence, feasible frequency will be set automatically": "Some jobs have slow frequency type, hence, feasible frequency will be set automatically",
"Some of the app functionality will not work due to missing configuration.": "Some of the app functionality will not work due to missing configuration.",
"Something went wrong": "Something went wrong",
"Something went wrong while getting complete user permissions.": "Something went wrong while getting complete user permissions.",
"Something went wrong while login. Please contact administrator.": "Something went wrong while login. Please contact administrator.",
Expand Down
28 changes: 28 additions & 0 deletions src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,33 @@ const login = async (username: string, password: string): Promise <any> => {
});
}

const moquiLogin = async (omsRedirectionUrl: string, token: string): Promise <any> => {
const baseURL = omsRedirectionUrl.startsWith('http') ? omsRedirectionUrl.includes('/rest/s1/admin') ? omsRedirectionUrl : `${omsRedirectionUrl}/rest/s1/admin/` : `https://${omsRedirectionUrl}.hotwax.io/rest/s1/admin/`;
let api_key = ""

try {
const resp = await client({
url: "login",
method: "post",
baseURL,
params: {
token
},
headers: {
"Content-Type": "application/json"
}
}) as any;

if(!hasError(resp) && (resp.data.api_key || resp.data.token)) {
api_key = resp.data.api_key || resp.data.token
} else {
throw "Sorry, login failed. Please try again";
}
} catch(err) {
return Promise.resolve("");
}
return Promise.resolve(api_key)
}

const getShopifyConfig = async (productStoreId: any, token?: any): Promise <any> => {
try {
Expand Down Expand Up @@ -360,6 +387,7 @@ export const UserService = {
getPreferredStore,
getUserProfile,
associatePinnedJobPrefToUser,
moquiLogin,
updatePinnedJobPref,
setUserPreference,
getUserPermissions
Expand Down
4 changes: 4 additions & 0 deletions src/store/modules/user/UserState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ export default interface UserState {
currentShopifyConfig: any;
productStoreCategories: any;
pwaState: any;
omsRedirectionInfo: {
url: string;
token: string;
}
}
19 changes: 18 additions & 1 deletion src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const actions: ActionTree<UserState, RootState> = {
*/
async login({ commit, dispatch }, payload) {
try {
const { token, oms } = payload
const { token, oms, omsRedirectionUrl } = payload
dispatch("setUserInstanceUrl", oms);

// Getting the permissions list from server
Expand Down Expand Up @@ -84,6 +84,19 @@ const actions: ActionTree<UserState, RootState> = {
Settings.defaultZone = userProfile.userTimeZone;
}

if(omsRedirectionUrl) {
const api_key = await UserService.moquiLogin(omsRedirectionUrl, token)
if(api_key) {
dispatch("setOmsRedirectionInfo", { url: omsRedirectionUrl, token: api_key })
} else {
showToast(translate("Some of the app functionality will not work due to missing configuration."))
console.error("Some of the app functionality will not work due to missing configuration.");
}
} else {
showToast(translate("Some of the app functionality will not work due to missing configuration."))
console.error("Some of the app functionality will not work due to missing configuration.")
}

// TODO user single mutation
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, preferredStore);
commit(types.USER_INFO_UPDATED, userProfile);
Expand Down Expand Up @@ -243,6 +256,10 @@ const actions: ActionTree<UserState, RootState> = {
dispatch('job/clearJobState', null, { root: true });
},

setOmsRedirectionInfo({ commit }, payload) {
commit(types.USER_OMS_REDIRECTION_INFO_UPDATED, payload)
},

/**
* Get user pinned jobs
*/
Expand Down
3 changes: 3 additions & 0 deletions src/store/modules/user/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const getters: GetterTree <UserState, RootState> = {
},
getPinnedJobs(state) {
return state.current ? (state.current as any)['pinnedJobs']?.jobs : []
},
getOmsRedirectionInfo(state) {
return state.omsRedirectionInfo
}
}
export default getters;
4 changes: 4 additions & 0 deletions src/store/modules/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const userModule: Module<UserState, RootState> = {
updateExists: false,
registration: null,
},
omsRedirectionInfo: {
url: "",
token: ""
}
},
getters,
actions,
Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/user/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export const USER_CURRENT_SHOPIFY_CONFIG_UPDATED = SN_USER + '/SHOPIFY_CONFIG_UP
export const USER_CURRENT_ECOM_STORE_UPDATED = SN_USER + '/CURRENT_ECOM_STORE_UPDATED'
export const USER_PERMISSIONS_UPDATED = SN_USER + '/PERMISSIONS_UPDATED'
export const USER_PWA_STATE_UPDATED = SN_USER + '/PWA_STATE_UPDATED'
export const USER_PRDCT_STR_CATGRS_UPDATED = SN_USER + '/PRDCT_STR_CATGRS_UPDATED'
export const USER_PRDCT_STR_CATGRS_UPDATED = SN_USER + '/PRDCT_STR_CATGRS_UPDATED'
export const USER_OMS_REDIRECTION_INFO_UPDATED = SN_USER + '/OMS_REDIRECTION_INFO_UPDATED'
9 changes: 8 additions & 1 deletion src/store/modules/user/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ const mutations: MutationTree <UserState> = {
}
state.shopifyConfigs = []
state.permissions = []
state.productStoreCategories = {}
state.productStoreCategories = {},
state.omsRedirectionInfo = {
url: "",
token: ""
}
},
[types.USER_INFO_UPDATED] (state, payload) {
state.current = { ...state.current, ...payload}
Expand All @@ -43,5 +47,8 @@ const mutations: MutationTree <UserState> = {
[types.USER_PERMISSIONS_UPDATED] (state, payload) {
state.permissions = payload
},
[types.USER_OMS_REDIRECTION_INFO_UPDATED](state, payload) {
state.omsRedirectionInfo = payload;
}
}
export default mutations;

0 comments on commit 50cbd0b

Please sign in to comment.