diff --git a/src/app/(Administrador)/crearCuenta/page.tsx b/src/app/(Administrador)/crearCuenta/page.tsx new file mode 100644 index 0000000..5cd4415 --- /dev/null +++ b/src/app/(Administrador)/crearCuenta/page.tsx @@ -0,0 +1,124 @@ +"use client"; + +import { useState } from "react"; +import "../styles/layout/login.scss"; // puedes usar los mismos estilos +import "../styles/base/globales.scss"; + +import Link from "next/link"; +import axios from "axios"; +import { useRouter } from "next/navigation"; +import toast from "react-hot-toast"; + +function CrearCuenta() { + const [nombre, setNombre] = useState(""); + const [correo, setCorreo] = useState(""); + const [password, setPassword] = useState(""); + const [confirmarPassword, setConfirmarPassword] = useState(""); + const [loading, setLoading] = useState(false); + + const router = useRouter(); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + + if (password !== confirmarPassword) { + toast.error("Las contraseñas no coinciden"); + return; + } + + setLoading(true); + + try { + const response = await axios.post( + `${process.env.NEXT_PUBLIC_API_URL}/auth/register`, + { + nombre, + correo, + contraseña: password, + } + ); + + toast.success("Cuenta creada correctamente"); + router.push("/"); // redirige al login + } catch (err: unknown) { + if (axios.isAxiosError(err)) { + if (err.response) { + toast.error( + err.response.data?.message || "Error al crear la cuenta" + ); + } else if (err.request) { + toast.error("No se pudo conectar con el servidor"); + } else { + toast.error("Ocurrió un error inesperado"); + } + } else { + toast.error("Ocurrió un error inesperado"); + } + } finally { + setLoading(false); + } + + }; + + return ( +
+
+

Crear cuenta

+
+
+ + setNombre(e.target.value)} + required + /> +
+ +
+ + setCorreo(e.target.value)} + required + /> +
+ +
+ + setPassword(e.target.value)} + required + /> +
+ +
+ + setConfirmarPassword(e.target.value)} + required + /> +
+ + + + ¿Ya tienes cuenta? Inicia sesión +
+
+ + +
+ ); +} +export default CrearCuenta; \ No newline at end of file diff --git a/src/app/(Administrador)/forgotPassword/page.tsx b/src/app/(Administrador)/forgotPassword/page.tsx new file mode 100644 index 0000000..98e3cf1 --- /dev/null +++ b/src/app/(Administrador)/forgotPassword/page.tsx @@ -0,0 +1,80 @@ +"use client"; + +import { useState } from "react"; +import axios from "axios"; +import { useRouter } from "next/navigation"; +import toast from "react-hot-toast"; +import "../styles/base/globales.scss"; // ajusta ruta si tu proyecto la tiene en otro sitio + +export default function ForgotPasswordPage() { + const [email, setEmail] = 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) => { + ev.preventDefault(); + if (!validateEmail(email)) { + toast.error("Ingresa un correo válido."); + return; + } + + try { + setLoading(true); + const res = await axios.post("/api/auth/forgot-password", { email }); + 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); + } else { + toast.error("Ocurrió un error. Intenta de nuevo."); + } + } catch (error:any ) { + // manejar mensajes de error desde el servidor si vienen + const msg = error?.response?.data?.message ?? "Error al enviar el correo."; + toast.error(msg); + } finally { + setLoading(false); + } + }; + + return ( +
+

¿Olvidaste tu contraseña?

+

Escribe el correo asociado a tu cuenta y te enviaremos instrucciones para restablecerla.

+ +
+ + setEmail(e.target.value)} + placeholder="tu@correo.com" + required + style={{ padding: "0.6rem", borderRadius: 8, border: "1px solid #ccc" }} + /> + + + +
+ Recordé mi contraseña — Iniciar sesión +
+
+
+ ); +} diff --git a/src/app/login/Login.tsx b/src/app/login/Login.tsx index f96ae52..a87dc51 100644 --- a/src/app/login/Login.tsx +++ b/src/app/login/Login.tsx @@ -73,8 +73,9 @@ export default function Login() { /> - Olvidaste Contraseña? - Crear Cuenta + + {/* Olvidaste Contraseña? */} + {/* Crear Cuenta */} @@ -121,7 +122,7 @@ export default function Login() {