Skip to content

Commit

Permalink
Merge pull request #127 from amansinghbais/#91
Browse files Browse the repository at this point in the history
Improved: user card so as to allow user jump directly to the details page (#91)
  • Loading branch information
ymaheshwari1 authored Aug 16, 2024
2 parents 494cdad + 65c2fab commit 84f38d6
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ VUE_APP_I18N_FALLBACK_LOCALE=en
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-dev", "inventorycount-uat"]
VUE_APP_MAARG_LOGIN=["atp", "company", "order-routing", "inventorycount-dev", "inventorycount-uat"]
VUE_APP_USERS_LOGIN_URL="http://users.hotwax.io/login"
64 changes: 64 additions & 0 deletions src/components/Image.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<template>
<img :src="imageUrl"/>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { useAuthStore } from '@/store/auth';
export default defineComponent({
name: "Image",
props: ['src'],
components: {},
mounted() {
this.setImageUrl();
},
updated() {
this.setImageUrl();
},
data() {
return {
imageUrl: require("@/assets/images/defaultImage.png")
}
},
methods: {
checkIfImageExists(src: string) {
return new Promise((resolve, reject) => {
const img = new Image();
img.onload = function () {
resolve(true);
}
img.onerror = function (error) {

Check warning on line 31 in src/components/Image.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / build_and_deploy

'error' is defined but never used

Check warning on line 31 in src/components/Image.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

'error' is defined but never used

Check warning on line 31 in src/components/Image.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

'error' is defined but never used
reject(false);
}
img.src = src;
})
},
setImageUrl() {
if (this.src) {
if (this.src.indexOf('assets/') != -1) {
// Assign directly in case of assets
this.imageUrl = this.src;
} else if (this.src.startsWith('http')) {
// If starts with http, it is web url check for existence and assign
this.checkIfImageExists(this.src).then(() => {
this.imageUrl = this.src;
}).catch(() => {
console.error("Image doesn't exist", this.src);

Check warning on line 47 in src/components/Image.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / build_and_deploy

Unexpected console statement

Check warning on line 47 in src/components/Image.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

Unexpected console statement

Check warning on line 47 in src/components/Image.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

Unexpected console statement
})
} else {
const authStore = useAuthStore();
const baseURL = authStore.getBaseUrl.replace("/api", "")
const imageUrl = baseURL.concat(this.src)
this.checkIfImageExists(imageUrl).then(() => {
this.imageUrl = imageUrl;
}).catch(() => {
console.error("Image doesn't exist", imageUrl);

Check warning on line 57 in src/components/Image.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / build_and_deploy

Unexpected console statement

Check warning on line 57 in src/components/Image.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

Unexpected console statement

Check warning on line 57 in src/components/Image.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

Unexpected console statement
})
}
}
}
},
});
</script>
64 changes: 64 additions & 0 deletions src/components/UserActionsPopover.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<template>
<ion-content>
<ion-list>
<ion-list-header>{{ authStore.current?.partyName ? authStore.current.partyName : authStore.current.userLoginId }}</ion-list-header>

<ion-item button @click="redirectToUserDetails()">
<ion-label>{{ translate("View profile") }}</ion-label>
<ion-icon :icon="personCircleOutline" />
</ion-item>
<ion-item button lines="none" @click="logout()">
<ion-label color="danger">{{ translate("Logout") }}</ion-label>
<ion-icon :icon="exitOutline" color="danger"/>
</ion-item>
</ion-list>
</ion-content>
</template>

<script lang="ts">
import {
IonContent,
IonIcon,
IonItem,
IonLabel,
IonList,
IonListHeader,
popoverController,
} from "@ionic/vue";
import { defineComponent } from "vue";
import { translate } from "@/i18n";
import { exitOutline, personCircleOutline } from 'ionicons/icons';
import { useAuthStore } from '@/store/auth';
export default defineComponent({
name: "UserActionsPopover",
components: {
IonContent,
IonIcon,
IonItem,
IonLabel,
IonList,
IonListHeader,
},
methods: {
redirectToUserDetails() {
window.location.href = `${process.env.VUE_APP_USERS_LOGIN_URL}?oms=${this.authStore.oms}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}&partyId=${this.authStore.current.partyId}`
popoverController.dismiss()
},
async logout() {
await this.authStore.logout()
popoverController.dismiss()
}
},
setup() {
const authStore = useAuthStore();
return {
authStore,
exitOutline,
personCircleOutline,
translate
}
}
});
</script>
3 changes: 2 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"Something went wrong while login. Please contact administrator.": "Something went wrong while login. Please contact administrator.",
"Sorry, your username or password is incorrect. Please try again.": "Sorry, your username or password is incorrect. Please try again.",
"This application is not enabled for your account": "This application is not enabled for your account",
"Username": "Username"
"Username": "Username",
"View profile": "View profile"
}
37 changes: 29 additions & 8 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@

