HomePage.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
<script setup>
import { onMounted, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { useRouter } from 'vue-router'
import { Button, Card, Input } from '@drama/ui'
import { api, getToken } from '../api.js'
const { t } = useI18n()
const router = useRouter()
const me = ref(null)
const note = ref('')
async function load() {
me.value = await api('GET', '/api/voko/me')
}
async function apply() {
await api('POST', '/api/voko/access-requests', { note: note.value })
await load()
}
onMounted(async () => {
if (getToken() === null) {
await router.push('/login')
return
}
await load()
})
</script>
<template>
<Card v-if="me">
<h1>{{ t('home.title') }}</h1>
<p>{{ me.user.email }}</p>
<template v-if="me.access_request === null">
<p>{{ t('home.notApplied') }}</p>
<label class="voko-field">{{ t('home.note') }}<Input v-model="note" /></label>
<Button @click="apply">{{ t('home.apply') }}</Button>
</template>
<p v-else>{{ t(`home.status.${me.access_request.status}`) }}</p>
<p v-if="me.access_request !== null && me.access_request.status === 'approved'"><router-link to="/agents">{{ t('home.agents') }}</router-link></p>
<router-link v-if="me.user.role === 'admin'" to="/admin">{{ t('home.admin') }}</router-link>
</Card>
</template>