import { Dispatch, MutableRefObject, ReactElement, ReactNode, SetStateAction, useCallback, useMemo, useRef, useState, } from 'react'; import ConfirmDialog from '../components/ConfirmDialog'; import MessageBox from '../components/MessageBox'; const useConfirmDialog = ( args: { initial?: Partial; } = {}, ): { confirmDialog: ReactElement; confirmDialogRef: MutableRefObject; setConfirmDialogOpen: (value: boolean) => void; setConfirmDialogProps: Dispatch>; finishConfirm: (title: ReactNode, message: Message) => void; } => { const { initial: { actionProceedText = '', closeOnProceed, content = '', titleText = '', } = {}, } = args; const confirmDialogRef = useRef( null, ); const [confirmDialogProps, setConfirmDialogProps] = useState({ actionProceedText, content, titleText, }); const setConfirmDialogOpen = useCallback( (value: boolean) => confirmDialogRef?.current?.setOpen?.call(null, value), [], ); const finishConfirm = useCallback( (title: ReactNode, message: Message) => setConfirmDialogProps({ actionProceedText: '', content: , showActionArea: false, showClose: true, titleText: title, }), [], ); const confirmDialog = useMemo( () => ( ), [closeOnProceed, confirmDialogProps], ); return { confirmDialog, confirmDialogRef, setConfirmDialogOpen, setConfirmDialogProps, finishConfirm, }; }; export default useConfirmDialog;