11import { useState } from 'react' ;
22import { Link , useNavigate } from 'react-router-dom' ;
3+ import type React from 'react' ;
4+ import { Mail , Lock } from 'lucide-react' ;
35import { useAuth } from '../../hooks/useAuth' ;
46import { authService } from '../../api/services/auth.service' ;
5- import type React from 'react' ;
6- import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
7- import { faEnvelope , faLock } from '@fortawesome/free-solid-svg-icons' ;
8- import Button from '../../components/ui/Button.tsx' ;
9- import Input from '../../components/ui/Input.tsx' ;
10- import AuthCard from '../../components/layouts/AuthCard.tsx' ;
7+ import Button from '../../components/ui/Button' ;
8+ import Input from '../../components/ui/Input' ;
9+ import AuthCard from '../../components/layouts/AuthCard' ;
1110
1211const LoginPage = ( ) => {
1312 const [ credentials , setCredentials ] = useState ( { mail : '' , password : '' } ) ;
1413 const [ error , setError ] = useState < string | null > ( null ) ;
1514 const [ isLoading , setIsLoading ] = useState ( false ) ;
1615 const navigate = useNavigate ( ) ;
1716 const auth = useAuth ( ) ;
18-
1917 const handleChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
2018 setCredentials ( ( prev ) => ( { ...prev , [ e . target . name ] : e . target . value } ) ) ;
2119 } ;
22-
2320 const handleSubmit = async ( e : React . FormEvent < HTMLFormElement > ) => {
2421 e . preventDefault ( ) ;
2522 setIsLoading ( true ) ;
2623 setError ( null ) ;
27-
2824 try {
29- const payload = { mail : credentials . mail , password_plaintext : credentials . password } ;
25+ const payload = {
26+ mail : credentials . mail ,
27+ password_plaintext : credentials . password ,
28+ } ;
3029 const { user, token } = await authService . login ( payload ) ;
3130 auth . login ( user , token ) ;
3231 navigate ( '/' ) ;
3332 } catch ( err ) {
34- setError ( 'Incorrect credentials. Please try again .' ) ;
33+ setError ( 'Credenciales incorrectas. Por favor, inténtalo de nuevo .' ) ;
3534 console . error ( err ) ;
3635 } finally {
3736 setIsLoading ( false ) ;
@@ -40,61 +39,78 @@ const LoginPage = () => {
4039
4140 return (
4241 < AuthCard
43- title = 'Welcome'
44- description = 'Please enter your credentials to continue'
42+ title = "Iniciar Sesión"
43+ description = "Accede a tu cuenta para continuar aprendiendo"
4544 >
46-
47- < form onSubmit = { handleSubmit } className = "flex flex-col gap-6" >
45+ < form onSubmit = { handleSubmit } className = "space-y-6" >
4846 < Input
4947 id = "mail"
50- label = "Email "
48+ label = "Correo electrónico "
5149 name = "mail"
52- type = "mail "
53- placeholder = "your @email.com"
50+ type = "email "
51+ placeholder = "tu @email.com"
5452 value = { credentials . mail }
5553 onChange = { handleChange }
56- icon = { < FontAwesomeIcon icon = { faEnvelope } /> }
57- error = { error && error . includes ( 'mail' ) ? error : null }
54+ icon = { < Mail className = "h-5 w-5" /> }
5855 required
56+ autoComplete = "email"
5957 />
60-
6158 < Input
6259 id = "password"
63- label = "Password "
60+ label = "Contraseña "
6461 name = "password"
6562 type = "password"
66- placeholder = "•••••••• "
63+ placeholder = "Tu contraseña "
6764 value = { credentials . password }
6865 onChange = { handleChange }
69- icon = { < FontAwesomeIcon icon = { faLock } /> }
66+ icon = { < Lock className = "h-5 w-5" /> }
7067 required
68+ autoComplete = "current-password"
7169 />
72-
73- < div className = "flex items-center justify-between mt-2" >
70+ < div className = "flex items-center justify-between text-sm pt-1" >
7471 < div className = "flex items-center gap-2" >
75- < input id = "remember" name = "remember" type = "checkbox" className = "h-4 w-4 rounded accent-primary-600" />
76- < label htmlFor = "remember" className = "text-sm text-neutral-600 font-bold cursor-pointer" > Remember me</ label >
72+ < input
73+ id = "remember"
74+ name = "remember"
75+ type = "checkbox"
76+ className = "h-4 w-4 rounded border-slate-300 text-blue-500 focus:ring-blue-500"
77+ />
78+ < label htmlFor = "remember" className = "text-slate-600 cursor-pointer" >
79+ Recordarme
80+ </ label >
7781 </ div >
78- < a href = "#" className = "text-sm text-primary-600 hover:text-primary-800 hover:underline font-medium" >
79- Forgot your password?
80- </ a >
82+ < Link
83+ to = "/forgot-password"
84+ className = "font-medium text-blue-500 hover:underline"
85+ >
86+ ¿Olvidaste tu contraseña?
87+ </ Link >
8188 </ div >
8289
83- { error && < p className = "text-sm text-error mt-1" > { error } </ p > }
90+ { error && < p className = "text-sm text-red-500 text-center" > { error } </ p > }
91+
92+ < div className = "pt-6" >
93+ < Button
94+ type = "submit"
95+ isLoading = { isLoading }
96+ className = "w-full text-base py-3"
97+ >
98+ Iniciar Sesión
99+ </ Button >
100+ </ div >
84101
85- < Button type = "submit" isLoading = { isLoading } >
86- Login
87- </ Button >
88-
89- < div className = "text-center mt-2" >
90- < p className = "text-neutral-600" >
91- You don't have an account?
92- < Link to = "/register" className = "text-primary-600 hover:text-primary-800 font-medium ml-2 hover:underline" > Create one</ Link >
93- </ p >
102+ < div className = "text-center text-sm text-slate-500 pt-6" >
103+ ¿No tienes una cuenta?{ ' ' }
104+ < Link
105+ to = "/register"
106+ className = "font-semibold text-blue-500 hover:underline"
107+ >
108+ Regístrate aquí
109+ </ Link >
94110 </ div >
95111 </ form >
96112 </ AuthCard >
97113 ) ;
98114} ;
99115
100- export default LoginPage ;
116+ export default LoginPage ;
0 commit comments