-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathLoginPage.tsx
More file actions
85 lines (73 loc) · 2.24 KB
/
LoginPage.tsx
File metadata and controls
85 lines (73 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import React, { useState } from 'react'
import { useNavigate } from 'react-router-dom'
interface ApiService {
login: (
email: string,
password: string
) => Promise<{ success: boolean; data?: unknown; error?: string }>
}
interface LoginPageProps {
apiService: ApiService
}
const LoginPage: React.FC<LoginPageProps> = ({ apiService }) => {
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const [error, setError] = useState('')
const navigate = useNavigate()
const handleLogin = async () => {
try {
setError('')
const response = await apiService.login(email, password)
if (response.success) {
navigate('/dashboard')
} else {
setError(response.error || 'Login failed')
}
} catch (err) {
setError('An error occurred during login')
console.error(err)
}
}
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault()
handleLogin()
}
return (
<div className="min-h-screen flex items-center justify-center bg-zinc-900">
<form
onSubmit={handleSubmit}
className="bg-zinc-800 p-8 rounded-lg border border-zinc-500/50"
>
<h2 className="text-2xl font-bold text-white mb-6">Login</h2>
{error && <div className="bg-red-500/20 text-red-400 p-3 rounded mb-4">{error}</div>}
<div className="mb-4">
<label className="block text-white mb-2">Email</label>
<input
type="email"
value={email}
onChange={e => setEmail(e.target.value)}
className="w-full bg-zinc-700 text-white px-4 py-2 rounded"
required
/>
</div>
<div className="mb-6">
<label className="block text-white mb-2">Password</label>
<input
type="password"
value={password}
onChange={e => setPassword(e.target.value)}
className="w-full bg-zinc-700 text-white px-4 py-2 rounded"
required
/>
</div>
<button
type="submit"
className="w-full bg-blue-600 text-white py-2 rounded hover:bg-blue-700 transition-colors"
>
Login
</button>
</form>
</div>
)
}
export default LoginPage