From 2c7ea9ee0c8d3f45b6768fff75dc7d53d2561c43 Mon Sep 17 00:00:00 2001 From: tikagan <30419893+tikagan@users.noreply.github.com> Date: Mon, 18 Sep 2023 15:51:42 -0400 Subject: [PATCH] feat: form submit error + styling --- components/subfooter-form.vue | 101 +++++++++++++++++++++------------- 1 file changed, 63 insertions(+), 38 deletions(-) diff --git a/components/subfooter-form.vue b/components/subfooter-form.vue index 30a17cb..49a3297 100644 --- a/components/subfooter-form.vue +++ b/components/subfooter-form.vue @@ -1,42 +1,46 @@ @@ -60,6 +64,8 @@ const props = defineProps({ // ======================================================================== Data const formSubmitted = ref(false) +const submitError = ref(false) +const errorMessage = "Uh oh, we were not able to send that data due to an error — please try again, or reach out to us via Slack" const fieldError = ref(false) const field = ref(false) // ==================================================================== Computed @@ -89,8 +95,7 @@ const updateValue = (val) => { * @method submitForm */ const submitForm = async () => { - // if (formSubmitted.value) { $button('triple-line-loader').set({ loading: false }); return } - if (formSubmitted.value) { return } + if (formSubmitted.value) { $button('triple-line-loader').set({ loading: false }); return } if (field.value) { const body = { records: [ @@ -105,16 +110,18 @@ const submitForm = async () => { 'Content-Type': 'application/json', 'Authorization': `Bearer ${config.public.airtableToken}` } - const res = await $fetch('https://api.airtable.com/v0/apphbQmrNLNNXiaqG/tblSB1NYasWQIDGlp', { + await $fetch('https://api.airtable.com/v0/apphbQmrNLNNXiaqG/tblSB1NYasWQIDGlp', { method: 'POST', body, headers - }) - if (res) { + }).then(() => { buttonStore.set({id: 'subfooter-card-newsletter-signup', loading: false}) formSubmitted.value = true return - } + }).catch(() => { + submitError.value = true + buttonStore.set({id: 'subfooter-card-newsletter-signup', loading: false}) + }) } if(!field.value) { fieldError.value = true @@ -127,6 +134,11 @@ const submitForm = async () => {