Skip to content

Commit 7d32c65

Browse files
committed
feat: handle missing FORMSPREE_URL and some errors
1 parent 9fdb7be commit 7d32c65

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

components/Button.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ defineProps({
33
type: {
44
type: String,
55
default: 'submit'
6+
},
7+
disabled: {
8+
type: Boolean,
9+
default: false
610
}
711
})
812
</script>
913

1014
<template>
11-
<button :type="type">
15+
<button :type="type" :disabled="disabled">
1216
<slot />
1317
</button>
1418
</template>
@@ -33,6 +37,9 @@ css({
3337
'@dark': {
3438
backgroundColor: '{color.gray.100}',
3539
color: '{color.gray.900}',
40+
},
41+
'&:disabled': {
42+
cursor: 'not-allowed',
3643
}
3744
}
3845
})

components/content/ContactForm.vue

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ const alpine = useAppConfig().alpine
55
66
const { FORMSPREE_URL } = useRuntimeConfig().public
77
8+
if (!FORMSPREE_URL) {
9+
console.warn('No FORMSPREE_URL provided')
10+
}
11+
812
const status = ref()
913
1014
const props = defineProps({
11-
sendButton: {
15+
submitButtonText: {
1216
type: String,
1317
default: 'Send message'
1418
},
@@ -56,6 +60,8 @@ const onSend = async (e: any) => {
5660
e.preventDefault()
5761
const data = new FormData(e.target)
5862
63+
status.value = 'Sending...'
64+
5965
fetch(e.target.action, {
6066
method: e.target.method,
6167
body: data,
@@ -70,7 +76,11 @@ const onSend = async (e: any) => {
7076
// Handle errors from API
7177
response.json().then(data => {
7278
if (Object.hasOwn(data, 'errors')) {
79+
status.value = data["errors"][0].message
7380
console.error(data["errors"].map((error: any) => error["message"]).join(", "))
81+
setTimeout(() => {
82+
status.value = 'Send message'
83+
}, 2000)
7484
} else {
7585
console.error("There was a problem submitting your form")
7686
}
@@ -90,8 +100,8 @@ const onSend = async (e: any) => {
90100
<Input v-for="(field, index) in form" :key="index" v-model="field.data" :field="field" />
91101
</div>
92102
<div>
93-
<Button type="submit">
94-
{{ status ? status : sendButton }}
103+
<Button type="submit" :disabled="!FORMSPREE_URL">
104+
{{ status ? status : submitButtonText }}
95105
</Button>
96106
</div>
97107
</form>

components/data-entry/Input.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ css({
5757
fontSize: '{text.base.fontSize}',
5858
lineHeight: '{text.base.lineHeight}',
5959
fontWeight: '{fontWeight.semibold}',
60-
marginBottom: '{space.2}'
60+
marginBottom: '{space.2}',
61+
cursor: 'pointer',
6162
},
6263
'input, textarea': {
6364
backgroundColor: 'transparent',

0 commit comments

Comments
 (0)