diff --git a/components/admin/UsersTable.vue b/components/admin/UsersTable.vue index 62407a0..07958be 100644 --- a/components/admin/UsersTable.vue +++ b/components/admin/UsersTable.vue @@ -32,6 +32,13 @@ > mdi-pencil + + mdi-delete + @@ -95,6 +102,28 @@ + + + + + + Confirmar Exclusão + + + Tem certeza que deseja excluir o usuário {{ userToDelete?.name }}? + Esta ação não pode ser desfeita. + + + + + Cancelar + + + Excluir + + + + @@ -109,6 +138,7 @@ export default { search: '', loading: false, dialogEdit: false, + dialogDelete: false, users: [], editedUser: { id: null, @@ -124,6 +154,7 @@ export default { password: '', passwordConfirmation: '' }, + userToDelete: null, errors: { name: '', email: '', @@ -245,12 +276,43 @@ export default { } }, + confirmDelete (user) { + this.userToDelete = user + this.dialogDelete = true + }, + + async deleteUser () { + try { + await axiosClient.delete(`/user/admins/${this.userToDelete.id}`) + + this.showAlert({ + alertMessage: 'Usuário excluído com sucesso!', + alertType: 'success' + }) + + this.closeDelete() + this.fetchUsers() + } catch (error) { + this.showAlert({ + alertMessage: 'Erro ao excluir usuário. Tente novamente mais tarde.', + alertType: 'error' + }) + } + }, + closeEdit () { this.dialogEdit = false this.$nextTick(() => { this.editedUser = Object.assign({}, this.defaultUser) this.errors = { name: '', email: '', password: '', passwordConfirmation: '' } }) + }, + + closeDelete () { + this.dialogDelete = false + this.$nextTick(() => { + this.userToDelete = null + }) } } }