"use client"; import { Suspense, useState } from "react"; import { useSearchParams } from "next/navigation"; function LoginForm() { const params = useSearchParams(); const from = params.get("from") ?? "/admin"; const [password, setPassword] = useState(""); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(null); setLoading(true); try { const res = await fetch("/api/admin/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ password }), }); if (res.ok) { window.location.href = from; } else { const data = await res.json(); setError(data.error ?? "Login failed"); } } catch { setError("Network error"); } finally { setLoading(false); } }; return (
setPassword(e.target.value)} required autoFocus className="block w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-brand-500 focus:outline-none focus:ring-1 focus:ring-brand-500" placeholder="Enter admin password" />
{error && (

{error}

)}
); } export default function LoginPage() { return (

Admin Login

Transportationer

Loading…
}>
); }