kanban-app/frontend/src/pages/Login.tsx

79 lines
2.4 KiB
TypeScript
Raw Normal View History

2026-02-25 09:29:45 +00:00
import { useState } from 'react';
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-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('');
const { login: handleLogin } = useAuth();
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();
try {
await handleLogin(email, password);
} catch (err) {
// 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-25 09:29:45 +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
<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
<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
<button
type="submit"
className="w-full bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded-lg transition-colors"
>
Login
</button>
</form>
2026-02-25 09:29:45 +00:00
<p className="mt-6 text-center text-gray-400">
2026-02-27 07:53:36 +00:00
Don&apos;t have an account?
<Link to="/register" className="ml-2 text-blue-400 hover:text-blue-300">
Register
</Link>
</p>
</div>
2026-02-25 09:29:45 +00:00
);
}