1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +07:00

#58 made dialogs as routes

This commit is contained in:
Fedor Katurov 2021-03-29 14:11:39 +07:00
parent d9af895558
commit 4dc8bea040
21 changed files with 230 additions and 172 deletions

View file

@ -0,0 +1,38 @@
import React, { FC, useCallback, useMemo, useRef } from 'react';
import { EMPTY_NODE, NODE_TYPES } from '~/redux/node/constants';
import { EditorDialog } from '~/containers/dialogs/EditorDialog';
import { useHistory, useRouteMatch } from 'react-router';
import { values } from 'ramda';
import { ModalWrapper } from '~/components/dialogs/ModalWrapper';
const EditorCreateDialog: FC = () => {
const history = useHistory();
const {
params: { type },
url,
} = useRouteMatch<{ type: string }>();
const backUrl = useMemo(() => {
return url.replace(/\/create\/(.*)$/, '');
}, [url]);
const goBack = useCallback(() => {
history.replace(backUrl);
}, [backUrl, history]);
const isExist = useMemo(() => values(NODE_TYPES).some(el => el === type), [type]);
const data = useRef({ ...EMPTY_NODE, type });
if (!type || !isExist) {
return null;
}
return (
<ModalWrapper onOverlayClick={goBack}>
<EditorDialog node={data.current} onRequestClose={goBack} />
</ModalWrapper>
);
};
export { EditorCreateDialog };