Skip to content

Commit

Permalink
#102 update behavior RouteModal
Browse files Browse the repository at this point in the history
  • Loading branch information
artzub committed May 30, 2023
1 parent 6a5a973 commit 02de63b
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/shared/components/RouteModal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import useEventCallback from '@mui/material/utils/useEventCallback';
import Modal from '@/shared/components/Modal';

const RouteModal = (props) => {
const { path, ...tail } = props;
const { parent, onClose, ...tail } = props;

const location = useLocation();

Expand All @@ -20,34 +20,42 @@ const RouteModal = (props) => {
const navType = useNavigationType();

const navigate = useNavigate();
const { pathname } = useResolvedPath(path);
const parent = useResolvedPath(`${path}/..`);
const { pathname } = useResolvedPath('.');
const { pathname: parentPathname } = useResolvedPath(parent || './..');

const onClose = useEventCallback((event, reason) => {
const doClose = useEventCallback((event, reason) => {
if (reason !== 'closeButton') {
return;
}

if (navType !== 'REPLACE' && location.key !== 'default') {
if (!(from || navType === 'REPLACE' || location.key === 'default')) {
navigate(-1);
return;
}

navigate(from || parent.pathname, { replace: true });
navigate(from || parentPathname, { replace: true });

onClose?.(event, reason);
});

return (
<Modal
isOpen
isCloseShown={pathname === location.pathname}
onClose={onClose}
{...tail}
onClose={doClose}
/>
);
};

RouteModal.propTypes = {
path: PropTypes.string.isRequired,
parent: PropTypes.string,
onClose: PropTypes.func,
};

RouteModal.defaultProps = {
parent: null,
onClose: null,
};

export default RouteModal;

0 comments on commit 02de63b

Please sign in to comment.