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

feat: display add icon when user avatar is not setting #4694

Merged
Merged
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
26 changes: 17 additions & 9 deletions console/src/modules/system/users/components/UserAvatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { apiClient } from "@/utils/api-client";
import {
IconRiPencilFill,
IconAddCircle,
VButton,
VAvatar,
VDropdown,
Expand All @@ -18,6 +19,7 @@ import { useQueryClient } from "@tanstack/vue-query";
import { useI18n } from "vue-i18n";
import { useFileDialog } from "@vueuse/core";
import { inject } from "vue";
import { computed } from "vue";

const queryClient = useQueryClient();
const { currentUserHasPermission } = usePermission();
Expand All @@ -41,7 +43,6 @@ const user = inject<Ref<DetailedUser | undefined>>("user");
const isCurrentUser = inject<ComputedRef<boolean>>("isCurrentUser");

const userAvatarCropper = ref<IUserAvatarCropperType>();
const showAvatarEditor = ref(false);
const visibleCropperModal = ref(false);
const originalFile = ref<File>() as Ref<File>;

Expand Down Expand Up @@ -117,14 +118,14 @@ const changeUploadAvatar = () => {
reset();
open();
};

const hasAvatar = computed(() => {
return !!user?.value?.user.spec.avatar;
});
</script>

<template>
<div
class="h-full w-full"
@mouseover="showAvatarEditor = true"
@mouseout="showAvatarEditor = false"
>
<div class="group h-full w-full">
<VAvatar
:src="user?.user.spec.avatar"
:alt="user?.user.spec.displayName"
Expand All @@ -137,18 +138,25 @@ const changeUploadAvatar = () => {
v-if="currentUserHasPermission(['system:users:manage']) || isCurrentUser"
>
<div
v-show="showAvatarEditor"
class="absolute left-0 right-0 top-0 h-full w-full cursor-pointer rounded-full border-0 bg-black/60 text-center leading-[5rem] transition-opacity duration-300 group-hover:opacity-100"
class="absolute left-0 right-0 top-0 hidden h-full w-full cursor-pointer items-center rounded-full border-0 bg-black/60 text-center transition-all duration-300 group-hover:flex"
:class="{
'!flex': !hasAvatar,
}"
>
<IconAddCircle
v-if="!hasAvatar"
class="inline-block w-full self-center text-2xl text-white"
/>
<IconRiPencilFill
v-else
class="inline-block w-full self-center text-2xl text-white"
/>
</div>
<template #popper>
<VDropdownItem @click="open()">
{{ $t("core.common.buttons.upload") }}
</VDropdownItem>
<VDropdownItem @click="handleRemoveCurrentAvatar">
<VDropdownItem v-if="hasAvatar" @click="handleRemoveCurrentAvatar">
{{ $t("core.common.buttons.delete") }}
</VDropdownItem>
</template>
Expand Down