|
1 | 1 | <template> |
2 | | - <ClientOnly> |
3 | | - <vue-recaptcha |
4 | | - ref="recaptcha" |
5 | | - :sitekey="props.site_key" |
6 | | - :load-recaptcha-script="true" |
7 | | - align-self="center" |
8 | | - @expired="infra_store.is_captcha_validated = false" |
9 | | - @verify="submit_recaptcha" |
10 | | - /> |
11 | | - </ClientOnly> |
| 2 | + <VRow align="center" justify="center" style="display: none"> |
| 3 | + <VCol cols="4"> |
| 4 | + <VForm v-model="valid"> |
| 5 | + <VContainer> |
| 6 | + <VRow> |
| 7 | + <VCol> |
| 8 | + <VTextField v-model="name" label="Name" required /> |
| 9 | + </VCol> |
| 10 | + </VRow> |
| 11 | + <VRow> |
| 12 | + <VCol> |
| 13 | + <VTextField |
| 14 | + v-model="email" |
| 15 | + :rules="emailRules" |
| 16 | + label="E-mail" |
| 17 | + required |
| 18 | + /> |
| 19 | + </VCol> |
| 20 | + </VRow> |
| 21 | + <VRow> |
| 22 | + <VCol> |
| 23 | + <VCheckbox label="Launch the app" v-model="launch" /> |
| 24 | + </VCol> |
| 25 | + </VRow> |
| 26 | + </VContainer> |
| 27 | + </VForm> |
| 28 | + </VCol> |
| 29 | + </VRow> |
| 30 | + <VRow align="center" justify="center"> |
| 31 | + <VCol cols="4" class="d-flex justify-center align-center"> |
| 32 | + <VBtn |
| 33 | + :text="props.button_label" |
| 34 | + :color="props.button_color" |
| 35 | + @click="submit_recaptcha" |
| 36 | + /> |
| 37 | + </VCol> |
| 38 | + </VRow> |
12 | 39 | </template> |
13 | 40 |
|
14 | 41 | <script setup> |
15 | | - import { VueRecaptcha } from "vue-recaptcha" |
16 | | - const infra_store = useInfraStore() |
17 | | -
|
18 | 42 | const props = defineProps({ |
19 | | - site_key: { type: String, required: true }, |
| 43 | + button_label: { |
| 44 | + type: String, |
| 45 | + required: false, |
| 46 | + default: "Launch the app", |
| 47 | + }, |
| 48 | + button_color: { |
| 49 | + type: String, |
| 50 | + required: false, |
| 51 | + default: "white", |
| 52 | + }, |
20 | 53 | }) |
| 54 | + const infra_store = useInfraStore() |
| 55 | + const name = ref("") |
| 56 | + const email = ref("") |
| 57 | + const launch = ref(false) |
| 58 | + const emailRules = [ |
| 59 | + (value) => { |
| 60 | + if (value) { |
| 61 | + return true |
| 62 | + } |
| 63 | + return "E-mail is required." |
| 64 | + }, |
| 65 | + (value) => { |
| 66 | + if (/.+@.+\..+/.test(value)) { |
| 67 | + return true |
| 68 | + } |
| 69 | + return "E-mail must be valid." |
| 70 | + }, |
| 71 | + ] |
21 | 72 |
|
22 | 73 | onMounted(() => { |
23 | 74 | if (import.meta.client) { |
|
29 | 80 | } |
30 | 81 | } |
31 | 82 | }) |
32 | | - async function submit_recaptcha(token) { |
33 | | - try { |
34 | | - const response = await $fetch.raw( |
35 | | - `/.netlify/functions/recaptcha?token=${token}`, |
36 | | - ) |
37 | | - infra_store.$patch({ is_captcha_validated: response.status == 200 }) |
38 | | - recaptcha.reset() |
39 | | - } catch (error) { |
40 | | - console.error(error) |
41 | | - } |
| 83 | + function submit_recaptcha() { |
| 84 | + $fetch( |
| 85 | + `/.netlify/functions/recaptcha?name=${name.value}&email=${email.value}&launch=${launch.value}`, |
| 86 | + { |
| 87 | + onResponse({ response }) { |
| 88 | + if (response.ok) { |
| 89 | + infra_store.$patch({ |
| 90 | + is_captcha_validated: response.status === 200, |
| 91 | + }) |
| 92 | + } |
| 93 | + }, |
| 94 | + }, |
| 95 | + ) |
42 | 96 | } |
43 | 97 | </script> |
0 commit comments