40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
import { Inertia } from "@inertiajs/inertia";
|
|
import React, { useState } from "react";
|
|
|
|
const DeleteButton = ({ isOpen, onClose, item, tableName }) => {
|
|
if (!isOpen || !item) return null
|
|
|
|
const handleDelete = () => {
|
|
Inertia.post(`/delete${tableName}/${item.id}`, {
|
|
onSuccess: () => {
|
|
onClose();
|
|
},
|
|
})
|
|
}
|
|
|
|
return (
|
|
<div className="modal modal-open">
|
|
<div className="modal-box">
|
|
<h2 className="font-bold text-lg text-center mb-5">
|
|
Konfirmasi Hapus Data
|
|
</h2>
|
|
<p className="text-center mb-4">
|
|
Apakah Anda yakin ingin menghapus <strong>{item.nama}</strong>?
|
|
</p>
|
|
<div className="flex justify-center gap-4">
|
|
<button onClick={handleDelete} className="btn btn-error text-white">
|
|
Hapus
|
|
</button>
|
|
<button onClick={onClose} className="btn btn-secondary text-white">
|
|
Batal
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<label className="modal-backdrop" onClick={onClose}></label>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default DeleteButton
|
|
|