Add src/app/login/page.tsx

This commit is contained in:
2026-03-05 23:54:27 +00:00
parent 20cd4d67a5
commit 50ff3c7c75

121
src/app/login/page.tsx Normal file
View File

@@ -0,0 +1,121 @@
"use client";
import { useState } from "react";
import { useRouter } from "next/navigation";
export default function LoginPage() {
const router = useRouter();
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [error, setError] = useState("");
const [isLoading, setIsLoading] = useState(false);
const handleLogin = async (e: React.FormEvent) => {
e.preventDefault();
setError("");
setIsLoading(true);
try {
// Simulate login API call
if (!email || !password) {
setError("Please enter both email and password.");
return;
}
// Here you would typically make an API call to authenticate
// For now, we'll simulate a successful login
console.log("Login attempt:", { email, password });
// Simulate successful login
localStorage.setItem("user_email", email);
router.push("/dashboard");
} catch (err) {
setError("Login failed. Please try again.");
console.error(err);
} finally {
setIsLoading(false);
}
};
const handleRegister = () => {
router.push("/#contact");
};
return (
<div className="min-h-screen flex items-center justify-center bg-gradient-to-br from-blue-50 to-indigo-100 p-4">
<div className="w-full max-w-md">
<div className="bg-white rounded-lg shadow-lg p-8">
<h1 className="text-3xl font-bold text-center mb-2 text-gray-800">
Learn German
</h1>
<p className="text-center text-gray-600 mb-8">Login to your account</p>
<form onSubmit={handleLogin} className="space-y-4">
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
Email
</label>
<input
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="Enter your email"
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent outline-none transition"
disabled={isLoading}
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
Password
</label>
<input
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="Enter your password"
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent outline-none transition"
disabled={isLoading}
/>
</div>
{error && (
<div className="bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-lg text-sm">
{error}
</div>
)}
<button
type="submit"
disabled={isLoading}
className="w-full bg-blue-600 hover:bg-blue-700 text-white font-semibold py-2 px-4 rounded-lg transition disabled:opacity-50 disabled:cursor-not-allowed"
>
{isLoading ? "Logging in..." : "Login"}
</button>
</form>
<div className="mt-6 text-center">
<p className="text-gray-600 text-sm">
Don't have an account?{" "}
<button
onClick={handleRegister}
className="text-blue-600 hover:text-blue-700 font-semibold"
>
Register here
</button>
</p>
</div>
<div className="mt-6 text-center">
<button
onClick={() => router.push("/")}
className="text-gray-600 hover:text-gray-700 text-sm"
>
Back to Home
</button>
</div>
</div>
</div>
</div>
);
}