43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
'use client';
|
|
|
|
import { useState } from 'react';
|
|
import { Trash2 } from 'lucide-react';
|
|
import { deleteDocumentServer } from '@/app/actions/appwrite';
|
|
|
|
export const DeleteButton = ({
|
|
collectionId,
|
|
documentId,
|
|
entityAlias
|
|
}: {
|
|
collectionId: string,
|
|
documentId: string,
|
|
entityAlias: string
|
|
}) => {
|
|
const [isDeleting, setIsDeleting] = useState(false);
|
|
|
|
const handleDelete = async () => {
|
|
if (!window.confirm("¿Estás seguro de que deseas eliminar este registro? Esta acción es irreversible.")) {
|
|
return;
|
|
}
|
|
|
|
setIsDeleting(true);
|
|
const res = await deleteDocumentServer(collectionId, documentId, entityAlias);
|
|
setIsDeleting(false);
|
|
|
|
if (!res.success) {
|
|
alert(res.error || "Hubo un error al eliminar el registro.");
|
|
}
|
|
};
|
|
|
|
return (
|
|
<button
|
|
onClick={handleDelete}
|
|
disabled={isDeleting}
|
|
className="p-2 text-slate-400 hover:text-red-500 hover:bg-red-500/10 rounded-lg transition-colors disabled:opacity-50 inline-flex items-center justify-center border border-transparent hover:border-red-500/20"
|
|
title="Eliminar Registro"
|
|
>
|
|
<Trash2 size={16} className={isDeleting ? "animate-pulse" : ""} />
|
|
</button>
|
|
);
|
|
};
|