koel/resources/assets/js/components/shared/user-item.vue
2016-12-01 17:54:28 +07:00

82 lines
1.8 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<article class="user-item" :class="{ me: isCurrentUser }">
<div class="info">
<img :src="user.avatar" width="128" height="128">
<div class="right">
<div>
<h1>{{ user.name }}
<i v-if="isCurrentUser" class="you fa fa-check-circle"/>
</h1>
<p>{{ user.email }}</p>
</div>
<div class="buttons">
<button class="btn btn-blue btn-edit" @click="edit">
{{ isCurrentUser ? 'Update Profile' : 'Edit' }}
</button>
<button v-if="!isCurrentUser" class="btn btn-red btn-delete" @click="del">Delete</button>
</div>
</div>
</div>
</article>
</template>
<script>
import { userStore } from '../../stores'
import router from '../../router'
import { alerts } from '../../utils'
export default {
props: ['user'],
data () {
return {
confirmingDelete: false
}
},
computed: {
/**
* Determine if the current logged in user is the user bound to this component.
*
* @return {Boolean}
*/
isCurrentUser () {
return this.user.id === userStore.current.id
}
},
methods: {
/**
* Trigger editing a user.
* If the user is the current logged-in user, redirect to the profile screen instead.
*/
edit () {
if (this.isCurrentUser) {
router.go('profile')
return
}
this.$emit('editUser', this.user)
},
/**
* Kill off the freaking user.
*/
del () {
alerts.confirm(`Youre about to unperson ${this.user.name}. Are you sure?`, () => {
userStore.destroy(this.user).then(() => {
this.$destroy(true)
})
})
}
}
}
</script>
<style lang="sass">
@import "../../../sass/partials/_vars.scss";
@import "../../../sass/partials/_mixins.scss";
</style>