templates2.Base.Nuxt/app/components/UserActions.vue
w4c-templates a7a56fd5e0
Some checks failed
CI / quality (push) Has been cancelled
chore(template): publish Base.Nuxt
2026-10-11 23:23:38 +03:00

29 lines
1,000 B
Vue

<script setup lang="ts">
const props = defineProps<{ id: string; role: string }>();
const busy = ref(false);
async function update(role: string) {
busy.value = true;
await $fetch(`/api/admin/users/${props.id}`, { method: 'PATCH', body: { role } }).catch(() => undefined);
busy.value = false;
await refreshNuxtData('admin-users');
}
async function remove() {
if (!window.confirm('Delete this user? This cannot be undone.')) return;
busy.value = true;
await $fetch(`/api/admin/users/${props.id}`, { method: 'DELETE' }).catch(() => undefined);
busy.value = false;
await refreshNuxtData('admin-users');
}
</script>
<template>
<div class="flex justify-end gap-2">
<button type="button" class="btn-secondary" :disabled="busy" @click="update(props.role === 'admin' ? 'user' : 'admin')">
{{ props.role === 'admin' ? 'Make user' : 'Make admin' }}
</button>
<button type="button" class="btn-danger" :disabled="busy" @click="remove">Delete</button>
</div>
</template>