Files
hr-assessment-system/app/login/page.tsx
2025-09-25 12:30:25 +08:00

130 lines
4.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client"
import type React from "react"
import { useState } from "react"
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { Alert, AlertDescription } from "@/components/ui/alert"
import { Users, Eye, EyeOff } from "lucide-react"
import Link from "next/link"
import { useRouter } from "next/navigation"
import { useAuth } from "@/lib/hooks/use-auth"
export default function LoginPage() {
const [email, setEmail] = useState("")
const [password, setPassword] = useState("")
const [showPassword, setShowPassword] = useState(false)
const [error, setError] = useState("")
const [isLoading, setIsLoading] = useState(false)
const router = useRouter()
const { login } = useAuth()
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault()
setError("")
setIsLoading(true)
try {
const success = await login(email, password)
if (success) {
router.push("/dashboard")
} else {
setError("帳號或密碼錯誤")
}
} catch (err) {
setError("登入失敗,請稍後再試")
} finally {
setIsLoading(false)
}
}
return (
<div className="min-h-screen bg-background flex items-center justify-center p-4">
<div className="w-full max-w-md">
<div className="text-center mb-8">
<div className="w-16 h-16 bg-primary rounded-lg flex items-center justify-center mx-auto mb-4">
<Users className="w-8 h-8 text-primary-foreground" />
</div>
<h1 className="text-2xl font-bold text-foreground">HR </h1>
<p className="text-muted-foreground"></p>
</div>
<Card>
<CardHeader>
<CardTitle></CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<CardContent>
<form onSubmit={handleSubmit} className="space-y-4">
<div className="space-y-2">
<Label htmlFor="email"></Label>
<Input
id="email"
type="email"
placeholder="請輸入電子郵件"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
/>
</div>
<div className="space-y-2">
<Label htmlFor="password"></Label>
<div className="relative">
<Input
id="password"
type={showPassword ? "text" : "password"}
placeholder="請輸入密碼"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
/>
<Button
type="button"
variant="ghost"
size="sm"
className="absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent"
onClick={() => setShowPassword(!showPassword)}
>
{showPassword ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
</Button>
</div>
</div>
{error && (
<Alert variant="destructive">
<AlertDescription>{error}</AlertDescription>
</Alert>
)}
<Button type="submit" className="w-full" disabled={isLoading}>
{isLoading ? "登入中..." : "登入"}
</Button>
</form>
<div className="mt-6 text-center">
<p className="text-sm text-muted-foreground">
{" "}
<Link href="/register" className="text-primary hover:underline">
</Link>
</p>
</div>
<div className="mt-4 p-4 bg-muted/50 rounded-lg">
<p className="text-sm font-medium mb-2"></p>
<div className="text-xs text-muted-foreground space-y-1">
<p>admin@company.com / admin123</p>
<p>user@company.com / user123</p>
</div>
</div>
</CardContent>
</Card>
</div>
</div>
)
}