"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; type Props = { brandId: string }; export default function WaterAdminPinClient({ brandId }: Props) { const router = useRouter(); const [pin, setPin] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); if (pin.length !== 4) return; setLoading(true); setError(""); try { const res = await fetch("/api/water-admin-auth", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ brandId, pin }), }); const data = await res.json(); if (data.success) { router.push("/water/admin"); } else { setError(data.error ?? "Invalid PIN"); setPin(""); } } catch { setError("Connection error"); } setLoading(false); } return (
setPin(e.target.value.replace(/\D/g, "").slice(0, 4))} placeholder="••••" className="w-full rounded-xl border-2 border-slate-300 px-6 py-6 text-center text-4xl font-bold tracking-widest outline-none focus:border-slate-900" style={{ letterSpacing: "0.4em" }} /> {error && (

{error}

)}
); }