Property Management Network — Next.js 16 (App Router), Better Auth, Drizzle ORM over PostgreSQL, Stripe, OpenAI, Resend. Includes: - Security hardening: access-control/IDOR fixes, TLS-by-default DB layer, constant-time cron auth, strict security headers, atomic AI quota gating, HTML/email output encoding, demo-backdoor disabled in production. - Superadmin dashboard at /admin (overview/MRR, server-paginated users with ban/impersonate/plan/delete, billing, platform activity + admin audit log, AI usage, system health) via the Better Auth admin plugin. - Seed/migration utility scripts under scripts/. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
63 lines
1.6 KiB
TypeScript
63 lines
1.6 KiB
TypeScript
"use client"
|
|
|
|
import { useState } from "react"
|
|
import { useRouter } from "next/navigation"
|
|
import { Trash2 } from "lucide-react"
|
|
import { ConfirmModal } from "@/components/ui/confirm-modal"
|
|
import { toast } from "sonner"
|
|
|
|
interface DeleteButtonProps {
|
|
id: string
|
|
endpoint: string
|
|
label?: string
|
|
onDeleted?: () => void
|
|
}
|
|
|
|
export function DeleteButton({ id, endpoint, label = "this item", onDeleted }: DeleteButtonProps) {
|
|
const router = useRouter()
|
|
const [open, setOpen] = useState(false)
|
|
const [loading, setLoading] = useState(false)
|
|
|
|
async function handleDelete() {
|
|
setLoading(true)
|
|
try {
|
|
const res = await fetch(`${endpoint}/${id}`, { method: "DELETE" })
|
|
if (!res.ok) {
|
|
const data = await res.json().catch(() => null)
|
|
toast.error(data?.error ?? "Failed to delete")
|
|
return
|
|
}
|
|
toast.success("Deleted successfully")
|
|
if (onDeleted) onDeleted()
|
|
else router.refresh()
|
|
} catch {
|
|
toast.error("Network error — please try again")
|
|
} finally {
|
|
setLoading(false)
|
|
setOpen(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<button
|
|
onClick={() => setOpen(true)}
|
|
className="text-white/20 hover:text-red-400 transition"
|
|
title="Delete"
|
|
>
|
|
<Trash2 className="h-3.5 w-3.5" />
|
|
</button>
|
|
|
|
<ConfirmModal
|
|
open={open}
|
|
title="Delete item?"
|
|
description={`Are you sure you want to delete ${label}? This cannot be undone.`}
|
|
confirmLabel="Delete"
|
|
loading={loading}
|
|
onConfirm={handleDelete}
|
|
onCancel={() => setOpen(false)}
|
|
/>
|
|
</>
|
|
)
|
|
}
|