2022-04-15 14:24:30 +00:00
|
|
|
|
<template>
|
2022-07-13 15:46:41 +00:00
|
|
|
|
<article :class="{ me: isCurrentUser }" class="user-card" data-testid="user-card">
|
|
|
|
|
<img :alt="`${user.name}'s avatar`" :src="user.avatar" height="80" width="80">
|
|
|
|
|
|
|
|
|
|
<main>
|
|
|
|
|
<h1>
|
|
|
|
|
<span class="name">{{ user.name }}</span>
|
2022-07-15 07:23:55 +00:00
|
|
|
|
<icon v-if="isCurrentUser" :icon="faCircleCheck" class="you text-highlight" title="This is you!"/>
|
|
|
|
|
<icon
|
|
|
|
|
v-if="user.is_admin"
|
|
|
|
|
:icon="faShield"
|
|
|
|
|
class="is-admin text-blue"
|
|
|
|
|
title="User has admin privileges"
|
|
|
|
|
/>
|
2022-07-13 15:46:41 +00:00
|
|
|
|
</h1>
|
|
|
|
|
|
|
|
|
|
<p class="email text-secondary">{{ user.email }}</p>
|
|
|
|
|
|
|
|
|
|
<footer>
|
|
|
|
|
<Btn class="btn-edit" data-testid="edit-user-btn" small orange @click="edit">
|
|
|
|
|
{{ isCurrentUser ? 'Your Profile' : 'Edit' }}
|
|
|
|
|
</Btn>
|
|
|
|
|
<Btn v-if="!isCurrentUser" class="btn-delete" data-testid="delete-user-btn" small red @click="confirmDelete">
|
|
|
|
|
Delete
|
|
|
|
|
</Btn>
|
|
|
|
|
</footer>
|
|
|
|
|
</main>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
</article>
|
|
|
|
|
</template>
|
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
|
<script lang="ts" setup>
|
2022-07-15 07:23:55 +00:00
|
|
|
|
import { faCircleCheck, faShield } from '@fortawesome/free-solid-svg-icons'
|
2022-07-13 15:46:41 +00:00
|
|
|
|
import { computed, toRefs } from 'vue'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
import { userStore } from '@/stores'
|
2022-07-26 09:51:19 +00:00
|
|
|
|
import { eventBus, requireInjection } from '@/utils'
|
2022-04-30 14:05:02 +00:00
|
|
|
|
import { useAuthorization } from '@/composables'
|
2022-07-26 09:51:19 +00:00
|
|
|
|
import { DialogBoxKey, MessageToasterKey } from '@/symbols'
|
2022-04-30 14:05:02 +00:00
|
|
|
|
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-07-26 09:51:19 +00:00
|
|
|
|
const toaster = requireInjection(MessageToasterKey)
|
|
|
|
|
const dialog = requireInjection(DialogBoxKey)
|
|
|
|
|
|
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-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
|
|
|
|
|
2022-07-13 15:46:41 +00:00
|
|
|
|
const edit = () => isCurrentUser.value ? router.go('profile') : eventBus.emit('MODAL_SHOW_EDIT_USER_FORM', user.value)
|
2022-07-26 09:51:19 +00:00
|
|
|
|
|
|
|
|
|
const confirmDelete = async () =>
|
|
|
|
|
await dialog.value.confirm(`You’re about to unperson ${user.value.name}. Are you sure?`) && await destroy()
|
2022-04-15 17:00:08 +00:00
|
|
|
|
|
2022-07-13 15:46:41 +00:00
|
|
|
|
const destroy = async () => {
|
|
|
|
|
await userStore.destroy(user.value)
|
2022-07-26 09:51:19 +00:00
|
|
|
|
toaster.value.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 {
|
2022-07-13 15:46:41 +00:00
|
|
|
|
padding: 10px;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
align-items: center;
|
|
|
|
|
border-radius: 5px;
|
|
|
|
|
background: var(--color-bg-secondary);
|
|
|
|
|
border: 1px solid var(--color-bg-secondary);
|
|
|
|
|
gap: 1rem;
|
|
|
|
|
|
|
|
|
|
img {
|
2022-07-18 17:01:30 +00:00
|
|
|
|
border-radius: 50%;
|
2022-07-13 15:46:41 +00:00
|
|
|
|
flex: 0 0 80px;
|
|
|
|
|
background: rgba(0, 0, 0, .2)
|
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
2022-07-13 15:46:41 +00:00
|
|
|
|
main {
|
|
|
|
|
flex: 1;
|
2022-04-15 14:24:30 +00:00
|
|
|
|
display: flex;
|
2022-07-13 15:46:41 +00:00
|
|
|
|
flex-direction: column;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
position: relative;
|
|
|
|
|
gap: .5rem;
|
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
2022-07-13 15:46:41 +00:00
|
|
|
|
h1 {
|
|
|
|
|
font-size: 1rem;
|
|
|
|
|
font-weight: var(--font-weight-normal);
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
2022-07-13 15:46:41 +00:00
|
|
|
|
> * + * {
|
|
|
|
|
margin-left: .5rem
|
2022-04-15 14:24:30 +00:00
|
|
|
|
}
|
2022-07-13 15:46:41 +00:00
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
2022-07-13 15:46:41 +00:00
|
|
|
|
footer {
|
|
|
|
|
visibility: hidden;
|
2022-04-23 21:46:25 +00:00
|
|
|
|
|
2022-07-13 15:46:41 +00:00
|
|
|
|
> * + * {
|
|
|
|
|
margin-left: .3rem;
|
2022-04-15 14:24:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-13 15:46:41 +00:00
|
|
|
|
@media (hover: none) {
|
|
|
|
|
visibility: visible;
|
2022-04-15 14:24:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-13 15:46:41 +00:00
|
|
|
|
&:hover footer {
|
|
|
|
|
visibility: visible;
|
2022-04-15 14:24:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|