From f038fe4c69a2d8c5701e0314c9c3f206a71a3085 Mon Sep 17 00:00:00 2001 From: rafael Date: Sat, 22 Nov 2025 22:46:35 -0400 Subject: [PATCH] Add payment modal for reloading credits with simulated payment flow Integrated a modal to handle credit reloading with a simulated payment process. Updated logic to manage payment amount, successful payment handling, and credit updates. Improved UI with validations and placeholders for future payment gateway integration. --- src/App.js | 108 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 99 insertions(+), 9 deletions(-) diff --git a/src/App.js b/src/App.js index a3b8948..5ef5cd4 100644 --- a/src/App.js +++ b/src/App.js @@ -41,17 +41,24 @@ function App() { setIsMobileMenuOpen(false); }; + const [showPayment, setShowPayment] = useState(false); + const handleReloadCredits = () => { - const input = window.prompt('¿Cuántos créditos desea recargar?'); - if (input == null) return; - const add = parseInt(input, 10); - if (Number.isNaN(add) || add <= 0) { - alert('Ingrese un número válido mayor a 0.'); - return; + // Abrir modal de pasarela de pago + setShowPayment(true); + }; + + const handlePaymentClose = () => setShowPayment(false); + + const handlePaymentSuccess = (amount) => { + // Actualizar créditos después de un pago exitoso + const add = parseInt(amount, 10); + if (!Number.isNaN(add) && add > 0) { + const next = credits + add; + setCredits(next); + try { localStorage.setItem('credits', String(next)); } catch {} } - const next = credits + add; - setCredits(next); - try { localStorage.setItem('credits', String(next)); } catch {} + setShowPayment(false); }; const headerTitle = activeView === 'scheduled' @@ -68,6 +75,25 @@ function App() { ? 'Perfil' : 'Dashboard'; + const [paymentAmount, setPaymentAmount] = useState(''); + const [isPaying, setIsPaying] = useState(false); + + const proceedPayment = async () => { + const val = parseInt(paymentAmount, 10); + if (Number.isNaN(val) || val <= 0) { + alert('Ingrese un monto válido mayor a 0.'); + return; + } + // Simulación de pasarela de pago + try { + setIsPaying(true); + await new Promise((res) => setTimeout(res, 1200)); + handlePaymentSuccess(val); + } finally { + setIsPaying(false); + } + }; + return (
)} + + {showPayment && ( +
+
e.stopPropagation()}> +
+

+ + Recargar créditos +

+ +
+
+
+
+
+ + setPaymentAmount(e.target.value)} + placeholder="Ej: 10" + disabled={isPaying} + autoFocus + /> +
+
+ + {/* Placeholder de pasarela de pago: reemplace con su integración real (Mercado Pago, Stripe, etc.) */} +
+
+

+ + Pasarela de pago +

+
+
+

+ Esta es una simulación. Conecte aquí su pasarela (iframe, checkout, etc.). +

+ +
+
+
+
+
+
+ )}
);