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