2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
2022-11-29 10:18:58 +00:00
|
|
|
<article :class="{ me: isCurrentUser }" class="user-card">
|
2024-02-25 09:54:57 +00:00
|
|
|
<UserAvatar :user="user" width="48" />
|
2022-07-13 15:46:41 +00:00
|
|
|
|
|
|
|
<main>
|
|
|
|
<h1>
|
2023-08-20 22:35:58 +00:00
|
|
|
<span v-if="user.name" class="name">{{ user.name }}</span>
|
|
|
|
<span v-else class="name anonymous">Anonymous</span>
|
2023-11-10 13:16:06 +00:00
|
|
|
<Icon v-if="isCurrentUser" :icon="faCircleCheck" class="you text-highlight" title="This is you!" />
|
2024-03-30 16:49:25 +00:00
|
|
|
<Icon
|
2022-07-15 07:23:55 +00:00
|
|
|
v-if="user.is_admin"
|
|
|
|
:icon="faShield"
|
|
|
|
class="is-admin text-blue"
|
|
|
|
title="User has admin privileges"
|
|
|
|
/>
|
2024-03-30 16:49:25 +00:00
|
|
|
<img
|
|
|
|
v-if="user.sso_provider === 'Google'"
|
|
|
|
title="Google SSO"
|
|
|
|
:src="googleLogo"
|
|
|
|
alt="Google"
|
|
|
|
width="14"
|
|
|
|
height="14"
|
|
|
|
>
|
2022-07-13 15:46:41 +00:00
|
|
|
</h1>
|
|
|
|
|
|
|
|
<p class="email text-secondary">{{ user.email }}</p>
|
|
|
|
</main>
|
2024-02-25 09:54:57 +00:00
|
|
|
|
|
|
|
<div class="actions">
|
|
|
|
<template v-if="user.is_prospect">
|
|
|
|
<Btn class="btn-revoke" red small @click="revokeInvite">Revoke</Btn>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<Btn v-if="!user.is_prospect" class="btn-edit" orange small @click="edit">
|
|
|
|
{{ isCurrentUser ? 'Your Profile' : 'Edit' }}
|
|
|
|
</Btn>
|
|
|
|
<Btn v-if="!isCurrentUser" class="btn-delete" red small @click="destroy">Delete</Btn>
|
|
|
|
</template>
|
|
|
|
</div>
|
2022-04-15 14:24:30 +00:00
|
|
|
</article>
|
|
|
|
</template>
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
<script lang="ts" setup>
|
2024-03-30 16:49:25 +00:00
|
|
|
import googleLogo from '@/../img/logos/google.svg'
|
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'
|
2023-08-20 22:35:58 +00:00
|
|
|
import { invitationService } from '@/services'
|
2022-11-18 18:44:20 +00:00
|
|
|
import { useAuthorization, useDialogBox, useMessageToaster, useRouter } from '@/composables'
|
2023-08-20 22:35:58 +00:00
|
|
|
import { eventBus, parseValidationError } from '@/utils'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-07-07 18:05:46 +00:00
|
|
|
import Btn from '@/components/ui/Btn.vue'
|
2024-01-18 11:13:05 +00:00
|
|
|
import UserAvatar from '@/components/user/UserAvatar.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-11-18 17:45:38 +00:00
|
|
|
const { toastSuccess } = useMessageToaster()
|
2023-08-20 22:35:58 +00:00
|
|
|
const { showConfirmDialog, showErrorDialog } = useDialogBox()
|
2022-11-18 18:44:20 +00:00
|
|
|
const { go } = useRouter()
|
2022-11-18 17:45:38 +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-11-18 18:44:20 +00:00
|
|
|
const edit = () => isCurrentUser.value ? go('profile') : eventBus.emit('MODAL_SHOW_EDIT_USER_FORM', user.value)
|
2022-07-26 09:51:19 +00:00
|
|
|
|
2022-07-13 15:46:41 +00:00
|
|
|
const destroy = async () => {
|
2023-08-20 22:35:58 +00:00
|
|
|
if (!await showConfirmDialog(`Unperson ${user.value.name}?`)) return
|
|
|
|
|
2022-07-13 15:46:41 +00:00
|
|
|
await userStore.destroy(user.value)
|
2022-11-18 17:45:38 +00:00
|
|
|
toastSuccess(`User "${user.value.name}" deleted.`)
|
2022-04-15 17:00:08 +00:00
|
|
|
}
|
2023-08-20 22:35:58 +00:00
|
|
|
|
|
|
|
const revokeInvite = async () => {
|
|
|
|
if (!await showConfirmDialog(`Revoke the invite for ${user.value.email}?`)) return
|
|
|
|
|
|
|
|
try {
|
|
|
|
await invitationService.revoke(user.value)
|
|
|
|
toastSuccess(`Invitation for ${user.value.email} revoked.`)
|
|
|
|
} catch (err: any) {
|
|
|
|
if (err.response.status === 404) {
|
|
|
|
showErrorDialog('Cannot revoke the invite. Maybe it has been accepted?', 'Revocation Failed')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const msg = err.response.status === 422 ? parseValidationError(err.response.data)[0] : 'Unknown error.'
|
|
|
|
showErrorDialog(msg, 'Error')
|
|
|
|
}
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
</script>
|
|
|
|
|
2024-04-04 20:13:35 +00:00
|
|
|
<style lang="postcss" scoped>
|
2022-04-15 14:24:30 +00:00
|
|
|
.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;
|
2024-01-24 22:39:47 +00:00
|
|
|
transition: border-color .2s ease-in-out;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
border-color: rgba(255, 255, 255, .15);
|
|
|
|
}
|
2022-07-13 15:46:41 +00:00
|
|
|
|
2023-08-20 22:35:58 +00:00
|
|
|
.anonymous {
|
|
|
|
font-weight: var(--font-weight-light);
|
|
|
|
color: var(--color-text-secondary);
|
|
|
|
}
|
|
|
|
|
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);
|
2024-03-30 16:49:25 +00:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
gap: .5rem
|
2022-07-13 15:46:41 +00:00
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2024-02-25 09:54:57 +00:00
|
|
|
.actions {
|
|
|
|
display: flex;
|
|
|
|
gap: .5rem;
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|