This commit is contained in:
Oliver
2025-10-03 10:07:18 -03:00
parent 8232058ec5
commit 53204119a1

View File

@@ -8,38 +8,105 @@ function createModal() {
modal.style.left = "0"; modal.style.left = "0";
modal.style.width = "100%"; modal.style.width = "100%";
modal.style.height = "100%"; modal.style.height = "100%";
modal.style.backgroundColor = "rgba(0,0,0,0.5)"; modal.style.backgroundColor = "rgba(0,0,0,0.6)";
modal.style.display = "none"; modal.style.display = "none";
modal.style.justifyContent = "center"; modal.style.justifyContent = "center";
modal.style.alignItems = "center"; modal.style.alignItems = "center";
modal.style.zIndex = "1000"; modal.style.zIndex = "1000";
modal.innerHTML = ` modal.innerHTML = `
<div style="background: #fff; padding: 25px; border-radius: 12px; max-width: 450px; width: 95%; position: relative; font-family: sans-serif; box-shadow: 0 4px 12px rgba(0,0,0,0.15);"> <div style="
<span id="closeModal" style="position: absolute; top: 10px; right: 15px; cursor: pointer; font-weight: bold; font-size: 20px;">&times;</span> background: #ffffff;
<h2 style="margin-bottom: 10px;">Order Details</h2> padding: 40px 30px;
<p id="productText" style="margin-bottom: 20px; font-weight: 500;"></p> border-radius: 16px;
max-width: 500px;
<form id="buyForm" style="display: flex; flex-direction: column; gap: 12px;"> width: 90%;
<input type="text" name="name" placeholder="Name" required> position: relative;
<input type="text" name="company" placeholder="Company" required> font-family: 'Arial', sans-serif;
<input type="text" name="country" placeholder="Country" required> box-shadow: 0 10px 25px rgba(0,0,0,0.2);
<input type="text" name="street" placeholder="Street" required> transition: transform 0.3s ease;
">
<span id="closeModal" style="
position: absolute;
top: 15px;
right: 20px;
cursor: pointer;
font-weight: bold;
font-size: 24px;
color: #555;
">&times;</span>
<h2 style="margin-bottom: 15px; font-size: 24px; color: #333;">Order Details</h2>
<p id="productText" style="margin-bottom: 25px; font-weight: 500; color: #555;"></p>
<form id="buyForm" style="display: flex; flex-direction: column; gap: 15px;">
<input type="text" name="name" placeholder="Name" required style="padding: 12px 15px; font-size: 16px; border: 1px solid #ccc; border-radius: 8px; outline: none; transition: border 0.2s;">
<input type="text" name="company" placeholder="Company" required style="padding: 12px 15px; font-size: 16px; border: 1px solid #ccc; border-radius: 8px; outline: none; transition: border 0.2s;">
<input type="text" name="country" placeholder="Country" required style="padding: 12px 15px; font-size: 16px; border: 1px solid #ccc; border-radius: 8px; outline: none; transition: border 0.2s;">
<input type="text" name="street" placeholder="Street" required style="padding: 12px 15px; font-size: 16px; border: 1px solid #ccc; border-radius: 8px; outline: none; transition: border 0.2s;">
<div style="display: flex; gap: 10px;"> <div style="display: flex; gap: 10px;">
<input type="text" name="zip" placeholder="ZIP" required style="flex: 1;"> <input type="text" name="zip" placeholder="ZIP" required style="flex: 1; padding: 12px 15px; font-size: 16px; border: 1px solid #ccc; border-radius: 8px; outline: none;">
<input type="text" name="town" placeholder="Town" required style="flex: 2;"> <input type="text" name="town" placeholder="Town" required style="flex: 2; padding: 12px 15px; font-size: 16px; border: 1px solid #ccc; border-radius: 8px; outline: none;">
</div> </div>
<input type="email" name="email" placeholder="Email" required>
<input type="email" name="email" placeholder="Email" required style="padding: 12px 15px; font-size: 16px; border: 1px solid #ccc; border-radius: 8px; outline: none; transition: border 0.2s;">
<input type="hidden" name="product"> <input type="hidden" name="product">
<input type="hidden" name="price"> <input type="hidden" name="price">
<button type="submit" style="padding: 10px; background: #007BFF; color: #fff; border: none; border-radius: 6px; cursor: pointer; font-size: 16px;">Submit</button>
<button type="submit" style="
padding: 14px;
background: #007BFF;
color: #fff;
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 18px;
font-weight: bold;
transition: background 0.3s;
" onmouseover="this.style.background='#0056b3'" onmouseout="this.style.background='#007BFF'">Buy Now</button>
</form> </form>
<div id="confirmation" style="
display: none;
margin-top: 20px;
padding: 20px;
background-color: #e6ffed;
color: #056608;
border-radius: 12px;
text-align: center;
font-weight: 500;
">
<p>Thank you for your purchase! 🎉</p>
<button id="closeConfirmation" style="
margin-top: 10px;
padding: 10px 20px;
background: #007BFF;
color: #fff;
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 16px;
transition: background 0.3s;
" onmouseover="this.style.background='#0056b3'" onmouseout="this.style.background='#007BFF'">Close</button>
</div>
</div> </div>
`; `;
document.body.appendChild(modal); document.body.appendChild(modal);
// Close modal
document.getElementById("closeModal").onclick = () => { modal.style.display = "none"; }; document.getElementById("closeModal").onclick = () => { modal.style.display = "none"; };
modal.onclick = (e) => { if (e.target === modal) modal.style.display = "none"; }; modal.onclick = (e) => { if (e.target === modal) modal.style.display = "none"; };
// Close confirmation
modal.querySelector("#closeConfirmation").onclick = () => {
modal.style.display = "none";
document.getElementById("buyForm").style.display = "flex";
document.getElementById("confirmation").style.display = "none";
};
return modal; return modal;
} }
@@ -62,6 +129,8 @@ function openModal(productHref) {
function handleFormSubmit() { function handleFormSubmit() {
const form = document.getElementById("buyForm"); const form = document.getElementById("buyForm");
const confirmation = document.getElementById("confirmation");
form.addEventListener("submit", async (e) => { form.addEventListener("submit", async (e) => {
e.preventDefault(); e.preventDefault();
const data = {}; const data = {};
@@ -75,9 +144,9 @@ function handleFormSubmit() {
}); });
if (res.ok) { if (res.ok) {
alert("Form submitted successfully!"); form.style.display = "none";
confirmation.style.display = "block";
form.reset(); form.reset();
document.getElementById("buyNowModal").style.display = "none";
} else { } else {
alert("Failed to submit form."); alert("Failed to submit form.");
} }