Skip to content

Commit

Permalink
Implemented: bringing moqui redirection info in ofbiz apps (hotwax#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
amansinghbais committed Sep 27, 2024
1 parent 6b7d593 commit aa32a6b
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 30 deletions.
94 changes: 70 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"@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/oms-api": "1.14.0",
"@hotwax/dxp-components": "1.15.2",
"@hotwax/oms-api": "1.15.0",
"@ionic/core": "^7.6.0",
"@ionic/vue": "^7.6.0",
"@ionic/vue-router": "^7.6.0",
Expand Down
29 changes: 29 additions & 0 deletions src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,34 @@ 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/order-routing') ? omsRedirectionUrl : `${omsRedirectionUrl}/rest/s1/order-routing/` : `https://${omsRedirectionUrl}.hotwax.io/rest/s1/order-routing/`;
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 setUserPreference = async (payload: any): Promise<any> => {
return api({
url: "service/setUserPreference",
Expand Down Expand Up @@ -195,5 +223,6 @@ export const UserService = {
getUserProfile,
getUserPermissions,
login,
moquiLogin,
setUserPreference,
}
4 changes: 4 additions & 0 deletions src/store/modules/user/UserState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ export default interface UserState {
pwaState: any;
instanceUrl: string;
currentEComStore: object;
omsRedirectionInfo: {
url: string;
token: string;
}
}
22 changes: 19 additions & 3 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const actions: ActionTree<UserState, RootState> = {
*/
async login ({ commit, dispatch }, payload) {

const { token, oms } = payload;
const { token, oms, omsRedirectionUrl } = payload;
dispatch("setUserInstanceUrl", oms);
try {
if (token) {
Expand Down Expand Up @@ -66,6 +66,17 @@ 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 {
console.error("Some of the configuration of the app is missing.");
}
} else {
console.error("Some of the configuration of the app is missing.")
}

// TODO user single mutation
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, preferredStore);
commit(types.USER_INFO_UPDATED, userProfile);
Expand All @@ -83,7 +94,7 @@ const actions: ActionTree<UserState, RootState> = {
/**
* Logout user
*/
async logout ({ commit }, payload) {
async logout ({ commit, dispatch }, payload) {
// store the url on which we need to redirect the user after logout api completes in case of SSO enabled
let redirectionUrl = ''

Expand Down Expand Up @@ -118,6 +129,7 @@ const actions: ActionTree<UserState, RootState> = {
this.dispatch("order/resetOrderQuery")
this.dispatch("job/clearCtgryAndBrkrngJobs")
this.dispatch("util/clearInvConfigs")
dispatch("setOmsRedirectionInfo", { url: "", token: "" })
resetPermissions();

// reset plugin state on logout
Expand Down Expand Up @@ -167,7 +179,11 @@ const actions: ActionTree<UserState, RootState> = {

updatePwaState({ commit }, payload) {
commit(types.USER_PWA_STATE_UPDATED, payload);
}
},

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

}
export default actions;
4 changes: 4 additions & 0 deletions src/store/modules/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const userModule: Module<UserState, RootState> = {
pwaState: {
updateExists: false,
registration: null,
},
omsRedirectionInfo: {
url: "",
token: ""
}
},
getters,
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 @@ -6,4 +6,5 @@ export const USER_INSTANCE_URL_UPDATED = SN_USER + '/INSTANCE_URL_UPDATED'
export const USER_PERMISSIONS_UPDATED = SN_USER + '/PERMISSIONS_UPDATED'
export const USER_CURRENT_ECOM_STORE_UPDATED = SN_USER + '/CURRENT_ECOM_STORE_UPDATED'
export const USER_STORE_RSRV_INV_STATUS_UPDATED = SN_USER + '/STORE_RSRV_INV_STATUS_UPDATED'
export const USER_PWA_STATE_UPDATED = SN_USER + '/PWA_STATE_UPDATED'
export const USER_PWA_STATE_UPDATED = SN_USER + '/PWA_STATE_UPDATED'
export const USER_OMS_REDIRECTION_INFO_UPDATED = SN_USER + '/OMS_REDIRECTION_INFO_UPDATED'
3 changes: 3 additions & 0 deletions src/store/modules/user/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ const mutations: MutationTree <UserState> = {
state.pwaState.registration = payload.registration;
state.pwaState.updateExists = payload.updateExists;
},
[types.USER_OMS_REDIRECTION_INFO_UPDATED](state, payload) {
state.omsRedirectionInfo = payload;
}
}
export default mutations;

0 comments on commit aa32a6b

Please sign in to comment.