29 lines
1,000 B
Vue
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>
|