visatas cambiarpass y navheader
This commit is contained in:
@@ -4,79 +4,82 @@ import { useState } from "react";
|
||||
import axios from "axios";
|
||||
import { useRouter } from "next/navigation";
|
||||
import toast from "react-hot-toast";
|
||||
import "../../styles/layout/ForgotPasswordPage.scss"; // ajusta ruta si tu proyecto la tiene en otro sitio
|
||||
import "../../styles/layout/ForgotPasswordPage.scss";
|
||||
import Link from "next/link";
|
||||
|
||||
export default function Page() {
|
||||
const [email, setEmail] = useState("");
|
||||
const [nombre, setNombre] = useState("");
|
||||
const [contraseña, setContraseña] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const router = useRouter();
|
||||
|
||||
const validateEmail = (e: string) => {
|
||||
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e);
|
||||
};
|
||||
|
||||
const handleSubmit = async (ev: React.FormEvent<HTMLFormElement>) => {
|
||||
ev.preventDefault();
|
||||
if (!validateEmail(email)) {
|
||||
toast.error("Ingresa un correo válido.");
|
||||
|
||||
if (nombre.trim().length < 3) {
|
||||
toast.error("El nombre debe tener al menos 3 caracteres.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (contraseña.trim().length < 6) {
|
||||
toast.error("La contraseña debe tener al menos 6 caracteres.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
const res = await axios.post("/api/auth/forgot-password", { email });
|
||||
const res = await axios.post("/api/admin/change-password", {
|
||||
nombre,
|
||||
contraseña,
|
||||
});
|
||||
|
||||
if (res.status === 200) {
|
||||
toast.success(
|
||||
"Si existe esa cuenta, recibirás un correo con instrucciones."
|
||||
);
|
||||
// Opcional: redirigir al login después de enviar
|
||||
setTimeout(() => router.push("/"), 1200);
|
||||
toast.success("Contraseña actualizada correctamente.");
|
||||
setNombre("");
|
||||
setContraseña("");
|
||||
} else {
|
||||
toast.error("Ocurrió un error. Intenta de nuevo.");
|
||||
toast.error("No se pudo cambiar la contraseña.");
|
||||
}
|
||||
} catch (error) {
|
||||
// manejar mensajes de error desde el servidor si vienen
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
toast.error("Ocurrió un error al cambiar la contraseña.");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<main
|
||||
className="forgot-password-page"
|
||||
>
|
||||
<h1>¿Olvidaste tu contraseña?</h1>
|
||||
<p>
|
||||
Escribe el correo asociado a tu cuenta y te enviaremos instrucciones
|
||||
para restablecerla.
|
||||
</p>
|
||||
<main className="forgot-password-page">
|
||||
<h1>Cambiar contraseña</h1>
|
||||
<p>Ingresa el nombre del usuario y su nueva contraseña.</p>
|
||||
|
||||
<form
|
||||
onSubmit={handleSubmit}
|
||||
className="forgot-form"
|
||||
style={{ display: "grid", gap: 12 }}
|
||||
>
|
||||
<label htmlFor="email">Correo electrónico</label>
|
||||
<form onSubmit={handleSubmit} className="forgot-form">
|
||||
<label htmlFor="nombre">Nombre de usuario</label>
|
||||
<input
|
||||
id="email"
|
||||
type="email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
placeholder="tu@correo.com"
|
||||
id="nombre"
|
||||
type="text"
|
||||
value={nombre}
|
||||
onChange={(e) => setNombre(e.target.value)}
|
||||
placeholder="Nombre de usuario"
|
||||
required
|
||||
/>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? "Enviando..." : "Enviar instrucciones"}
|
||||
<label htmlFor="contraseña">Nueva contraseña</label>
|
||||
<input
|
||||
id="contraseña"
|
||||
type="password"
|
||||
value={contraseña}
|
||||
onChange={(e) => setContraseña(e.target.value)}
|
||||
placeholder="Nueva contraseña"
|
||||
required
|
||||
/>
|
||||
|
||||
<button type="submit" disabled={loading}>
|
||||
{loading ? "Actualizando..." : "Cambiar contraseña"}
|
||||
</button>
|
||||
|
||||
<div style={{ marginTop: 8 }}>
|
||||
<Link href="/">Recordé mi contraseña — Iniciar sesión</Link>
|
||||
<Link href="/">Regresar al inicio</Link>
|
||||
</div>
|
||||
</form>
|
||||
</main>
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
.barNavigation {
|
||||
text-align: center;
|
||||
justify-content: end;
|
||||
background-color: #ffffff;
|
||||
display: flex;
|
||||
width: 100%;
|
||||
top: 0;
|
||||
height: 45px;
|
||||
max-height: 40px;
|
||||
}
|
||||
|
||||
.barNavigation ul {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
width: 90%;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.barNavigation li {
|
||||
transition: all 0.3s ease;
|
||||
cursor: pointer;
|
||||
width: auto;
|
||||
transition: background-color 0.3s ease;
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.menuToggle {
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
cursor: pointer;
|
||||
padding: 10px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.menuToggle div {
|
||||
width: 25px;
|
||||
height: 3px;
|
||||
background-color: black;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.subMenu {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
border-radius: 4px 4px 0 0;
|
||||
}
|
||||
|
||||
.subMenu ul {
|
||||
opacity: 0;
|
||||
max-height: 0;
|
||||
position: absolute;
|
||||
flex-direction: column;
|
||||
min-width: 200px;
|
||||
max-width: 300px;
|
||||
left: 0;
|
||||
background-color: #003e79;
|
||||
transition: opacity 0.4s ease, max-height 0.4s ease;
|
||||
}
|
||||
|
||||
.subMenu ul a {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.subMenu:hover ul {
|
||||
opacity: 1;
|
||||
max-height: 500px;
|
||||
}
|
||||
|
||||
.subMenu:hover ul a {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.subMenu li {
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
.subMenu span {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #383838;
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.links {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
/* Estilo del botón de cierre de sesión */
|
||||
.logout-button {
|
||||
background-color: #ff4d4d;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 8px 16px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-weight: bold;
|
||||
font-size: 2rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
max-width: 200px;
|
||||
|
||||
&:hover {
|
||||
background-color: #e63939;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 1000px) {
|
||||
.menuToggle {
|
||||
display: flex;
|
||||
position: relative;
|
||||
align-items: end;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.barNavigation {
|
||||
font-size: 15px;
|
||||
display: block;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.barNavigation ul {
|
||||
position: absolute;
|
||||
background-color: #f4f5f7;
|
||||
flex-direction: column;
|
||||
padding: 10px 0;
|
||||
align-items: center;
|
||||
display: none;
|
||||
z-index: 1;
|
||||
height: auto;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.barNavigation ul.active {
|
||||
left: 0;
|
||||
display: flex;
|
||||
width: 100vw;
|
||||
}
|
||||
|
||||
.barNavigation li:hover {
|
||||
background-color: #d59f0f;
|
||||
color: black;
|
||||
border-radius: 0;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.subMenu ul {
|
||||
width: 100%;
|
||||
border-radius: 4px;
|
||||
position: relative;
|
||||
background-color: rgb(1, 92, 184);
|
||||
}
|
||||
|
||||
.logout-button {
|
||||
margin-top: 10px;
|
||||
font-size: 1.75rem;
|
||||
padding: 6px 12px;
|
||||
max-width: 180px;
|
||||
}
|
||||
|
||||
thead,
|
||||
tbody {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.subMenu a span {
|
||||
color: black;
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,8 @@
|
||||
color: #222;
|
||||
}
|
||||
|
||||
input[type="email"] {
|
||||
input[type="text"],
|
||||
input[type="password"] {
|
||||
padding: 1rem 0.8rem;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 8px;
|
||||
@@ -95,7 +96,8 @@
|
||||
background: #1e1e1e;
|
||||
color: #eee;
|
||||
|
||||
input[type="email"] {
|
||||
input[type="text"],
|
||||
input[type="password"] {
|
||||
background: #2a2a2a;
|
||||
border-color: #444;
|
||||
color: #f3f3f3;
|
||||
@@ -129,7 +131,7 @@
|
||||
margin: 15rem auto;
|
||||
padding: 1.5rem;
|
||||
width: 92%;
|
||||
box-shadow: none; // para evitar saturar pantallas pequeñas
|
||||
box-shadow: none;
|
||||
|
||||
h1 {
|
||||
font-size: 1.6rem;
|
||||
@@ -141,7 +143,8 @@
|
||||
}
|
||||
|
||||
.forgot-form {
|
||||
input[type="email"] {
|
||||
input[type="text"],
|
||||
input[type="password"] {
|
||||
font-size: 0.95rem;
|
||||
padding: 0.9rem;
|
||||
}
|
||||
@@ -174,7 +177,8 @@
|
||||
.forgot-form {
|
||||
gap: 1.2rem;
|
||||
|
||||
input[type="email"] {
|
||||
input[type="text"],
|
||||
input[type="password"] {
|
||||
font-size: 1.05rem;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import "../app/styles/layout/BarNavigation.scss";
|
||||
import Link from "next/link";
|
||||
|
||||
function BarNavigation() {
|
||||
const router = useRouter();
|
||||
const [openMenu, setOpenMenu] = useState(false);
|
||||
|
||||
const toggleMenu = () => setOpenMenu(!openMenu);
|
||||
|
||||
const cerrarSesion = () => {
|
||||
if (typeof window !== "undefined") {
|
||||
localStorage.removeItem("loggedIn");
|
||||
router.push("/");
|
||||
}
|
||||
setOpenMenu(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<nav className="barNavigation">
|
||||
<div className="menuToggle" onClick={toggleMenu}>
|
||||
<div></div>
|
||||
<div></div>
|
||||
<div></div>
|
||||
</div>
|
||||
|
||||
<ul className={openMenu ? "active" : ""}>
|
||||
<li className="subMenu" onClick={toggleMenu}>
|
||||
<Link href="/crearCuenta" className="links">
|
||||
<span>Crear Cuenta</span>
|
||||
</Link>
|
||||
</li>
|
||||
<li className="subMenu" onClick={toggleMenu}>
|
||||
<Link href="/CambiarPass" className="links">
|
||||
<span>Cambiar Contraseña</span>
|
||||
</Link>
|
||||
</li>
|
||||
<li className="subMenu" onClick={toggleMenu}>
|
||||
<Link href="/reporte" className="links">
|
||||
<span>Reporte</span>
|
||||
</Link>
|
||||
</li>
|
||||
<li className="subMenu">
|
||||
<button className="logout-button" onClick={cerrarSesion}>
|
||||
Cerrar sesión
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
|
||||
export default BarNavigation;
|
||||
//IO
|
||||
@@ -3,6 +3,7 @@ import Image from "next/image";
|
||||
import header from "../app/styles/layout/header.module.scss";
|
||||
import Link from "next/link";
|
||||
import BarNavigation from "./BarNavigation";
|
||||
import BarNavigationAdmin from "./BarNavigationAdmin";
|
||||
import { usePathname } from "next/navigation";
|
||||
|
||||
function Header() {
|
||||
@@ -42,7 +43,7 @@ function Header() {
|
||||
}}
|
||||
>
|
||||
{publicNav.includes(pathname) && <BarNavigation />}
|
||||
{privateNav.includes(pathname) && <BarNavigation />}
|
||||
{privateNav.includes(pathname) && <BarNavigationAdmin />}
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user