<ion-card v-if="authStore.isAuthenticated">
<ion-list>
<ion-item lines="full">
<ion-icon slot="start" :icon="lockClosedOutline"/>
{{ authStore.current?.partyName ? authStore.current?.partyName : authStore.current.userLoginId }}
<ion-button fill="outline" color="medium" slot="end" @click="authStore.logout()">
{{ $t('Logout') }}
<ion-item lines="full" button @click="openUserActionsPopover($event)">
<ion-avatar slot="start">
<Image :src="authStore.current?.partyImageUrl" />
</ion-avatar>
<ion-label class="ion-text-nowrap">
<h2>{{ authStore.current?.partyName ? authStore.current?.partyName : authStore.current.userLoginId }}</h2>
</ion-label>
<ion-button fill="clear" slot="end" @click="openUserActionsPopover($event)">
<ion-icon color="medium" slot="icon-only" :icon="chevronForwardOutline" />
</ion-button>
</ion-item>
<ion-item lines="none">
<ion-item lines="none" button @click="goToOms(authStore.token.value, authStore.getOMS)">
<ion-icon slot="start" :icon="hardwareChipOutline"/>
<ion-label>
<h2>{{ authStore.getOMS }}</h2>
</ion-label>
<ion-button fill="clear" @click="goToOms(authStore.token.value, authStore.getOMS)">
<ion-button fill="clear">
<ion-icon color="medium" slot="icon-only" :icon="openOutline" />
</ion-button>
</ion-item>
Expand Down Expand Up @@ -66,6 +70,7 @@

<script lang="ts">
import {
IonAvatar,
IonBadge,
IonButton,
IonButtons,
Expand All @@ -77,10 +82,12 @@ import {
IonItem,
IonLabel,
IonList,
IonPage
IonPage,
popoverController
} from '@ionic/vue';
import { defineComponent, ref } from 'vue';
import {
chevronForwardOutline,
codeWorkingOutline,
hardwareChipOutline,
lockClosedOutline,
Expand All @@ -94,10 +101,14 @@ import { useRouter } from "vue-router";
import { goToOms } from '@hotwax/dxp-components'
import { isMaargLogin } from '@/util';
import { translate } from '@/i18n';
import UserActionsPopover from '@/components/UserActionsPopover.vue'
import Image from "@/components/Image.vue";
export default defineComponent({
name: 'Home',
components: {
Image,
IonAvatar,
IonBadge,
IonButton,
IonButtons,
Expand Down Expand Up @@ -138,6 +149,15 @@ 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 : ''}` : '')
},
async openUserActionsPopover(event: any) {
const userActionsPopover = await popoverController.create({
component: UserActionsPopover,
event,
showBackdrop: false,
});
userActionsPopover.present();
}
},
setup() {
Expand Down Expand Up @@ -229,6 +249,7 @@ export default defineComponent({
return {
authStore,
appCategory,
chevronForwardOutline,
codeWorkingOutline,
devHandle,
domain,
Expand Down

0 comments on commit 84f38d6

Please sign in to comment.