From 6716baca3a3534b12299340ebba94271b39b73d7 Mon Sep 17 00:00:00 2001 From: westonz7042 Date: Sun, 11 May 2025 22:17:31 -0700 Subject: [PATCH] spam click issue --- frontend/src/pages/Individual-product-page.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/Individual-product-page.tsx b/frontend/src/pages/Individual-product-page.tsx index b8ffce8..9ce6b06 100644 --- a/frontend/src/pages/Individual-product-page.tsx +++ b/frontend/src/pages/Individual-product-page.tsx @@ -22,6 +22,7 @@ export function IndividualProductPage() { const [error, setError] = useState(); const [hasPermissions, setHasPermissions] = useState(false); const COOLDOWN = 60 * 24 * 1000 * 60; + const [isSubmitting, setIsSubmitting] = useState(false); useEffect(() => { if (!message) return; const t = setTimeout(() => setMessage(""), 3000); @@ -77,12 +78,16 @@ export function IndividualProductPage() { setMessage("Please wait before sending another interest email."); return; } - + if (isSubmitting) { + return; + } + setIsSubmitting(true); try { const response = await post("/api/interestEmail", { consumerId: user?.uid, productId: id }); const result = await response.json(); if (!response.ok) { setMessage(`Error: ${result.message}`); + setIsSubmitting(false); return; } @@ -97,6 +102,7 @@ export function IndividualProductPage() { }, COOLDOWN); } catch { setMessage("An unexpected error occurred."); + setIsSubmitting(false); } }; const isCooling = Boolean(cooldownEnd && Date.now() < cooldownEnd);