2022-04-15 14:24:30 +00:00
|
|
|
|
<template>
|
2022-05-10 23:01:48 +00:00
|
|
|
|
<article v-if="showing" :class="{ me: isCurrentUser }" class="user-card" data-testid="user-card">
|
2022-04-15 14:24:30 +00:00
|
|
|
|
<div class="info">
|
2022-04-23 21:50:05 +00:00
|
|
|
|
<img :alt="`${user.name}'s avatar`" :src="user.avatar" height="96" width="96">
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
|
|
|
|
<div class="right">
|
|
|
|
|
<div>
|
|
|
|
|
<h1>
|
|
|
|
|
<span class="name">{{ user.name }}</span>
|
2022-05-10 23:01:48 +00:00
|
|
|
|
<i v-if="isCurrentUser" class="you text-orange fa fa-check-circle" title="This is you!"/>
|
|
|
|
|
<i v-if="user.is_admin" class="is-admin text-blue fa fa-shield" title="User has admin privileges"/>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
</h1>
|
2022-05-10 23:01:48 +00:00
|
|
|
|
<p class="email">{{ user.email }}</p>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="buttons">
|
2022-06-10 10:47:46 +00:00
|
|
|
|
<Btn class="btn-edit" data-testid="edit-user-btn" small orange @click="edit">{{ editButtonLabel }}</Btn>
|
|
|
|
|
<Btn v-if="!isCurrentUser" class="btn-delete" data-testid="delete-user-btn" small red @click="confirmDelete">
|
2022-04-15 14:24:30 +00:00
|
|
|
|
Delete
|
2022-04-15 17:00:08 +00:00
|
|
|
|
</Btn>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</article>
|
|
|
|
|
</template>
|
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
|
<script lang="ts" setup>
|
2022-07-07 18:05:46 +00:00
|
|
|
|
import { computed, ref, toRefs } from 'vue'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
import { userStore } from '@/stores'
|
|
|
|
|
import { alerts } from '@/utils'
|
2022-04-30 14:05:02 +00:00
|
|
|
|
import { useAuthorization } from '@/composables'
|
|
|
|
|
import router from '@/router'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
2022-07-07 18:05:46 +00:00
|
|
|
|
import Btn from '@/components/ui/Btn.vue'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
|
const props = defineProps<{ user: User }>()
|
|
|
|
|
const { user } = toRefs(props)
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
|
const showing = ref(true)
|
|
|
|
|
|
2022-04-30 14:05:02 +00:00
|
|
|
|
const { currentUser } = useAuthorization()
|
|
|
|
|
|
|
|
|
|
const isCurrentUser = computed(() => user.value.id === currentUser.value.id)
|
2022-04-15 17:00:08 +00:00
|
|
|
|
const editButtonLabel = computed(() => isCurrentUser.value ? 'Update Profile' : 'Edit')
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits(['editUser'])
|
|
|
|
|
|
|
|
|
|
const edit = () => isCurrentUser.value ? router.go('profile') : emit('editUser', user.value)
|
|
|
|
|
const confirmDelete = () => alerts.confirm(`You’re about to unperson ${user.value.name}. Are you sure?`, destroy)
|
|
|
|
|
|
|
|
|
|
const destroy = () => {
|
|
|
|
|
userStore.destroy(user.value)
|
|
|
|
|
showing.value = false
|
2022-04-21 22:51:48 +00:00
|
|
|
|
alerts.success(`User "${user.value.name}" deleted.`)
|
2022-04-15 17:00:08 +00:00
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.user-card {
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
|
|
|
|
.info {
|
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
|
|
img {
|
|
|
|
|
flex: 0 0 96px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.email {
|
|
|
|
|
opacity: .5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.right {
|
|
|
|
|
flex: 1;
|
|
|
|
|
padding: 1rem;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
background-color: rgba(255, 255, 255, .02);
|
|
|
|
|
position: relative;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
h1 {
|
|
|
|
|
font-size: 1.4rem;
|
|
|
|
|
margin-bottom: .25rem;
|
|
|
|
|
|
|
|
|
|
> * + * {
|
|
|
|
|
margin-left: .5rem
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.buttons {
|
|
|
|
|
display: none;
|
|
|
|
|
margin-top: .5rem;
|
|
|
|
|
|
2022-04-23 21:46:25 +00:00
|
|
|
|
> * + * {
|
|
|
|
|
margin-left: .25rem;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-15 14:24:30 +00:00
|
|
|
|
@media (hover: none) {
|
|
|
|
|
display: block;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&:hover .buttons {
|
|
|
|
|
display: block;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@media only screen and (max-width: 1024px) {
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|