const ButtonCtl = ({ label, onClick, variant = 'primary', // primary secondary success danger warning info light dark link size = 'sm', // sm (nhỏ) | md (mặc định) | lg (lớn) disabled = false, style, // Tùy chọn style để tùy chỉnh CSS type = 'button', // Kiểu button | submit | reset visible=true, tabIndex="-1", refCtl , name, onKeyDown, className }) => { if(!visible){ return null } const { Button } =ReactBootstrap return ( ); }; function IconActionCtl(props) { const { handleAction, caption,style, className, disabled=false, visible=true,variant='', tabIndex="-1",refCtl} = props const combinedClassName = `${className} ${variant}`; if (disabled){ return( null ) } if (!visible) { return null; // Không render gì nếu không visible } const handleKeyDown = (e) => { if (e.key === 'Enter' && handleAction) { handleAction(); } }; return ( handleAction()} style={style} onKeyDown={handleKeyDown} tabIndex={tabIndex} variant={variant} ref={refCtl} > {caption} ); } const CustomAlert = ({ message, style='success', duration = 3000, onClose }) => { const [show, setShow] = useState(message?.length>0?true:false); const { Alert } =ReactBootstrap useEffect(() => { if(message?.length>0){ setShow(true) } const timer = setTimeout(() => { setShow(false); if (onClose) onClose(); }, duration); return () => clearTimeout(timer); // Dọn dẹp timer khi component unmount }, [duration, onClose, message]); if (!show) return null; return ( setShow(false)} dismissible> {message} ); }; const actionConfirm = ({ title, message, onConfirm, onCancel, confirmText, cancelText, objectId }) => { // 1. Tạo một div để render component vào const container = document.createElement('div'); document.body.appendChild(container); const root = ReactDOM.createRoot(container); // 2. Hàm dọn dẹp để unmount component và xóa div const cleanup = () => { root.unmount(); if (document.body.contains(container)) { document.body.removeChild(container); } }; // 3. Xử lý khi người dùng hủy const handleCancel = () => { if (onCancel) { onCancel(); } cleanup(); }; // 4. Xử lý khi người dùng xác nhận const handleConfirm = () => { if (onConfirm) { onConfirm(objectId); } cleanup(); }; // 5. Render component ActionConfirm // Component này sẽ tự quản lý vòng đời của nó và tự hủy sau khi hoàn thành. root.render( ); }; const ActionConfirm = ({ show, onConfirm, onCancel, message = "Are you sure?", confirmText = "Yes", cancelText = "No", objectId=null }) => { const { Modal, Button } = ReactBootstrap; return ( Confirm Action {message} ); };