Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
chore: formated the email-form component
Browse files Browse the repository at this point in the history
  • Loading branch information
taciturnaxolotl committed Dec 18, 2023
1 parent 19e105a commit c1f6d25
Showing 1 changed file with 49 additions and 37 deletions.
86 changes: 49 additions & 37 deletions src/components/Email-Form.astro
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
<style>
#email-form {
transform: translateY(33em);
visibility: hidden;
position: absolute;
visibility: hidden;
position: absolute;
}

form {
Expand Down Expand Up @@ -148,42 +148,54 @@
</style>

<script>
document.getElementById('subscribeForm').addEventListener('submit', function (event) {
event.preventDefault();
document
.getElementById("subscribeForm")
.addEventListener("submit", function (event) {
event.preventDefault();

const formData = new FormData(event.target as HTMLFormElement);
const notification = document.getElementById('notification');
const chevronButton = document.getElementById('chevron-button');
const emailForm = document.getElementById('email-form');
const notificationTitle = document.getElementById('notification-title');
const notificationMessage = document.getElementById('notification-message');
const formData = new FormData(event.target as HTMLFormElement);
const notification = document.getElementById("notification");
const chevronButton = document.getElementById("chevron-button");
const emailForm = document.getElementById("email-form");
const notificationTitle = document.getElementById("notification-title");
const notificationMessage = document.getElementById(
"notification-message",
);

function displayNotification(title, message) {
notificationTitle.innerHTML = title;
notificationMessage.innerHTML = message
notification.classList.add('show');
// hide the form
emailForm.style.visibility = "hidden";
chevronButton.style.visibility = "visible";
}
function displayNotification(title, message) {
notificationTitle.innerHTML = title;
notificationMessage.innerHTML = message;

notification.classList.add("show");
// hide the form
emailForm.style.visibility = "hidden";
chevronButton.style.visibility = "visible";
}

fetch('/api/fetch', {
method: 'POST',
body: JSON.stringify(Object.fromEntries(formData)),
headers: {
'Content-Type': 'application/json',
},
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
displayNotification("Success!", "Thank you for signing up to our newsletter!" + "<br>" + data)
})
.catch(error => {
// Handle errors
console.error('Error:', error);
displayNotification("Error!", "There was an error signing you up to our newsletter. Please try again later." + "<br>" + error)
});
});
fetch("/api/fetch", {
method: "POST",
body: JSON.stringify(Object.fromEntries(formData)),
headers: {
"Content-Type": "application/json",
},
})
.then((response) => response.json())
.then((data) => {
console.log("Success:", data);
displayNotification(
"Success!",
"Thank you for signing up to our newsletter!" + "<br>" + data,
);
})
.catch((error) => {
// Handle errors
console.error("Error:", error);
displayNotification(
"Error!",
"There was an error signing you up to our newsletter. Please try again later." +
"<br>" +
error,
);
});
});
</script>

0 comments on commit c1f6d25

Please sign in to comment.