import { CrossIcon } from "@/assets/icons"; import { useIsMutating } from "@tanstack/react-query"; import { ReactNode, useEffect, useState } from "react"; import { createPortal } from "react-dom"; import IsVisible from "./IsVisible"; interface ModalProps { isOpen: boolean; onClose: () => void; onConfirm?: () => void; children: ReactNode; confirmText?: string; cancelText?: string; showButtons?: boolean; classNames?: string; } const Modal: React.FC = ({ isOpen, onClose, children, onConfirm, confirmText = "confirm", cancelText = "close", showButtons = true, classNames, }) => { const [mounted, setMounted] = useState(false); const isMutating = useIsMutating(); useEffect(() => { setMounted(true); }, []); useEffect(() => { if (isOpen) { if (document) document.body.style.overflow = "hidden"; } else { if (document) document.body.style.overflow = "unset"; } return () => { if (document) document.body.style.overflow = "unset"; }; }, [isOpen]); if (!mounted || !isOpen) return null; const modalContent = (
e.stopPropagation()} >
{children}
); return createPortal(modalContent, document.body); }; export default Modal;