|
| 1 | +<template> |
| 2 | + <VRow align="center" justify="center"> |
| 3 | + <VCol> |
| 4 | + <VForm v-model="valid"> |
| 5 | + <VContainer> |
| 6 | + <VRow> |
| 7 | + <VCol cols="12" md="4" justify="center"> |
| 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 align="center" justify="center"> |
| 27 | + <VCol align="center" justify="center"> |
| 28 | + <VBtn |
| 29 | + :text="props.button_label" |
| 30 | + :color="props.button_color" |
| 31 | + @click="submit_recaptcha" |
| 32 | + /> |
| 33 | + </VCol> |
| 34 | + </VRow> |
| 35 | +</template> |
| 36 | + |
| 37 | +<script setup> |
| 38 | +const props = defineProps({ |
| 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 | + }, |
| 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 | +]; |
| 66 | +
|
| 67 | +onMounted(() => { |
| 68 | + if (import.meta.client) { |
| 69 | + if ( |
| 70 | + process.env.NODE_ENV !== "production" || |
| 71 | + infra_store.app_mode !== appMode.appMode.CLOUD |
| 72 | + ) { |
| 73 | + infra_store.$patch({ is_captcha_validated: true }); |
| 74 | + } |
| 75 | + } |
| 76 | +}); |
| 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 | + ); |
| 94 | +} |
| 95 | +</script> |
0 commit comments