diff --git a/.env.example b/.env.example index c768924..fae3aa0 100644 --- a/.env.example +++ b/.env.example @@ -5,4 +5,5 @@ VUE_APP_LOCALES={"en": "English", "ja": "日本語", "es": "Español"} VUE_APP_CURRENCY_FORMATS={"en": {"currency": {"style": "currency","currency": "USD"}}, "ja": {"currency": {"style": "currency", "currency": "JPY"}}, "es": {"currency": {"style": "currency","currency": "ESP"}}} VUE_APP_DEFAULT_ALIAS= VUE_APP_MAARG_LOGIN=["atp", "company", "order-routing", "inventorycount"] -VUE_APP_USERS_LOGIN_URL="http://users.hotwax.io/login" \ No newline at end of file +VUE_APP_USERS_LOGIN_URL="http://users.hotwax.io/login" +VUE_APP_OMS_WITH_MAARG=["preorder"] diff --git a/src/util/index.ts b/src/util/index.ts index bf5ed75..9869901 100644 --- a/src/util/index.ts +++ b/src/util/index.ts @@ -16,4 +16,10 @@ const isMaargLogin = (handle: string, environment = "") => { return maargLoginApps.some((appName: string) => appHandle.includes(appName)) } -export { isMaargLogin, showToast } \ No newline at end of file +const isOmsWithMaarg = (handle: string, environment = "") => { + const appHandle = environment ? handle + environment : handle + const appsWithMarg = JSON.parse(process.env.VUE_APP_OMS_WITH_MAARG ? process.env.VUE_APP_OMS_WITH_MAARG : []) + return appsWithMarg.some((appName: string) => appHandle.includes(appName)) +} + +export { isMaargLogin, isOmsWithMaarg, showToast } \ No newline at end of file diff --git a/src/views/Home.vue b/src/views/Home.vue index 0afda29..ccd1938 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -95,7 +95,7 @@ import { import { useAuthStore } from '@/store/auth'; import { useRouter } from "vue-router"; import { goToOms } from '@hotwax/dxp-components' -import { isMaargLogin } from '@/util'; +import { isMaargLogin, isOmsWithMaarg } from '@/util'; import { translate } from '@/i18n'; import UserActionsPopover from '@/components/UserActionsPopover.vue' import Image from "@/components/Image.vue"; @@ -144,7 +144,7 @@ export default defineComponent({ }, generateAppLink(app: any, appEnvironment = '') { const oms = isMaargLogin(app.handle, appEnvironment) ? this.authStore.getMaargOms : this.authStore.getOMS; - window.location.href = this.scheme + app.handle + appEnvironment + this.domain + (this.authStore.isAuthenticated ? `/login?oms=${oms.startsWith('http') ? isMaargLogin(app.handle, appEnvironment) ? oms : oms.includes('/api') ? oms : `${oms}/api/` : oms}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}${isMaargLogin(app.handle, appEnvironment) ? '&omsRedirectionUrl=' + this.authStore.getOMS : ''}` : '') + window.location.href = this.scheme + app.handle + appEnvironment + this.domain + (this.authStore.isAuthenticated ? `/login?oms=${oms.startsWith('http') ? isMaargLogin(app.handle, appEnvironment) ? oms : oms.includes('/api') ? oms : `${oms}/api/` : oms}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}${isMaargLogin(app.handle, appEnvironment) ? '&omsRedirectionUrl=' + this.authStore.getOMS : isOmsWithMaarg(app.handle, appEnvironment) ? '&omsRedirectionUrl=' + this.authStore.getMaargOms : ''}` : '') }, async openUserActionsPopover(event: any) { const userActionsPopover = await popoverController.create({ @@ -251,6 +251,7 @@ export default defineComponent({ domain, goToOms, isMaargLogin, + isOmsWithMaarg, lockClosedOutline, hardwareChipOutline, openOutline, diff --git a/src/views/Login.vue b/src/views/Login.vue index 5b3197c..c498423 100644 --- a/src/views/Login.vue +++ b/src/views/Login.vue @@ -76,7 +76,7 @@ import Logo from '@/components/Logo.vue'; import { arrowForwardOutline, gridOutline } from 'ionicons/icons' import { UserService } from "@/services/UserService"; import { translate } from "@/i18n"; -import { isMaargLogin, showToast } from "@/util"; +import { isMaargLogin, isOmsWithMaarg, showToast } from "@/util"; import { hasError } from "@hotwax/oms-api"; export default defineComponent({ @@ -304,6 +304,7 @@ export default defineComponent({ }, generateRedirectionLink() { let omsUrl = '' + let omsRedirectionUrl = '' if(isMaargLogin(this.authStore.getRedirectUrl)) { if(this.authStore.getMaargOms) omsUrl = this.authStore.getMaargOms else { @@ -311,10 +312,15 @@ export default defineComponent({ this.router.push("/") return; } + omsRedirectionUrl = this.authStore.oms + } + + if(isOmsWithMaarg(this.authStore.getRedirectUrl) && this.authStore.getMaargOms) { + omsRedirectionUrl = this.authStore.getMaargOms } omsUrl = omsUrl ? omsUrl : this.authStore.oms.startsWith('http') ? this.authStore.oms.includes('/api') ? this.authStore.oms : `${this.authStore.oms}/api/` : this.authStore.oms - window.location.replace(`${this.authStore.getRedirectUrl}?oms=${omsUrl}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}${isMaargLogin(this.authStore.getRedirectUrl) ? '&omsRedirectionUrl=' + this.authStore.oms : ''}`) + window.location.replace(`${this.authStore.getRedirectUrl}?oms=${omsUrl}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}${omsRedirectionUrl ? '&omsRedirectionUrl=' + omsRedirectionUrl : ''}`) } }, setup () {