feat: login page component

This commit is contained in:
Ken
2026-05-26 19:17:16 +00:00
parent c24fd035eb
commit 77fe2bafd4
2 changed files with 173 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
import { useState, FormEvent } from 'react'
interface LoginPageProps {
onLogin: (email: string, password: string) => Promise<void>
}
export function LoginPage({ onLogin }: LoginPageProps) {
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const [error, setError] = useState('')
const [loading, setLoading] = useState(false)
async function handleSubmit(e: FormEvent) {
e.preventDefault()
setError('')
setLoading(true)
try {
await onLogin(email, password)
} catch {
setError('Invalid credentials')
} finally {
setLoading(false)
}
}
return (
<div className="login-page">
<form className="login-card" onSubmit={handleSubmit}>
<h2>Research Workbench</h2>
{error && <div className="login-error">{error}</div>}
<label htmlFor="email">Email</label>
<input
id="email"
type="email"
value={email}
onChange={e => setEmail(e.target.value)}
autoFocus
required
/>
<label htmlFor="password">Password</label>
<input
id="password"
type="password"
value={password}
onChange={e => setPassword(e.target.value)}
required
/>
<button type="submit" disabled={loading}>
{loading ? 'Signing in...' : 'Sign In'}
</button>
</form>
</div>
)
}