Skip to content

Commit 0cb94f8

Browse files
committed
fix: parameterize contact backend in contact form.
1 parent 3c5a660 commit 0cb94f8

3 files changed

Lines changed: 10 additions & 12 deletions

File tree

src/components/ContactForm.astro

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ interface Props {
66
title: string;
77
lead: string;
88
turnstileSiteKey: string;
9+
contactBackend: string;
910
}
1011
const props = Astro.props;
1112
---
@@ -64,21 +65,18 @@ const props = Astro.props;
6465
src="https://challenges.cloudflare.com/turnstile/v0/api.js"
6566
defer></script>
6667

67-
<script>
68+
<script define:vars={{ props }} is:inline>
6869
// Add event listener for form submission
6970
document.querySelector("form")?.addEventListener("submit", async (e) => {
7071
e.preventDefault();
71-
const formData = new FormData(e.target! as HTMLFormElement);
72+
const formData = new FormData(e.target);
7273

7374
// Call the contact webhook
7475
try {
75-
const response = await fetch(
76-
"https://wediy-life-contact.deno.dev/contact",
77-
{
78-
method: "POST",
79-
body: formData,
80-
}
81-
);
76+
const response = await fetch(props.contactBackend, {
77+
method: "POST",
78+
body: formData,
79+
});
8280

8381
if (!response.ok) {
8482
throw new Error("Network response was not ok");
@@ -94,9 +92,7 @@ const props = Astro.props;
9492
// Clear the form fields
9593
document
9694
.querySelectorAll("input,textarea")
97-
.forEach(
98-
(x) => ((x as HTMLInputElement | HTMLTextAreaElement).value = "")
99-
);
95+
.forEach((x) => (x.value = ""));
10096
} catch (error) {
10197
console.error("Error sending message:", error);
10298
window

src/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ sections:
1313
title: Contact Us
1414
lead: Let's get it done.
1515
turnstileSiteKey: 0x4AAAAAABXiVbLyKqAQitnM
16+
contactBackend: ktech-consulting-contact.deno.dev/contact

src/env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ declare module "~/config.yaml" {
4747
| {
4848
type: "contact-form";
4949
turnstileSiteKey: string;
50+
contactBackend: string;
5051
}
5152
);
5253
const value: {

0 commit comments

Comments
 (0)