|
1 |
| -import React, { useState } from 'react'; |
2 |
| -import { useNavigate } from 'react-router-dom'; // ✅ Importamos useNavigate |
| 1 | +import React, { useState } from "react"; |
| 2 | +import { useNavigate, Link } from "react-router-dom"; |
3 | 3 |
|
4 | 4 | export const RecuperacionContraseña = () => {
|
5 |
| - const [email, setEmail] = useState(''); |
6 |
| - const navigate = useNavigate(); // ✅ Inicializamos el hook de navegación |
| 5 | + const [email, setEmail] = useState(""); |
| 6 | + const navigate = useNavigate(); |
7 | 7 |
|
8 |
| - const handleSubmit = async (e) => { |
9 |
| - e.preventDefault(); |
10 |
| - |
11 |
| - try { |
12 |
| - const response = await fetch(`${process.env.BACKEND_URL}/api/forgotpassword`, { // ✅ Asegúrate de que esta ruta es correcta |
13 |
| - method: 'POST', |
14 |
| - headers: { 'Content-Type': 'application/json' }, |
15 |
| - body: JSON.stringify({ email }) |
16 |
| - }); |
| 8 | + const handleSubmit = async (e) => { |
| 9 | + e.preventDefault(); |
17 | 10 |
|
18 |
| - const data = await response.json(); |
19 |
| - |
20 |
| - if (response.ok) { |
21 |
| - alert("Correo enviado correctamente. Revisa tu bandeja de entrada."); // ✅ Alert con el mensaje |
22 |
| - navigate("/loginSignup"); // ✅ Redirigir al inicio de sesión después de aceptar el alert |
23 |
| - } else { |
24 |
| - alert(`Error: ${data.msg}`); |
25 |
| - } |
26 |
| - } catch (error) { |
27 |
| - alert("Error de conexión con el servidor."); |
| 11 | + try { |
| 12 | + const response = await fetch( |
| 13 | + `${process.env.BACKEND_URL}/api/forgotpassword`, |
| 14 | + { |
| 15 | + method: "POST", |
| 16 | + headers: { "Content-Type": "application/json" }, |
| 17 | + body: JSON.stringify({ email }), |
28 | 18 | }
|
29 |
| - }; |
| 19 | + ); |
30 | 20 |
|
31 |
| - return ( |
32 |
| - <div> |
33 |
| - <h2>Recuperar contraseña</h2> |
34 |
| - <form onSubmit={handleSubmit}> |
35 |
| - <input |
36 |
| - type="email" |
37 |
| - placeholder="Introduce tu correo electrónico" |
38 |
| - value={email} |
39 |
| - onChange={(e) => setEmail(e.target.value)} |
40 |
| - required |
41 |
| - /> |
42 |
| - <button type="submit">Enviar</button> |
43 |
| - </form> |
| 21 | + const data = await response.json(); |
| 22 | + |
| 23 | + if (response.ok) { |
| 24 | + alert("Correo enviado correctamente. Revisa tu bandeja de entrada."); |
| 25 | + navigate("/loginSignup"); |
| 26 | + } else { |
| 27 | + alert(`Error: ${data.msg}`); |
| 28 | + } |
| 29 | + } catch (error) { |
| 30 | + alert("Error de conexión con el servidor."); |
| 31 | + } |
| 32 | + }; |
| 33 | + |
| 34 | + return ( |
| 35 | + <div |
| 36 | + className="d-flex justify-content-center align-items-center min-vh-100" |
| 37 | + style={{ |
| 38 | + background: "linear-gradient(to bottom, #FFDCAE, #ffffff)", |
| 39 | + backgroundSize: "cover", |
| 40 | + padding: "2rem" |
| 41 | + }} |
| 42 | + > |
| 43 | + <div |
| 44 | + className="card shadow-lg p-5" |
| 45 | + style={{ |
| 46 | + width: "100%", |
| 47 | + maxWidth: "35rem", |
| 48 | + borderRadius: "20px", |
| 49 | + backgroundColor: "#ffffff", |
| 50 | + border: "none", |
| 51 | + boxShadow: "0 10px 30px rgba(0, 0, 0, 0.1)" |
| 52 | + }} |
| 53 | + > |
| 54 | + <div className="card-body text-center"> |
| 55 | + <h2 className="card-title mb-4" style={{ color: "#333", fontWeight: "bold" }}>Recuperar Contraseña</h2> |
| 56 | + <p className="text-muted mb-4" style={{ fontSize: "1.1rem" }}> |
| 57 | + Ingresa tu correo y te enviaremos instrucciones para restablecer tu contraseña. |
| 58 | + </p> |
| 59 | + <form onSubmit={handleSubmit}> |
| 60 | + <div className="mb-4"> |
| 61 | + <input |
| 62 | + type="email" |
| 63 | + className="form-control p-3" |
| 64 | + style={{ |
| 65 | + borderRadius: "10px", |
| 66 | + border: "2px solid #ddd", |
| 67 | + transition: "border-color 0.3s ease-in-out", |
| 68 | + }} |
| 69 | + placeholder="Introduce tu correo electrónico" |
| 70 | + value={email} |
| 71 | + onChange={(e) => setEmail(e.target.value)} |
| 72 | + required |
| 73 | + onFocus={(e) => e.target.style.borderColor = "#007bff"} |
| 74 | + onBlur={(e) => e.target.style.borderColor = "#ddd"} |
| 75 | + /> |
| 76 | + </div> |
| 77 | + <button |
| 78 | + type="submit" |
| 79 | + className="btn w-100 py-2" |
| 80 | + style={{ |
| 81 | + backgroundColor: "#007bff", |
| 82 | + color: "#ffffff", |
| 83 | + fontSize: "1.1rem", |
| 84 | + borderRadius: "10px", |
| 85 | + transition: "0.3s ease-in-out", |
| 86 | + }} |
| 87 | + onMouseOver={(e) => e.target.style.backgroundColor = "#0056b3"} |
| 88 | + onMouseOut={(e) => e.target.style.backgroundColor = "#007bff"} |
| 89 | + > |
| 90 | + Enviar Correo |
| 91 | + </button> |
| 92 | + </form> |
| 93 | + <Link to="/" className="d-block mt-3 text-secondary" style={{ fontSize: "1rem", textDecoration: "none" }}> |
| 94 | + <i className="bi bi-arrow-left"></i> Volver a la página principal |
| 95 | + </Link> |
44 | 96 | </div>
|
45 |
| - ); |
| 97 | + </div> |
| 98 | + </div> |
| 99 | + ); |
46 | 100 | };
|
0 commit comments