"use client" import { useState } from "react" import { Plus, CheckCircle } from "lucide-react" import { Select } from "@/components/ui/select" const CATEGORIES = [ { value: "plumbing", label: "Plumbing" }, { value: "electrical", label: "Electrical" }, { value: "hvac", label: "HVAC" }, { value: "appliance", label: "Appliance" }, { value: "structural", label: "Structural" }, { value: "pest", label: "Pest" }, { value: "general", label: "General" }, ] interface Props { tenantId: string propertyId: string unitId: string | null portalToken: string } export function TenantMaintenanceForm({ tenantId, propertyId, unitId, portalToken }: Props) { const [open, setOpen] = useState(false) const [loading, setLoading] = useState(false) const [done, setDone] = useState(false) const [error, setError] = useState("") const cls = "w-full rounded-lg border border-white/10 bg-white/5 px-4 py-2.5 text-sm text-white placeholder-white/30 outline-none ring-indigo-500 transition focus:border-indigo-500/50 focus:ring-1" async function handleSubmit(e: React.FormEvent) { e.preventDefault() setLoading(true) setError("") const fd = new FormData(e.currentTarget) const res = await fetch("/api/maintenance", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ title: fd.get("title"), description: fd.get("description"), category: fd.get("category"), priority: "medium", property_id: propertyId, unit_id: unitId ?? undefined, tenant_id: tenantId, portal_token: portalToken, // verified server-side — no user_id from client }), }) const data = await res.json() setLoading(false) if (!res.ok) { setError(typeof data.error === "string" ? data.error : "Something went wrong") return } setDone(true) setOpen(false) } if (done) { return (
Request submitted! Your landlord will be in touch.
) } if (!open) { return ( ) } return (

New Maintenance Request

{error &&

{error}

}