AdminPage.vue
1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<script setup>
import { onMounted, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { Button, Card } from '@drama/ui'
import { api } from '../api.js'
const { t } = useI18n()
const requests = ref([])
const error = ref('')
async function load() {
try {
requests.value = (await api('GET', '/api/voko/admin/access-requests?status=pending')).access_requests
} catch (err) {
error.value = err instanceof Error ? err.message : String(err)
}
}
/**
* @param {string} id
* @param {'approved'|'rejected'} decision
*/
async function review(id, decision) {
await api('POST', `/api/voko/admin/access-requests/${id}/review`, { decision })
await load()
}
onMounted(load)
</script>
<template>
<Card>
<h1>{{ t('admin.title') }}</h1>
<p v-if="error">{{ error }}</p>
<p v-else-if="requests.length === 0">{{ t('admin.empty') }}</p>
<div v-for="request in requests" :key="request.id" class="voko-field">
<strong>{{ request.email }}</strong>
<span>{{ request.note }}</span>
<span>{{ request.created_at }}</span>
<div>
<Button @click="review(request.id, 'approved')">{{ t('admin.approve') }}</Button>
<Button variant="ghost" @click="review(request.id, 'rejected')">{{ t('admin.reject') }}</Button>
</div>
</div>
</Card>
</template>