2026-02-25 09:29:45 +00:00
|
|
|
import { useState } from 'react';
|
2026-02-26 14:12:19 +00:00
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
|
import { useAuth } from '../hooks/useAuth';
|
2026-02-27 10:15:50 +00:00
|
|
|
import { useToast } from '../context/toasts/useToast';
|
2026-02-14 16:56:10 +00:00
|
|
|
|
2026-02-24 08:52:57 +00:00
|
|
|
export default function Login() {
|
2026-02-25 09:29:45 +00:00
|
|
|
const [email, setEmail] = useState('');
|
|
|
|
|
const [password, setPassword] = useState('');
|
2026-02-26 14:12:19 +00:00
|
|
|
const { login: handleLogin } = useAuth();
|
2026-02-14 16:56:10 +00:00
|
|
|
|
2026-02-27 07:53:36 +00:00
|
|
|
const { addNotification } = useToast();
|
|
|
|
|
|
2026-02-24 08:52:57 +00:00
|
|
|
const handleSubmit = async (e: React.FormEvent) => {
|
2026-02-25 09:29:45 +00:00
|
|
|
e.preventDefault();
|
2026-02-14 16:56:10 +00:00
|
|
|
try {
|
2026-02-26 14:12:19 +00:00
|
|
|
await handleLogin(email, password);
|
2026-02-14 16:56:10 +00:00
|
|
|
} catch (err) {
|
2026-02-26 14:12:19 +00:00
|
|
|
// Error is handled by the hook (toast shown)
|
2026-02-27 07:53:36 +00:00
|
|
|
const errorMessage = err instanceof Error ? err.message : 'Failed to create card';
|
|
|
|
|
addNotification({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Error Login',
|
|
|
|
|
message: errorMessage,
|
|
|
|
|
duration: 5000,
|
|
|
|
|
});
|
2026-02-14 16:56:10 +00:00
|
|
|
}
|
2026-02-25 09:29:45 +00:00
|
|
|
};
|
2026-02-14 16:56:10 +00:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="max-w-md mx-auto">
|
|
|
|
|
<h1 className="text-3xl font-bold text-white mb-8 text-center">Login</h1>
|
2026-02-25 09:29:45 +00:00
|
|
|
|
2026-02-14 16:56:10 +00:00
|
|
|
<form onSubmit={handleSubmit} className="space-y-6">
|
|
|
|
|
<div>
|
|
|
|
|
<label htmlFor="email" className="block text-sm font-medium text-gray-300 mb-2">
|
|
|
|
|
Email
|
|
|
|
|
</label>
|
|
|
|
|
<input
|
|
|
|
|
id="email"
|
|
|
|
|
type="email"
|
|
|
|
|
value={email}
|
|
|
|
|
onChange={(e) => setEmail(e.target.value)}
|
|
|
|
|
required
|
|
|
|
|
className="w-full px-4 py-2 bg-gray-800 border border-gray-700 rounded-lg text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2026-02-25 09:29:45 +00:00
|
|
|
|
2026-02-14 16:56:10 +00:00
|
|
|
<div>
|
|
|
|
|
<label htmlFor="password" className="block text-sm font-medium text-gray-300 mb-2">
|
|
|
|
|
Password
|
|
|
|
|
</label>
|
|
|
|
|
<input
|
|
|
|
|
id="password"
|
|
|
|
|
type="password"
|
|
|
|
|
value={password}
|
|
|
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
|
|
|
required
|
|
|
|
|
className="w-full px-4 py-2 bg-gray-800 border border-gray-700 rounded-lg text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2026-02-25 09:29:45 +00:00
|
|
|
|
2026-02-14 16:56:10 +00:00
|
|
|
<button
|
|
|
|
|
type="submit"
|
2026-02-26 14:12:19 +00:00
|
|
|
className="w-full bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded-lg transition-colors"
|
2026-02-14 16:56:10 +00:00
|
|
|
>
|
2026-02-26 14:12:19 +00:00
|
|
|
Login
|
2026-02-14 16:56:10 +00:00
|
|
|
</button>
|
|
|
|
|
</form>
|
2026-02-25 09:29:45 +00:00
|
|
|
|
2026-02-14 16:56:10 +00:00
|
|
|
<p className="mt-6 text-center text-gray-400">
|
2026-02-27 07:53:36 +00:00
|
|
|
Don't have an account?
|
2026-02-26 14:12:19 +00:00
|
|
|
<Link to="/register" className="ml-2 text-blue-400 hover:text-blue-300">
|
2026-02-14 16:56:10 +00:00
|
|
|
Register
|
|
|
|
|
</Link>
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
2026-02-25 09:29:45 +00:00
|
|
|
);
|
|
|
|
|
}
|