diff --git a/app/components/Feedback.vue b/app/components/Feedback.vue index 422d6ce90..7a4dcb7ad 100644 --- a/app/components/Feedback.vue +++ b/app/components/Feedback.vue @@ -1,5 +1,6 @@ [ /> -import * as v from 'valibot' -import type { FormSubmitEvent } from '#ui/types' +import type { FormError, FormSubmitEvent } from '#ui/types' const { label = 'Subscribe to our newsletter', @@ -17,17 +16,16 @@ const { track } = useAnalytics() const loading = ref(false) -const schema = v.object({ - email: v.pipe(v.string(), v.email('Please enter a valid email')) -}) - -type Schema = v.InferOutput - const state = reactive({ email: '' }) -async function onSubmit(event: FormSubmitEvent) { +// The server validates the address too; this only catches typos before the request. +function validate(data: Partial): FormError[] { + return /^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/.test(data.email ?? '') ? [] : [{ name: 'email', message: 'Please enter a valid email' }] +} + +async function onSubmit(event: FormSubmitEvent) { loading.value = true await $fetch('/api/newsletter/subscribe', { @@ -49,7 +47,7 @@ async function onSubmit(event: FormSubmitEvent) {