(feat): Fixed adding emails to subscribers list

This commit is contained in:
Blake Ridgway 2025-02-11 21:43:52 -06:00
parent 715f52d2fd
commit 524d56f747

View file

@ -1,16 +1,23 @@
document.getElementById("notify-button").addEventListener("click", async () => { document.getElementById("notify-button").addEventListener("click", async () => {
const emailInput = document.getElementById("email-input"); const emailInput = document.getElementById("email-input");
const email = emailInput.value; const email = emailInput.value.trim();
if (email) { if (email) {
try {
const response = await fetch("/subscribe", { const response = await fetch("/subscribe", {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email }), body: JSON.stringify({ email }),
}); });
// Check if response is OK, then parse JSON
const result = await response.json(); const result = await response.json();
console.log("Server response:", result);
alert(result.message || result.error); alert(result.message || result.error);
} catch (error) {
console.error("Error during subscribe fetch:", error);
alert("There was an error during subscription. Please try again later.");
}
emailInput.value = ""; // Clear input field emailInput.value = ""; // Clear input field
} else { } else {
alert("Please enter a valid email."); alert("Please enter a valid email.");