-
Notifications
You must be signed in to change notification settings - Fork 27
Implemented: centralized user profile component and image component on settings page (#169) #199
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
80cef76
Implemented: centralized user profile info in dxp-components (#169)
amansinghbais a115a8f
Implemented: image component in dxp-components (#169)
amansinghbais 423b0a2
Fixed: unused changes in shopifyImg component (#169)
amansinghbais f0820a9
Merge branch 'main' of https://github.com/hotwax/dxp-components into …
amansinghbais b041378
Improved: passing userProfile and button text as a prop (#169)
amansinghbais 5a7119f
Fixed: unused locale entry from user store (#169)
amansinghbais d6e1d64
Improved: getting env variable in component without storing in state …
amansinghbais 209d273
Improved: userprofile styling from apps move to dxp (#169)
amansinghbais 0049c41
Improved: default value for labels (#169)
amansinghbais File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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}` | ||
ymaheshwari1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }) | ||
| } | ||
|
|
||
| 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.