-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Implemented: centralized user profile component and image component on settings page (#169)
- Loading branch information
Showing
4 changed files
with
147 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<template> | ||
<img :src="imageUrl"/> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { onMounted, onUpdated, ref } from 'vue'; | ||
import { imageContext as context } from "../index"; | ||
declare let process: any; | ||
const props = defineProps(['src']); | ||
let imageUrl = ref(context.defaultImgUrl); | ||
let resourceUrl = process.env.VUE_APP_RESOURCE_URL || ""; | ||
const setImageUrl = () => { | ||
if (props.src) { | ||
if (props.src.indexOf('assets/') != -1) { | ||
// Assign directly in case of assets | ||
imageUrl.value = props.src; | ||
} else if (props.src.startsWith('http')) { | ||
// If starts with http, it is web url check for existence and assign | ||
checkIfImageExists(props.src).then(() => { | ||
imageUrl.value = props.src; | ||
}).catch(() => { | ||
console.error("Image doesn't exist"); | ||
}) | ||
} else { | ||
// Image is from resource server, hence append to base resource url, check for existence and assign | ||
const newImageUrl = resourceUrl.concat(props.src) | ||
checkIfImageExists(imageUrl).then(() => { | ||
imageUrl.value = newImageUrl; | ||
}).catch(() => { | ||
console.error("Image doesn't exist"); | ||
}) | ||
} | ||
} | ||
} | ||
const checkIfImageExists = (src: string) => { | ||
return new Promise((resolve, reject) => { | ||
const img = new Image(); | ||
img.onload = () => resolve(true); | ||
img.onerror = () => reject(false); | ||
img.src = src; | ||
}) | ||
} | ||
onMounted(() => { | ||
setImageUrl(); | ||
}) | ||
onUpdated(() => { | ||
setImageUrl(); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<template> | ||
<div class="user-profile"> | ||
<ion-card> | ||
<ion-item lines="full"> | ||
<ion-avatar slot="start" v-if="userProfile?.partyImageUrl"> | ||
<DxpImage :src="userProfile.partyImageUrl"/> | ||
</ion-avatar> | ||
<!-- ion-no-padding to remove extra side/horizontal padding as additional padding | ||
is added on sides from ion-item and ion-padding-vertical to compensate the removed | ||
vertical padding --> | ||
<ion-card-header class="ion-no-padding ion-padding-vertical"> | ||
<ion-card-subtitle>{{ userProfile.userLoginId }}</ion-card-subtitle> | ||
<ion-card-title>{{ userProfile.partyName }}</ion-card-title> | ||
</ion-card-header> | ||
</ion-item> | ||
<ion-button color="danger" @click="logout()">{{ logoutLabel }}</ion-button> | ||
<ion-button fill="outline" @click="goToLaunchpad()"> | ||
{{ goToLabel }} | ||
<ion-icon slot="end" :icon="openOutline" /> | ||
</ion-button> | ||
<!-- Commenting this code as we currently do not have reset password functionality --> | ||
<!-- <ion-button fill="outline" color="medium">{{ $t("Reset password") }}</ion-button> --> | ||
</ion-card> | ||
</div> | ||
</template> | ||
<script setup lang="ts"> | ||
import { | ||
IonAvatar, | ||
IonButton, | ||
IonCard, | ||
IonCardHeader, | ||
IonCardSubtitle, | ||
IonCardTitle, | ||
IonIcon, | ||
IonItem | ||
} from '@ionic/vue'; | ||
import { DxpImage } from './index'; | ||
import { openOutline } from 'ionicons/icons'; | ||
import { appContext } from '../index'; | ||
declare let process: any; | ||
const appState = appContext.config.globalProperties.$store; | ||
defineProps({ | ||
userProfile: { | ||
type: Object, | ||
required: true | ||
}, | ||
logoutLabel: { | ||
type: String, | ||
default: 'Logout' | ||
}, | ||
goToLabel: { | ||
type: String, | ||
default: 'Go To Launchpad' | ||
} | ||
}) | ||
const emit = defineEmits(['before-logout']); | ||
const appLoginUrl = process.env.VUE_APP_LOGIN_URL; | ||
const logout = () => { | ||
// Emit to handle actions and resets performed by apps before logout. | ||
emit('before-logout') | ||
appState.dispatch('user/logout').then(() => { | ||
const redirectUrl = window.location.origin + '/login' | ||
window.location.href = `${appLoginUrl}?isLoggedOut=true&redirectUrl=${redirectUrl}` | ||
}) | ||
} | ||
const goToLaunchpad = () => { | ||
window.location.href = appLoginUrl; | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.user-profile { | ||
display: grid; | ||
grid-template-columns: repeat(auto-fill, minmax(400px, 1fr)); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters