"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 (
); }