mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-27 05:46:41 +07:00
removed all router-modals
This commit is contained in:
parent
85d20e5009
commit
ffce400398
15 changed files with 99 additions and 143 deletions
|
@ -1,30 +1,19 @@
|
|||
import React, { FC, useCallback, useMemo, useRef } from 'react';
|
||||
import { EMPTY_NODE, NODE_TYPES } from '~/constants/node';
|
||||
import { EditorDialog } from '~/containers/dialogs/EditorDialog';
|
||||
import { useHistory, useRouteMatch } from 'react-router';
|
||||
import { values } from 'ramda';
|
||||
import { INode } from '~/types';
|
||||
import { useCreateNode } from '~/hooks/node/useCreateNode';
|
||||
import { DialogComponentProps } from '~/types/modal';
|
||||
|
||||
const EditorCreateDialog: FC = () => {
|
||||
const history = useHistory();
|
||||
const {
|
||||
params: { type },
|
||||
url,
|
||||
} = useRouteMatch<{ type: string }>();
|
||||
|
||||
const backUrl = useMemo(() => {
|
||||
return (url && url.replace(/\/create\/(.*)$/, '')) || '/';
|
||||
}, [url]);
|
||||
|
||||
const goBack = useCallback(() => {
|
||||
history.replace(backUrl);
|
||||
}, [backUrl, history]);
|
||||
export interface EditorCreateDialogProps extends DialogComponentProps {
|
||||
type: typeof NODE_TYPES[keyof typeof NODE_TYPES];
|
||||
isInLab: boolean;
|
||||
}
|
||||
|
||||
const EditorCreateDialog: FC<EditorCreateDialogProps> = ({ type, isInLab, onRequestClose }) => {
|
||||
const isExist = useMemo(() => values(NODE_TYPES).some(el => el === type), [type]);
|
||||
|
||||
const isInLab = useMemo(() => !!url.match(/^\/lab/), [url]);
|
||||
|
||||
const data = useRef({ ...EMPTY_NODE, type, is_promoted: !isInLab });
|
||||
|
||||
const createNode = useCreateNode();
|
||||
|
@ -32,16 +21,16 @@ const EditorCreateDialog: FC = () => {
|
|||
const onSubmit = useCallback(
|
||||
async (node: INode) => {
|
||||
await createNode(node);
|
||||
goBack();
|
||||
onRequestClose();
|
||||
},
|
||||
[goBack, createNode]
|
||||
[onRequestClose, createNode]
|
||||
);
|
||||
|
||||
if (!type || !isExist) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <EditorDialog node={data.current} onRequestClose={goBack} onSubmit={onSubmit} />;
|
||||
return <EditorDialog node={data.current} onRequestClose={onRequestClose} onSubmit={onSubmit} />;
|
||||
};
|
||||
|
||||
export { EditorCreateDialog };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue