From 5eba5c1ffcdaee9a81e965f0570b00dd26bb38c6 Mon Sep 17 00:00:00 2001 From: ilyayudovin Date: Thu, 29 Oct 2020 21:28:52 +0300 Subject: Wait till modal slide right on close --- src/components/ModalScreen/ModalScreen.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/components/ModalScreen') diff --git a/src/components/ModalScreen/ModalScreen.tsx b/src/components/ModalScreen/ModalScreen.tsx index 0f2c96f..61cf44a 100644 --- a/src/components/ModalScreen/ModalScreen.tsx +++ b/src/components/ModalScreen/ModalScreen.tsx @@ -20,6 +20,7 @@ interface PropTypes { actionIcon?: JSX.Element; handleAction?: () => void; isActionDisabled?: boolean; + handleCloseModal: ()=> void; } const useStyles = makeStyles(theme => ({ @@ -42,24 +43,27 @@ const Transition = React.forwardRef(( ref: React.Ref ) => ); -const ModalScreen: React.FC = ({ title, actionIcon, handleAction, isActionDisabled, children }) => { +const ModalScreen: React.FC = ({ title, actionIcon, handleAction, isActionDisabled, handleCloseModal, children }) => { const [isOpen, setIsOpen] = useState(true); const classes = useStyles(); const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down('sm')); const history = useHistory(); - const handleClose = useCallback(() => history.goBack(), [history]); + + const handleClose = useCallback(() => setIsOpen(false), [setIsOpen]); + const onExited = useCallback(handleCloseModal, [history, handleAction]); const handleClickAction = useCallback(async () => { if (handleAction) await handleAction(); - return window.location.pathname.includes('/profile') ? null : handleClose(); + return handleClose(); }, [handleAction, handleClose]); return (