feat(admin): add delete functionality for areas, categories, and teams in admin panel
This commit is contained in:
@@ -13,6 +13,10 @@ const { getUsers, updateUserBan, updateUserRoles } = useAdmin()
|
||||
const { data: usersRes, pending, refresh } = useAsyncData('admin-users', () => getUsers())
|
||||
|
||||
const search = ref('')
|
||||
const banError = ref('')
|
||||
const roleError = ref('')
|
||||
const pendingBanUser = ref<any | null>(null)
|
||||
const isUpdatingBan = ref(false)
|
||||
const parseRoles = (roles?: string) => roles ? roles.split(',').map((r) => r.trim().toUpperCase()).filter(Boolean) : []
|
||||
|
||||
const filteredUsers = computed(() => {
|
||||
@@ -27,17 +31,33 @@ const filteredUsers = computed(() => {
|
||||
)
|
||||
})
|
||||
|
||||
const handleToggleBan = async (id: number, currentBanStatus: boolean) => {
|
||||
if (!confirm(`Sei sicuro di voler ${currentBanStatus ? 'sbloccare' : 'bannare'} questo utente?`)) return
|
||||
|
||||
const askToggleBan = (user: any) => {
|
||||
pendingBanUser.value = user
|
||||
}
|
||||
|
||||
const closeBanModal = () => {
|
||||
if (isUpdatingBan.value) return
|
||||
pendingBanUser.value = null
|
||||
}
|
||||
|
||||
const handleToggleBan = async () => {
|
||||
if (!pendingBanUser.value) return
|
||||
|
||||
const user = pendingBanUser.value
|
||||
isUpdatingBan.value = true
|
||||
banError.value = ''
|
||||
|
||||
try {
|
||||
const res = await updateUserBan(id, { banned: !currentBanStatus })
|
||||
const res = await updateUserBan(user.id, { banned: !user.banned })
|
||||
if (res.ok) {
|
||||
await refresh()
|
||||
pendingBanUser.value = null
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to update user ban status', err)
|
||||
alert('Errore durante l\'aggiornamento dello stato di ban.')
|
||||
banError.value = 'Errore durante l\'aggiornamento dello stato di ban.'
|
||||
} finally {
|
||||
isUpdatingBan.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +78,8 @@ const closeRoleModal = () => {
|
||||
|
||||
const saveRoles = async () => {
|
||||
if (!editingUserId.value) return
|
||||
|
||||
|
||||
roleError.value = ''
|
||||
try {
|
||||
const res = await updateUserRoles(editingUserId.value, { roles: selectedRoles.value })
|
||||
if (res.ok) {
|
||||
@@ -67,7 +88,7 @@ const saveRoles = async () => {
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to update roles', err)
|
||||
alert('Errore durante l\'aggiornamento dei ruoli.')
|
||||
roleError.value = 'Errore durante l\'aggiornamento dei ruoli.'
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -95,6 +116,14 @@ const saveRoles = async () => {
|
||||
Nessun utente trovato.
|
||||
</div>
|
||||
|
||||
<div v-if="banError" class="alert alert-danger">
|
||||
{{ banError }}
|
||||
</div>
|
||||
|
||||
<div v-if="roleError" class="alert alert-danger">
|
||||
{{ roleError }}
|
||||
</div>
|
||||
|
||||
<div v-else class="table-responsive">
|
||||
<table class="table table-hover align-middle">
|
||||
<thead>
|
||||
@@ -138,7 +167,7 @@ const saveRoles = async () => {
|
||||
<button
|
||||
class="btn btn-sm"
|
||||
:class="user.banned ? 'btn-outline-success' : 'btn-outline-danger'"
|
||||
@click="handleToggleBan(user.id, !!user.banned)"
|
||||
@click="askToggleBan(user)"
|
||||
>
|
||||
{{ user.banned ? 'Sblocca' : 'Banna' }}
|
||||
</button>
|
||||
@@ -177,5 +206,16 @@ const saveRoles = async () => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ConfirmModal
|
||||
:open="pendingBanUser !== null"
|
||||
title="Conferma stato utente"
|
||||
:message="pendingBanUser ? `Vuoi ${pendingBanUser.banned ? 'sbloccare' : 'bannare'} utente ${pendingBanUser.first_name} ${pendingBanUser.last_name}?` : ''"
|
||||
:confirm-label="pendingBanUser?.banned ? 'Sblocca utente' : 'Banna utente'"
|
||||
:confirm-class="pendingBanUser?.banned ? 'btn-success' : 'btn-danger'"
|
||||
:pending="isUpdatingBan"
|
||||
@cancel="closeBanModal"
|
||||
@confirm="handleToggleBan"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user