-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.vue
66 lines (58 loc) · 1.98 KB
/
app.vue
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
66
<script lang="ts" setup>
import type { Captcha, Submission } from '@/types/vue-shim'
import { PushButton } from 'tailvue'
const { $toast } = useNuxtApp()
const captcha = ref<Captcha|undefined>(undefined)
const submission = ref<Submission>({
name: '',
captcha: '',
uuid: '',
})
const getCaptcha = async () => {
captcha.value = (await useFetch('/api/generate')).data.value as Captcha
submission.value.uuid = captcha.value.uuid
}
interface Response {
success: boolean
message: string
errors: string[]
}
const submit = async () => {
const { data } = await useFetch('/api/submit', {
method: 'POST',
body: submission.value,
}) as { data: { value: Response } }
if (data.value?.success) {
$toast.success(data.value?.message)
} else {
data.value.errors.map(e => $toast.show({ message: e, timeout: 0}))
getCaptcha()
}
}
onMounted(getCaptcha)
</script>
<template>
<div class="dark max-w-md m-16 mx-auto flex flex-col space-y-4 border border-gray-600 bg-gray-800 p-4 rounded-lg">
<div class="flex items-center justify-start">
<label class="w-30" for="name">Name</label>
<input id="name" type="text" class="w-full" v-model="submission.name" />
</div>
<div class="flex items-center justify-start">
<label class="w-30" for="captcha">Captcha</label>
<div class="w-40 mx-4 flex items-center bg-gray-300 border border-gray-600 rounded">
<span v-if="captcha" v-html="captcha.svg" />
</div>
<input id="captcha" type="text" class="w-40" @keydown.enter="submit" v-model="submission.captcha" />
</div>
<div class="flex items-center justify-end space-x-4">
<push-button value="Refresh" @click="getCaptcha">Refresh</push-button>
<push-button value="Submit" @click="submit">Submit</push-button>
</div>
</div>
</template>
<style>
body, html { @apply bg-gray-900 text-gray-300; }
input[type="text"] { @apply h-10 border border-gray-700 bg-gray-600 rounded; }
p { margin: 0; }
button { background: transparent; }
</style>