From 430ea9615c870402086cb29b79427e87c3f91553 Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Thu, 11 Jan 2024 12:36:11 +0530 Subject: [PATCH 1/2] Improved: UI for login page, as per the ionic upgrade changes, improved login url(#14) --- src/api/index.ts | 3 ++- src/services/UserService.ts | 4 ++-- src/views/Login.vue | 14 +++++--------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/api/index.ts b/src/api/index.ts index e51e71d..8f70fd4 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -15,6 +15,7 @@ axios.interceptors.request.use((config: any) => { return config; }); +// TODO: need to update this as per the changes in the Moqui response format, if required. axios.interceptors.response.use(function (response) { // Any status code that lie within the range of 2xx cause this function to trigger // Do something with response data @@ -69,7 +70,7 @@ const api = async (customConfig: any) => { } const baseURL = store.getters['user/getInstanceUrl']; - if (baseURL) config.baseURL = `https://${baseURL}.hotwax.io/api/`; + if (baseURL) config.baseURL = `https://${baseURL}.hotwax.io/rest/s1/order-routing/`; if(customConfig.cache) config.adapter = axiosCache.adapter; const networkStatus = await OfflineHelper.getNetworkStatus(); if (customConfig.queue && !networkStatus.connected) { diff --git a/src/services/UserService.ts b/src/services/UserService.ts index afe029f..45013f0 100644 --- a/src/services/UserService.ts +++ b/src/services/UserService.ts @@ -6,8 +6,8 @@ const login = async (username: string, password: string): Promise => { url: "login", method: "post", data: { - 'USERNAME': username, - 'PASSWORD': password + username, + password } }); } diff --git a/src/views/Login.vue b/src/views/Login.vue index ead2474..1c91b05 100644 --- a/src/views/Login.vue +++ b/src/views/Login.vue @@ -6,16 +6,13 @@ - {{ $t("OMS") }} - + - {{ $t("Username") }} - + - {{ $t("Password") }} - +
@@ -33,8 +30,8 @@ import { IonContent, IonInput, IonItem, - IonLabel, - IonPage } from "@ionic/vue"; + IonPage +} from "@ionic/vue"; import { defineComponent } from "vue"; import { useRouter } from "vue-router"; import { useStore } from "@/store"; @@ -48,7 +45,6 @@ export default defineComponent({ IonContent, IonInput, IonItem, - IonLabel, IonPage, Logo }, From ef3a5e3b8e969de30eccb4fb89f38e0ce9ed7663 Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Fri, 12 Jan 2024 10:41:56 +0530 Subject: [PATCH 2/2] Removed: logic to fetch user-profile(#14) --- src/services/UserService.ts | 7 ----- src/store/modules/user/actions.ts | 50 +++++-------------------------- 2 files changed, 7 insertions(+), 50 deletions(-) diff --git a/src/services/UserService.ts b/src/services/UserService.ts index e9d7981..6f61ac5 100644 --- a/src/services/UserService.ts +++ b/src/services/UserService.ts @@ -12,12 +12,6 @@ const login = async (username: string, password: string): Promise => { }); } -const getProfile = async (): Promise => { - return api({ - url: "user-profile", - method: "get", - }); -} const getAvailableTimeZones = async (): Promise => { return api({ url: "getAvailableTimeZones", @@ -47,7 +41,6 @@ const checkPermission = async (payload: any): Promise => { export const UserService = { login, getAvailableTimeZones, - getProfile, setUserTimeZone, checkPermission } \ No newline at end of file diff --git a/src/store/modules/user/actions.ts b/src/store/modules/user/actions.ts index 88c42f9..c5a2f04 100644 --- a/src/store/modules/user/actions.ts +++ b/src/store/modules/user/actions.ts @@ -11,42 +11,16 @@ const actions: ActionTree = { /** * Login user and return token */ - async login ({ commit, dispatch }, { username, password }) { + async login({ commit }, { username, password }) { try { + // TODO: implement support for fetching user-profile + // TODO: implement support for permission check + // TODO: implement support for fetching product stores for user const resp = await UserService.login(username, password) if (resp.status === 200 && resp.data) { if (resp.data.token) { - const permissionId = process.env.VUE_APP_PERMISSION_ID; - if (permissionId) { - const checkPermissionResponse = await UserService.checkPermission({ - data: { - permissionId - }, - headers: { - Authorization: "Bearer " + resp.data.token, - "Content-Type": "application/json" - } - }); - - if (checkPermissionResponse.status === 200 && !hasError(checkPermissionResponse) && checkPermissionResponse.data && checkPermissionResponse.data.hasPermission) { - commit(types.USER_TOKEN_CHANGED, { newToken: resp.data.token }) - dispatch("getProfile") - if (resp.data._EVENT_MESSAGE_ && resp.data._EVENT_MESSAGE_.startsWith("Alert:")) { - // TODO Internationalise text - showToast(translate(resp.data._EVENT_MESSAGE_)); - } - return resp.data; - } else { - const permissionError = "You do not have permission to access the app."; - showToast(translate(permissionError)); - console.error("error", permissionError); - return Promise.reject(new Error(permissionError)); - } - } else { - commit(types.USER_TOKEN_CHANGED, { newToken: resp.data.token }) - dispatch("getProfile") - return resp.data; - } + commit(types.USER_TOKEN_CHANGED, { newToken: resp.data.token }) + return resp.data; } else if (hasError(resp)) { showToast(translate("Sorry, your username or password is incorrect. Please try again.")); console.error("error", resp.data._ERROR_MESSAGE_); @@ -74,16 +48,6 @@ const actions: ActionTree = { }, - /** - * Get User profile - */ - async getProfile ( { commit }) { - const resp = await UserService.getProfile() - if (resp.status === 200) { - commit(types.USER_INFO_UPDATED, resp.data); - } - }, - /** * update current facility information */ @@ -107,7 +71,7 @@ const actions: ActionTree = { /** * Set User Instance Url */ - setUserInstanceUrl ({ state, commit }, payload){ + setUserInstanceUrl ({ commit }, payload){ commit(types.USER_INSTANCE_URL_UPDATED, payload) } }