Skip to content

Commit 2c7ea9e

Browse files
committed
feat: form submit error + styling
1 parent bae030b commit 2c7ea9e

File tree

1 file changed

+63
-38
lines changed

1 file changed

+63
-38
lines changed

components/subfooter-form.vue

+63-38
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
11
<template>
22
<div class="subfooter-form">
3-
<div :class="['form-field-container', { error: fieldError}]">
43

5-
<div class="detail-wrapper">
6-
<svg
7-
width="400"
8-
viewBox="0 0 400 41"
9-
fill="none"
10-
xmlns="http://www.w3.org/2000/svg"
11-
class="detail">
12-
<path
13-
:d="path"
14-
stroke="#FFC582"
15-
stroke-width="2"
16-
shape-rendering="crispEdges"
17-
class="stroke-path" />
18-
</svg>
19-
</div>
4+
<div class="form-wrapper">
5+
<div :class="['form-field-container', { error: fieldError}]">
6+
<div class="detail-wrapper">
7+
<svg
8+
width="400"
9+
viewBox="0 0 400 41"
10+
fill="none"
11+
xmlns="http://www.w3.org/2000/svg"
12+
class="detail">
13+
<path
14+
:d="path"
15+
stroke="#FFC582"
16+
stroke-width="2"
17+
shape-rendering="crispEdges"
18+
class="stroke-path" />
19+
</svg>
20+
</div>
2021

21-
<div class="field-email">
22-
<input
23-
class="email"
24-
:placeholder="placeholder"
25-
type="email"
26-
required="true"
27-
@input="updateValue($event.target.value)" />
22+
<div class="field-email">
23+
<input
24+
class="email"
25+
:placeholder="placeholder"
26+
type="email"
27+
required="true"
28+
@input="updateValue($event.target.value)" />
29+
</div>
2830
</div>
31+
32+
<ButtonCtaWithLoader
33+
:class="['submit-button', { submitted: formSubmitted }]"
34+
theme="secondary"
35+
loader="subfooter-card-newsletter-signup"
36+
@clicked="submitForm">
37+
<template #button-content>
38+
<span class="button-label"> {{ buttonText }} </span>
39+
</template>
40+
</ButtonCtaWithLoader>
2941
</div>
3042

31-
<ButtonCtaWithLoader
32-
:class="['submit-button', { submitted: formSubmitted }]"
33-
theme="secondary"
34-
loader="subfooter-card-newsletter-signup"
35-
@clicked="submitForm">
36-
<template #button-content>
37-
<span class="button-label"> {{ buttonText }} </span>
38-
</template>
39-
</ButtonCtaWithLoader>
43+
<span v-if="submitError" class="submit-error" v-html="errorMessage" />
4044

4145
</div>
4246
</template>
@@ -60,6 +64,8 @@ const props = defineProps({
6064
6165
// ======================================================================== Data
6266
const formSubmitted = ref(false)
67+
const submitError = ref(false)
68+
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"
6369
const fieldError = ref(false)
6470
const field = ref(false)
6571
// ==================================================================== Computed
@@ -89,8 +95,7 @@ const updateValue = (val) => {
8995
* @method submitForm
9096
*/
9197
const submitForm = async () => {
92-
// if (formSubmitted.value) { $button('triple-line-loader').set({ loading: false }); return }
93-
if (formSubmitted.value) { return }
98+
if (formSubmitted.value) { $button('triple-line-loader').set({ loading: false }); return }
9499
if (field.value) {
95100
const body = {
96101
records: [
@@ -105,16 +110,18 @@ const submitForm = async () => {
105110
'Content-Type': 'application/json',
106111
'Authorization': `Bearer ${config.public.airtableToken}`
107112
}
108-
const res = await $fetch('https://api.airtable.com/v0/apphbQmrNLNNXiaqG/tblSB1NYasWQIDGlp', {
113+
await $fetch('https://api.airtable.com/v0/apphbQmrNLNNXiaqG/tblSB1NYasWQIDGlp', {
109114
method: 'POST',
110115
body,
111116
headers
112-
})
113-
if (res) {
117+
}).then(() => {
114118
buttonStore.set({id: 'subfooter-card-newsletter-signup', loading: false})
115119
formSubmitted.value = true
116120
return
117-
}
121+
}).catch(() => {
122+
submitError.value = true
123+
buttonStore.set({id: 'subfooter-card-newsletter-signup', loading: false})
124+
})
118125
}
119126
if(!field.value) {
120127
fieldError.value = true
@@ -127,6 +134,11 @@ const submitForm = async () => {
127134
<style lang="scss" scoped>
128135
// ///////////////////////////////////////////////////////////////////// General
129136
.subfooter-form {
137+
position: relative;
138+
}
139+
140+
.form-wrapper {
141+
position: relative;
130142
display: flex;
131143
white-space: nowrap;
132144
margin-left: 1.5625rem;
@@ -138,6 +150,19 @@ const submitForm = async () => {
138150
}
139151
}
140152
153+
.submit-error {
154+
display: block;
155+
width: 66%;
156+
margin-top: toRem(5);
157+
word-break: break-word;
158+
text-align: right;
159+
@include formFieldErrorMessage;
160+
color: var(--error);
161+
@include mini {
162+
width: calc(100% - toRem(2));
163+
}
164+
}
165+
141166
// ////////////////////////////////////////////////////////////// Detail Wrapper
142167
.detail-wrapper {
143168
position: absolute;

0 commit comments

Comments
 (0)