HelpPage.vue
2.09 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<script setup>
import { onMounted, reactive, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { useRouter } from 'vue-router'
import { Badge, Button, Card, Textarea } from '@drama/ui'
import { api, getToken } from '../api.js'
const { t } = useI18n()
const router = useRouter()
const requests = ref(null)
const drafts = reactive({})
const error = ref('')
async function load() {
requests.value = (await api('GET', '/api/voko/help')).help_requests
}
/** @param {string} id */
async function answer(id) {
error.value = ''
try {
await api('POST', `/api/voko/help/${id}/answer`, { answer: drafts[id] })
await load()
} catch (err) {
error.value = err instanceof Error ? err.message : String(err)
}
}
onMounted(async () => {
if (getToken() === null) {
await router.push({ path: '/login', query: { next: '/help' } })
return
}
await load()
})
</script>
<template>
<h1>{{ t('help.title') }}</h1>
<p><router-link to="/agents">{{ t('board.back') }}</router-link></p>
<p v-if="error" role="alert">{{ error }}</p>
<template v-if="requests">
<p v-if="requests.length === 0">{{ t('help.empty') }}</p>
<Card v-for="request in requests" :key="request.id" class="voko-help">
<h2>{{ request.agent_name }} <Badge :variant="request.status === 'open' ? 'warning' : 'success'">{{ t(`help.status.${request.status}`) }}</Badge></h2>
<p>{{ t('help.task', { title: request.task_title }) }} · {{ new Date(request.created_at).toLocaleString() }}</p>
<p class="voko-pre">{{ request.question }}</p>
<template v-if="request.status === 'open'">
<label class="voko-field">{{ t('help.answer') }}<Textarea v-model="drafts[request.id]" :rows="3" /></label>
<Button :disabled="!drafts[request.id] || drafts[request.id].trim() === ''" @click="answer(request.id)">{{ t('help.send') }}</Button>
</template>
<p v-else class="voko-pre"><strong>{{ t('help.yourAnswer') }}</strong> {{ request.answer }}</p>
</Card>
</template>
</template>
<style scoped>
.voko-help {
margin-bottom: var(--drama-space-md);
}
.voko-pre {
white-space: pre-wrap;
}
</style>