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

99 use swr (#100)

* 99: made node use SWR

* 99: fixed comments for SWR node

* 99: added error toast to useNodeFormFormik.ts
This commit is contained in:
muerwre 2022-01-02 17:10:21 +07:00 committed by GitHub
parent 832386d39a
commit c2d1c2bfc9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 366 additions and 413 deletions

View file

@ -3,6 +3,10 @@ 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 { INode } from '~/redux/types';
import { apiPostNode } from '~/redux/node/api';
import { useUpdateNode } from '~/utils/hooks/data/useUpdateNode';
import { useCreateNode } from '~/utils/hooks/data/useCreateNode';
const EditorCreateDialog: FC = () => {
const history = useHistory();
@ -25,11 +29,21 @@ const EditorCreateDialog: FC = () => {
const data = useRef({ ...EMPTY_NODE, type, is_promoted: !isInLab });
const createNode = useCreateNode();
const onSubmit = useCallback(
async (node: INode) => {
await createNode(node);
goBack();
},
[goBack, createNode]
);
if (!type || !isExist) {
return null;
}
return <EditorDialog node={data.current} onRequestClose={goBack} />;
return <EditorDialog node={data.current} onRequestClose={goBack} onSubmit={onSubmit} />;
};
export { EditorCreateDialog };