import { useTranslation } from "react-i18next"; import Icon from "../Icon"; import { generateDialog } from "./BaseDialog"; import "@/less/common-dialog.less"; type DialogStyle = "info" | "warning"; interface Props extends DialogProps { title: string; content: string; style?: DialogStyle; closeBtnText?: string; confirmBtnText?: string; onClose?: () => void; onConfirm?: () => void; } const defaultProps = { title: "", content: "", style: "info", closeBtnText: "common.close", confirmBtnText: "common.confirm", onClose: () => null, onConfirm: () => null, }; const CommonDialog: React.FC = (props: Props) => { const { t } = useTranslation(); const { title, content, destroy, closeBtnText, confirmBtnText, onClose, onConfirm, style } = { ...defaultProps, closeBtnText: t(defaultProps.closeBtnText), confirmBtnText: t(defaultProps.confirmBtnText), ...props, }; const handleCloseBtnClick = () => { onClose(); destroy(); }; const handleConfirmBtnClick = async () => { onConfirm(); destroy(); }; return ( <>

{title}

{content}

{closeBtnText} {confirmBtnText}
); }; interface CommonDialogProps { title: string; content: string; className?: string; style?: DialogStyle; dialogName: string; closeBtnText?: string; confirmBtnText?: string; onClose?: () => void; onConfirm?: () => void; } export const showCommonDialog = (props: CommonDialogProps) => { generateDialog( { className: `common-dialog ${props?.className ?? ""}`, dialogName: `common-dialog ${props?.className ?? ""}`, }, CommonDialog, props ); };