Update contact form to use mail proxy
Some checks failed
Build and deploy updated apps / Build & deploy (push) Failing after 1m9s
Some checks failed
Build and deploy updated apps / Build & deploy (push) Failing after 1m9s
This commit is contained in:
parent
85d080ab05
commit
822182a17c
@ -21,4 +21,9 @@ export default defineNuxtConfig({
|
|||||||
{code: 'en', name: 'English', file: 'en.json'}
|
{code: 'en', name: 'English', file: 'en.json'}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
runtimeConfig: {
|
||||||
|
public: {
|
||||||
|
hotelId: "test"
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
@ -95,6 +95,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
/*TODO form should contain link to privacy statement?*/
|
||||||
const {t, tm, rt} = useI18n()
|
const {t, tm, rt} = useI18n()
|
||||||
import * as v from 'valibot'
|
import * as v from 'valibot'
|
||||||
import type {FormSubmitEvent} from '@nuxt/ui'
|
import type {FormSubmitEvent} from '@nuxt/ui'
|
||||||
@ -117,11 +118,26 @@ const toast = useToast()
|
|||||||
|
|
||||||
/* ───── submit handler ───── */
|
/* ───── submit handler ───── */
|
||||||
async function onSubmit(event: FormSubmitEvent<Schema>) {
|
async function onSubmit(event: FormSubmitEvent<Schema>) {
|
||||||
|
const config = useRuntimeConfig()
|
||||||
|
const hotelId = config.public.hotelId
|
||||||
|
|
||||||
|
if (!hotelId) {
|
||||||
|
toast.add({
|
||||||
|
title: 'Fehler',
|
||||||
|
description: 'Hotel-ID ist nicht konfiguriert!',
|
||||||
|
color: 'red'
|
||||||
|
})
|
||||||
|
throw new Error('Hotel ID not configured')
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await $fetch('/contact.php', {
|
await $fetch('https://api.dominikmilacher.com/contact', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: event.data
|
body: {
|
||||||
|
...event.data,
|
||||||
|
hotel: hotelId
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
toast.add({
|
toast.add({
|
||||||
@ -135,9 +151,10 @@ async function onSubmit(event: FormSubmitEvent<Schema>) {
|
|||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
toast.add({
|
toast.add({
|
||||||
title: 'Fehler',
|
title: 'Fehler',
|
||||||
description: err?.data?.message ?? 'Nachricht konnte nicht gesendet werden.',
|
description: err?.data?.detail ?? err?.message ?? 'Nachricht konnte nicht gesendet werden.',
|
||||||
color: 'red'
|
color: 'red'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
Loading…
x
Reference in New Issue
Block a user