Files
front-AT/app/Components/Login/Login.tsx
T

82 lines
2.6 KiB
TypeScript
Raw Normal View History

2025-09-10 16:39:01 -04:00
'use client';
import { useState } from "react";
import axios from "axios";
2025-09-02 19:50:17 -04:00
import "./Login.css";
function Login() {
2025-09-10 16:39:01 -04:00
const [user, setUser] = useState("");
const [password, setPassword] = useState("");
const [message, setMessage] = useState("");
const handleLogin = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
try {
2025-09-10 19:23:18 -04:00
const response = await axios.post(`${process.env.NEXT_PUBLIC_API_URL}/user`, {
2025-09-10 16:39:01 -04:00
usuario: user,
password: password,
});
setMessage("Inicio de sesión exitoso");
console.log("Respuesta del servidor:", response.data);
} catch (error) {
setMessage("Error en inicio de sesión");
console.error("Error:", error);
}
};
2025-09-02 19:50:17 -04:00
return (
2025-09-08 19:35:24 -04:00
<section className='centerGrid containerSection'>
2025-09-02 19:50:17 -04:00
<form
className='login'
2025-09-10 16:39:01 -04:00
onSubmit={handleLogin}
2025-09-02 19:50:17 -04:00
>
2025-09-08 19:35:24 -04:00
<h2 className='title'>Inicio de sesión</h2>
2025-09-02 19:50:17 -04:00
<div className='containerInput'>
<label className='label'>Usuario</label>
<input
type='text'
2025-09-10 16:39:01 -04:00
value={user}
onChange={(e) => setUser(e.target.value)}
2025-09-02 19:50:17 -04:00
placeholder='Coloca tu usuario...'
/>
</div>
<div className='containerInput relative'>
<label className='label'>Contraseña</label>
<input
2025-09-10 16:39:01 -04:00
type='password'
value={password}
onChange={(e) => setPassword(e.target.value)}
2025-09-02 19:50:17 -04:00
placeholder='Coloca tu contraseña...'
/>
<span
2025-09-10 16:39:01 -04:00
//onClick={() => setShowPassword(!showPassword)}
//className={showPassword ? 'eyeOpen' : 'eyeClose'}
2025-09-02 19:50:17 -04:00
/>
</div>
<button
className='button buttonSearch'
style={{ maxWidth: '100%', width: '100%' }}
type='submit'
>Iniciar sesión
</button>
2025-09-10 19:23:18 -04:00
{message &&
2025-09-02 19:50:17 -04:00
<div
className={`messageBox ${message.includes('exitoso') ? 'success' : 'error'}`}
style={{ marginTop: '10px' }}
>
{message}
</div>
2025-09-10 16:39:01 -04:00
}
2025-09-10 19:23:18 -04:00
</form>
2025-09-02 19:50:17 -04:00
</section>
);
}
2025-09-10 16:39:01 -04:00
export default Login;
//IO