import React, { useState } from 'react'; import { useAuth } from '../../context/AuthContext.tsx'; import { errorMessage } from '../../services/apiClient.ts'; const LoginForm: React.FC = () => { const { login } = useAuth(); const [userLogin, setUserLogin] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setIsLoading(true); try { await login(userLogin, password); } catch (err) { setError(errorMessage(err)); } finally { setIsLoading(false); } }; return (
void handleSubmit(e)} className="space-y-6"> {error && (
{error}
)}
setUserLogin(e.target.value)} className="appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-red-500 focus:border-red-500 sm:text-sm" placeholder="Login pengguna" />
setPassword(e.target.value)} className="appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-red-500 focus:border-red-500 sm:text-sm" />
); }; export default LoginForm;