Skip to content

Commit 21b6326

Browse files
committed
feat: form submit error handling + message
1 parent 482c40f commit 21b6326

File tree

1 file changed

+51
-16
lines changed

1 file changed

+51
-16
lines changed

components/signup-card.vue

+51-16
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,21 @@
9393
<span v-if="fieldError.country" class="error message" v-html="errorMessage" />
9494
</div>
9595

96-
<ButtonCtaWithLoader
97-
:class="['submit-button', { submitted: !loading && formSubmitted }]"
98-
theme="primary"
99-
loader="signup-card-form"
100-
@clicked="submitForm">
101-
<template #button-content>
102-
<span class="button-label"> {{ submitButtonLabel }} </span>
103-
</template>
104-
</ButtonCtaWithLoader>
96+
<div class="button-row">
97+
<div v-if="submitError" class="submit-error">
98+
Uh oh, we were not able to send that data due to an error — please try again, or reach out to us via Slack
99+
</div>
100+
101+
<ButtonCtaWithLoader
102+
:class="['submit-button', { submitted: formSubmitted }]"
103+
theme="primary"
104+
loader="signup-card-form"
105+
@clicked="submitForm">
106+
<template #button-content>
107+
<span class="button-label"> {{ submitButtonLabel }} </span>
108+
</template>
109+
</ButtonCtaWithLoader>
110+
</div>
105111

106112
</div>
107113

@@ -123,6 +129,7 @@ const props = defineProps({
123129
124130
// ======================================================================== Data
125131
const formSubmitted = ref(false)
132+
const submitError = ref(false)
126133
const errorMessage = '[ Field is required ]'
127134
const fieldError = ref({
128135
firstName: false,
@@ -222,16 +229,21 @@ const submitForm = async () => {
222229
'Content-Type': 'application/json',
223230
'Authorization': `Bearer ${config.public.airtableToken}`
224231
}
225-
const res = await $fetch('https://api.airtable.com/v0/apphbQmrNLNNXiaqG/tblDUSr66nczukX9Y', {
232+
233+
await $fetch('https://api.airtable.com/v0/apphbQmrNLNNXiaqG/tblDUSr66nczukX9Y', {
226234
method: 'POST',
227235
body,
228236
headers
237+
}).then(() => {
238+
buttonStore.set({id: 'signup-card-form', loading: false})
239+
formSubmitted.value = true
240+
return
241+
229242
})
230-
if (res) {
231-
buttonStore.set({id: 'signup-card-form', loading: false})
232-
formSubmitted.value = true
233-
return
234-
}
243+
.catch(() => {
244+
submitError.value = true
245+
buttonStore.set({id: 'signup-card-form', loading: false})
246+
})
235247
}
236248
if(!firstName.value) { fieldError.value.firstName = true}
237249
if(!lastName.value) { fieldError.value.lastName = true}
@@ -314,8 +326,28 @@ const submitForm = async () => {
314326
color: var(--error);
315327
}
316328
329+
330+
.button-row {
331+
display: flex;
332+
justify-content: flex-end;
333+
align-items: center;
334+
@include mini {
335+
flex-direction: column;
336+
}
337+
}
338+
.submit-error {
339+
@include formFieldErrorMessage;
340+
color: var(--error);
341+
margin: 0 toRem(94) 0 toRem(5);
342+
@include mini {
343+
margin: 0 toRem(10) 1rem;
344+
}
345+
}
317346
.submit-button {
318-
align-self: flex-end;
347+
height: fit-content;
348+
@include mini {
349+
align-self: flex-end;
350+
}
319351
&.submitted,
320352
&.submitted:hover {
321353
cursor: default;
@@ -341,6 +373,9 @@ const submitForm = async () => {
341373
.name-fields {
342374
display: flex;
343375
justify-content: space-between;
376+
.field-wrapper:is(:last-of-type) {
377+
margin-bottom: toRem(24);
378+
}
344379
@include medium {
345380
flex-flow: row wrap;
346381
.field-wrapper {

0 commit comments

Comments
 (0)