fix: prevent multiple form submissions in Contact component

This commit is contained in:
2025-02-22 17:15:05 +01:00
parent b0f2533710
commit a00e8241d2
2 changed files with 23 additions and 15 deletions

View File

@@ -19,9 +19,6 @@ COPY .env .env
# Build the Next.js application # Build the Next.js application
RUN npm run build RUN npm run build
# Set environmental variable for production mode
ENV NODE_ENV=production
# Expose the port the app runs on # Expose the port the app runs on
EXPOSE 3000 EXPOSE 3000

View File

@@ -40,19 +40,30 @@ export default function Contact() {
// Convert FormData to a plain object // Convert FormData to a plain object
const jsonData = JSON.stringify(data); const jsonData = JSON.stringify(data);
const response = await sendEmail(jsonData); //prevent multiple submissions
if (response.success) { const submitButton = form.querySelector("button[type='submit']");
form.reset(); if (submitButton) {
} submitButton.setAttribute("disabled", "true");
submitButton.textContent = "Sending...";
setBanner({ const response = await sendEmail(jsonData);
show: true, if (response.success) {
message: response.message, form.reset();
type: response.success ? "success" : "error", submitButton.textContent = "Sent!";
}); setTimeout(() => {
setTimeout(() => { submitButton.removeAttribute("disabled");
setBanner((prev) => ({ ...prev, show: false })); submitButton.textContent = "Send";
}, 3000); }, 2000);
}
setBanner({
show: true,
message: response.message,
type: response.success ? "success" : "error",
});
setTimeout(() => {
setBanner((prev) => ({ ...prev, show: false }));
}, 3000);
}
} }
return ( return (
<section <section