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 redirect to the passed redirectionURL instead of oms #220

Merged
merged 4 commits into from
May 23, 2024
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
617 changes: 321 additions & 296 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 @@ -16,7 +16,7 @@
"@capacitor/core": "^2.4.7",
"@hotwax/app-version-info": "^1.0.0",
"@hotwax/apps-theme": "^1.2.6",
"@hotwax/dxp-components": "^1.13.0",
"@hotwax/dxp-components": "^1.14.0",
"@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 @@ -73,6 +73,7 @@
"kms": "kms",
"Last run": "Last run",
"Logging in...": "Logging in...",
"Logging out": "Logging out",
"Login": "Login",
"Logout": "Logout",
"Low": "Low",
Expand Down
6 changes: 5 additions & 1 deletion src/store/modules/user/UserState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@ export default interface UserState {
token: string;
current: object | null;
instanceUrl: string;
currentEComStore: object | null,
currentEComStore: object | null;
omsRedirectionInfo: {
url: string;
token: string;
}
}
12 changes: 10 additions & 2 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const actions: ActionTree<UserState, RootState> = {
// TODO: implement support for permission check

// TODO: oms here is of ofbiz we need to check how to get the maarg url from here as we need to hit all apis on maarg
const { token, oms } = payload;
const { token, oms, omsRedirectionUrl } = payload;
dispatch("setUserInstanceUrl", oms);

emitter.emit("presentLoader", { message: "Logging in...", backdropDismiss: false })
Expand All @@ -35,6 +35,9 @@ const actions: ActionTree<UserState, RootState> = {
Settings.defaultZone = userProfile.timeZone;
}

if(omsRedirectionUrl && token) {
dispatch("setOmsRedirectionInfo", { url: omsRedirectionUrl, token })
}
commit(types.USER_TOKEN_CHANGED, { newToken: api_key })
commit(types.USER_INFO_UPDATED, userProfile);
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, userProfile.stores.length ? userProfile.stores[0] : {});
Expand All @@ -50,7 +53,7 @@ const actions: ActionTree<UserState, RootState> = {
/**
* Logout user
*/
async logout({ commit }) {
async logout({ commit, dispatch }) {
emitter.emit('presentLoader', { message: 'Logging out', backdropDismiss: false })

const authStore = useAuthStore()
Expand All @@ -59,6 +62,7 @@ const actions: ActionTree<UserState, RootState> = {
commit(types.USER_END_SESSION)
this.dispatch("orderRouting/clearRouting")
this.dispatch("util/clearUtilState")
dispatch("setOMSRedirectionInfo", { url: "", token: "" })
resetConfig();

// reset plugin state on logout
Expand Down Expand Up @@ -88,6 +92,10 @@ const actions: ActionTree<UserState, RootState> = {
commit(types.USER_INSTANCE_URL_UPDATED, payload)
},

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

setEcomStore({ commit, state }, payload) {
let productStore = payload.productStore;
if(!productStore) {
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 @@ -24,6 +24,9 @@ const getters: GetterTree <UserState, RootState> = {
getBaseUrl(state) {
const baseURL = state.instanceUrl;
return baseURL.startsWith("http") ? baseURL : `https://${baseURL}.hotwax.io/rest/s1/order-routing/`;
},
getOmsRedirectionInfo(state) {
return state.omsRedirectionInfo;
}
}
export default getters;
6 changes: 5 additions & 1 deletion src/store/modules/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ const userModule: Module<UserState, RootState> = {
token: "",
current: null,
instanceUrl: "",
currentEComStore: {}
currentEComStore: {},
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 @@ -3,4 +3,5 @@ export const USER_TOKEN_CHANGED = SN_USER + "/TOKEN_CHANGED"
export const USER_END_SESSION = SN_USER + "/END_SESSION"
export const USER_INFO_UPDATED = SN_USER + "/INFO_UPDATED"
export const USER_INSTANCE_URL_UPDATED = SN_USER + "/INSTANCE_URL_UPDATED"
export const USER_CURRENT_ECOM_STORE_UPDATED = SN_USER + '/CURRENT_ECOM_STORE_UPDATED'
export const USER_CURRENT_ECOM_STORE_UPDATED = SN_USER + '/CURRENT_ECOM_STORE_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 @@ -19,6 +19,9 @@ const mutations: MutationTree <UserState> = {
},
[types.USER_CURRENT_ECOM_STORE_UPDATED] (state, payload) {
state.currentEComStore = payload;
},
[types.USER_OMS_REDIRECTION_INFO_UPDATED](state, payload) {
state.omsRedirectionInfo = payload;
}
}
export default mutations;
13 changes: 3 additions & 10 deletions src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<ion-card-content>
{{ $t('This is the name of the OMS you are connected to right now. Make sure that you are connected to the right instance before proceeding.') }}
</ion-card-content>
<ion-button @click="goToOms()" fill="clear">
<ion-button @click="goToOms(omsRedirectionInfo.token, omsRedirectionInfo.url)" fill="clear">
{{ $t('Go to OMS') }}
<ion-icon slot="end" :icon="openOutline" />
</ion-button>
Expand Down Expand Up @@ -99,22 +99,21 @@
import { IonAvatar, IonButton, IonCard, IonCardContent, IonCardHeader, IonCardSubtitle, IonCardTitle, IonContent, IonHeader, IonIcon, IonItem, IonLabel, IonMenuButton, IonPage, IonSelect, IonSelectOption, IonTitle, IonToolbar, modalController } from "@ionic/vue";
import { computed, onMounted, ref } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import TimeZoneModal from "@/components/TimezoneModal.vue";
import Image from "@/components/Image.vue"
import { DateTime } from "luxon";
import { translate } from "@/i18n"
import { openOutline } from "ionicons/icons"
import { goToOms } from "@hotwax/dxp-components";

const store = useStore()
const router = useRouter()
const appVersion = ref("")
const appInfo = (process.env.VUE_APP_VERSION_INFO ? JSON.parse(process.env.VUE_APP_VERSION_INFO) : {}) as any

const userProfile = computed(() => store.getters["user/getUserProfile"])
const currentEComStore = computed(() => store.getters["user/getCurrentEComStore"])
const token = computed(() => store.getters["user/getUserToken"])
const oms = computed(() => store.getters["user/getInstanceUrl"])
const omsRedirectionInfo = computed(() => store.getters["user/getOmsRedirectionInfo"])

onMounted(() => {
appVersion.value = appInfo.branch ? (appInfo.branch + "-" + appInfo.revision) : appInfo.tag;
Expand Down Expand Up @@ -145,12 +144,6 @@ function logout() {
function getDateTime(time: any) {
return time ? DateTime.fromMillis(time).toLocaleString({ ...DateTime.DATETIME_MED, hourCycle: "h12" }) : "";
}

function goToOms() {
const link = (oms.value.startsWith('http') ? oms.value.replace(/\/api\/?|\/$/, "") : `https://${oms.value}.hotwax.io`) + `/qapps?token=${token.value}`

window.open(link, '_blank', 'noopener, noreferrer')
}
</script>

<style scoped>
Expand Down
Loading