"use client" import { useState } from "react" import Link from "next/link" import { useRouter } from "next/navigation" import { Pencil, Trash2 } from "lucide-react" import { toast } from "sonner" interface UnitActionsProps { propertyId: string unitId: string unitNumber: string } export function UnitActions({ propertyId, unitId, unitNumber }: UnitActionsProps) { const router = useRouter() const [confirming, setConfirming] = useState(false) const [loading, setLoading] = useState(false) async function handleDelete() { setLoading(true) try { const res = await fetch(`/api/units/${unitId}`, { method: "DELETE" }) if (!res.ok) { const data = await res.json().catch(() => null) toast.error(data?.error ?? "Failed to delete unit") return } toast.success(`Unit ${unitNumber} deleted`) router.refresh() } catch { toast.error("Network error — please try again") } finally { setLoading(false) setConfirming(false) } } if (confirming) { return (
Delete?
) } return (
) }