Files
property-management-network/components/forms/unit-actions.tsx
Leon SerfatyandClaude Opus 4.8 c9968531e4 Consolidate audit-fixes branch: webhooks, integrations, and deploy hardening
Batch commit of the pending working tree on security/audit-fixes-2026-07.
Major areas:
- Outbound webhooks / Zapier: schema + signed delivery with retries, public
  v1 API (REST-hook subscribe/unsubscribe), settings UI, cron drain.
- Deploy hardening: email via SMTP2GO (Resend fully removed), verified DB TLS
  (DATABASE_SSL=require + DATABASE_CA), storage fails loud in production when
  Spaces is unconfigured instead of silently using ephemeral disk.
- Integrations & features (concurrent work): accounting (QuickBooks/Xero),
  e-signature (DocuSign/Dropbox Sign), PayPal, geocoding/maps, onboarding,
  expanded legal pages.
- DB migrations 0006–0009.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 13:42:34 -04:00

80 lines
2.4 KiB
TypeScript

"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 (
<div className="flex items-center gap-2">
<span className="text-xs text-white/50">Delete?</span>
<button
onClick={handleDelete}
disabled={loading}
className="rounded-lg bg-red-600 px-2.5 py-1.5 text-xs font-medium text-white hover:bg-red-500 disabled:opacity-50 transition"
>
{loading ? "Deleting…" : "Yes"}
</button>
<button
onClick={() => setConfirming(false)}
disabled={loading}
className="rounded-lg border border-white/10 px-2.5 py-1.5 text-xs text-white/60 hover:text-white transition"
>
Cancel
</button>
</div>
)
}
return (
<div className="flex items-center gap-1">
<Link
href={`/properties/${propertyId}/units/${unitId}/edit`}
className="rounded-lg border border-white/10 p-1.5 text-white/40 hover:border-white/20 hover:text-white transition"
title="Edit unit"
>
<Pencil className="h-3.5 w-3.5" />
</Link>
<button
onClick={() => setConfirming(true)}
className="rounded-lg border border-red-500/20 p-1.5 text-red-400/80 hover:border-red-500/40 hover:text-red-400 hover:bg-red-500/5 transition"
title="Delete unit"
>
<Trash2 className="h-3.5 w-3.5" />
</button>
</div>
)
}