import { Dialog, DialogContent, DialogTitle } from "@mui/material"; import { createRoot } from "react-dom/client"; import Icon from "./Icon"; type DialogStyle = "info" | "warning"; interface Props { title: string; content: string; style?: DialogStyle; closeBtnText?: string; confirmBtnText?: string; onClose?: () => void; onConfirm?: () => void; } const defaultProps = { title: "", content: "", style: "info", closeBtnText: "Close", confirmBtnText: "Confirm", onClose: () => null, onConfirm: () => null, }; const Alert: React.FC = (props: Props) => { const { title, content, closeBtnText, confirmBtnText, onClose, onConfirm, style } = { ...defaultProps, ...props, }; const handleCloseBtnClick = () => { onClose(); }; const handleConfirmBtnClick = async () => { onConfirm(); }; return (

{title}

{content}

); }; export const showCommonDialog = (props: Props) => { const tempDiv = document.createElement("div"); const dialog = createRoot(tempDiv); document.body.append(tempDiv); const destory = () => { dialog.unmount(); tempDiv.remove(); }; const onClose = () => { if (props.onClose) { props.onClose(); } destory(); }; const onConfirm = () => { if (props.onConfirm) { props.onConfirm(); } destory(); }; dialog.render(); };