Skip to content

Commit

Permalink
Implemented: Added support to login on maarg instances (#905).
Browse files Browse the repository at this point in the history
  • Loading branch information
ravilodhi committed Jan 23, 2025
1 parent aa1c42a commit 43a2a29
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 3 deletions.
30 changes: 30 additions & 0 deletions src/services/UserService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { api, client, hasError } from '@/adapter';
import store from '@/store';
import logger from '@/logger'

const login = async (username: string, password: string): Promise <any> => {
return api({
Expand All @@ -11,6 +12,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/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) {
logger.error(err)
return Promise.resolve("");
}
return Promise.resolve(api_key)
}

const getFacilityDetails = async (payload: any): Promise<any> => {
return api({
Expand Down Expand Up @@ -406,6 +435,7 @@ export const UserService = {
getUserProfile,
getPreferredStore,
isEnumExists,
moquiLogin,
recycleInProgressOrders,
recycleOutstandingOrders,
setUserPreference,
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 @@ -3,6 +3,10 @@ export default interface UserState {
current: any;
permissions: any;
pwaState: any;
omsRedirectionInfo: {
url: string;
token: string;
}
instanceUrl: string;
preference: {
printShippingLabel: boolean,
Expand Down
19 changes: 18 additions & 1 deletion src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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 @@ -80,6 +80,20 @@ const actions: ActionTree<UserState, RootState> = {
if (userProfile.userTimeZone) {
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."))
logger.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."))
logger.error("Some of the app functionality will not work due to missing configuration.")
}

updateToken(token)

dispatch('getFieldMappings')
Expand Down Expand Up @@ -407,6 +421,9 @@ 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)
},

async getNewRejectionApiConfig ({ commit }) {
let config = {};
Expand Down
7 changes: 7 additions & 0 deletions src/store/modules/user/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ const getters: GetterTree <UserState, RootState> = {
getPwaState(state) {
return state.pwaState;
},
getMaargBaseUrl (state) {
const url = state.omsRedirectionInfo.url
return url.startsWith('http') ? url.includes('/rest/s1/admin') ? url : `${url}/rest/s1/admin/` : `https://${url}.hotwax.io/rest/s1/admin/`;
},
getOmsRedirectionInfo(state) {
return state.omsRedirectionInfo
},
getNotifications(state) {
return state.notifications.sort((a: any, b: any) => b.time - a.time)
},
Expand Down
4 changes: 4 additions & 0 deletions src/store/modules/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const userModule: Module<UserState, RootState> = {
updateExists: false,
registration: null,
},
omsRedirectionInfo: {
url: "",
token: ""
},
fieldMappings: {},
currentMapping: {
id: '',
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 @@ -19,4 +19,5 @@ export const USER_PARTIAL_ORDER_REJECTION_CONFIG_UPDATED = SN_USER + '/PARTIAL_O
export const USER_COLLATERAL_REJECTION_CONFIG_UPDATED = SN_USER + '/COLLATERAL_REJECTION_CONFIG_UPDATED'
export const USER_DISABLE_SHIP_NOW_CONFIG_UPDATED = SN_USER + '/DISABLE_SHIP_NOW_CONFIG_UPDATED'
export const USER_DISABLE_UNPACK_CONFIG_UPDATED = SN_USER + '/DISABLE_UNPACK_CONFIG_UPDATED'
export const USER_AFFECT_QOH_CONFIG_UPDATED = SN_USER + '/USER_AFFECT_QOH_CONFIG_UPDATED'
export const USER_AFFECT_QOH_CONFIG_UPDATED = SN_USER + '/USER_AFFECT_QOH_CONFIG_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 @@ -10,7 +10,11 @@ const mutations: MutationTree <UserState> = {
state.token = ''
state.current = {},
state.permissions = [],
state.allNotificationPrefs = []
state.allNotificationPrefs = [],
state.omsRedirectionInfo = {
url: "",
token: ""
}
},
[types.USER_INFO_UPDATED] (state, payload) {
state.current = { ...state.current, ...payload}
Expand Down Expand Up @@ -72,6 +76,9 @@ const mutations: MutationTree <UserState> = {
},
[types.USER_DISABLE_UNPACK_CONFIG_UPDATED] (state, payload) {
state.isUnpackDisabled = payload
},
[types.USER_OMS_REDIRECTION_INFO_UPDATED](state, payload) {
state.omsRedirectionInfo = payload;
}
}
export default mutations;

0 comments on commit 43a2a29

Please sign in to comment.