"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; export default function AdminLoginPage() { const router = useRouter(); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(""); try { const res = await fetch("/api/admin/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ username, password }), }); const data = await res.json(); if (!res.ok) { throw new Error(data.error || "Најавата не успеа"); } router.push("/admin/dashboard"); } catch (err) { setError(err instanceof Error ? err.message : "Најавата не успеа"); } finally { setLoading(false); } }; return (

Администрација

setUsername(e.target.value)} className="mt-1 block w-full rounded-lg border border-stone-200 px-3 py-2.5 text-stone-900 placeholder:text-stone-400 focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary" autoComplete="username" />
setPassword(e.target.value)} className="mt-1 block w-full rounded-lg border border-stone-200 px-3 py-2.5 text-stone-900 placeholder:text-stone-400 focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary" autoComplete="current-password" />
{error &&

{error}

}
); }