diff --git a/web/src/components/ConfirmModal.jsx b/web/src/components/ConfirmModal.jsx new file mode 100644 index 0000000..a24fb4c --- /dev/null +++ b/web/src/components/ConfirmModal.jsx @@ -0,0 +1,50 @@ +import React from 'react'; +import { FaTrash, FaTimesCircle } from 'react-icons/fa'; // Icons + +export default function ConfirmModal({ message, onConfirm, onCancel, isOpen, isDeleting }) { + + // ใช้ open={isOpen} ใน เพื่อควบคุมการแสดงผล + if (!isOpen) return null; + + return ( + // Div ครอบคลุมจอทั้งหมด (Backdrop) +
+ +
+ + {/* Header/Title */} +

+ + ยืนยันการลบข้อมูล +

+ + {/* Message Body */} +

{message}

+ + {/* Action Buttons */} +
+ {/* ปุ่มยกเลิก */} + + + {/* ปุ่มยืนยันการลบ */} + +
+
+
+
+ ); +} \ No newline at end of file diff --git a/web/src/pages/data/ModelRegistry.jsx b/web/src/pages/data/ModelRegistry.jsx index a8ad2dc..12a5de5 100644 --- a/web/src/pages/data/ModelRegistry.jsx +++ b/web/src/pages/data/ModelRegistry.jsx @@ -12,7 +12,7 @@ import { } from '../../services/modelRegistryApi'; import ModelTable from '../../components/ModelRegistry/ModelTable'; import ModelTopBar from '../../components/ModelRegistry/ModelTopBar'; - +import ConfirmModal from '../../components/ConfirmModal'; function ModelRegistry() { const [isOpen, setIsOpen] = useState(false); @@ -20,6 +20,10 @@ function ModelRegistry() { const [selectedModel, setSelectedModel] = useState(null); const [searchTerm, setSearchTerm] = useState(''); // State สำหรับ Search + // State สำหรับ Confirm Modal + const [isConfirmOpen, setIsConfirmOpen] = useState(false); + const [modelToDelete, setModelToDelete] = useState(null); + // TanStack Query Hooks const { data: models, isLoading, isError } = useModelList(); const deleteMutation = useDeleteModel(); @@ -51,6 +55,26 @@ function ModelRegistry() { } }; + // ---------------------------------------------------- + // Logic การลบ (ใช้ Custom Confirmation) + // ---------------------------------------------------- + + // Handler สำหรับเปิด Custom Confirmation Modal + const handleConfirmDelete = (modelId) => { + setModelToDelete(modelId); // เก็บ ID ที่จะลบไว้ใน State + setIsConfirmOpen(true); // เปิด Custom Modal + }; + + // Handler ที่รันเมื่อผู้ใช้ยืนยันการลบใน Custom Modal + const executeDelete = () => { + if (modelToDelete) { + deleteMutation.mutate(modelToDelete); // รัน Mutation จริง + } + // ปิด Modal และเคลียร์ State เสมอ + setIsConfirmOpen(false); + setModelToDelete(null); + }; + // ---------------------------------------------------- // Logic การกรองข้อมูล (Filter/Search) // ---------------------------------------------------- @@ -78,7 +102,7 @@ function ModelRegistry() { handleOpen('edit', model)} - handleDelete={handleDelete} + handleDelete={handleConfirmDelete} deleteLoading={deleteMutation.isPending} // ส่ง Hook ไปให้ Component ย่อยใช้งาน @@ -97,6 +121,14 @@ function ModelRegistry() { model={selectedModel} isSubmitting={isSubmitting} /> + {/* Confirm Modal Component (ใช้แทน window.confirm) */} + setIsConfirmOpen(false)} + isDeleting={deleteMutation.isPending} // ส่งสถานะ Loading ไปให้ Modal + /> ); }