mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +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:
parent
832386d39a
commit
c2d1c2bfc9
35 changed files with 366 additions and 413 deletions
|
@ -5,7 +5,8 @@ import { ModalWrapper } from '~/components/dialogs/ModalWrapper';
|
|||
import { LoaderCircle } from '~/components/input/LoaderCircle';
|
||||
import styles from './styles.module.scss';
|
||||
import { useGetNode } from '~/utils/hooks/data/useGetNode';
|
||||
import { EMPTY_NODE } from '~/redux/node/constants';
|
||||
import { useUpdateNode } from '~/utils/hooks/data/useUpdateNode';
|
||||
import { INode } from '~/redux/types';
|
||||
|
||||
const EditorEditDialog: FC = () => {
|
||||
const history = useHistory();
|
||||
|
@ -24,6 +25,15 @@ const EditorEditDialog: FC = () => {
|
|||
}, [backUrl, history]);
|
||||
|
||||
const { node, isLoading } = useGetNode(parseInt(id, 10));
|
||||
const updateNode = useUpdateNode(parseInt(id, 10));
|
||||
|
||||
const onSubmit = useCallback(
|
||||
async (node: INode) => {
|
||||
await updateNode(node);
|
||||
goBack();
|
||||
},
|
||||
[updateNode, goBack]
|
||||
);
|
||||
|
||||
if (isLoading || !node) {
|
||||
return (
|
||||
|
@ -35,7 +45,7 @@ const EditorEditDialog: FC = () => {
|
|||
);
|
||||
}
|
||||
|
||||
return <EditorDialog node={node || EMPTY_NODE} onRequestClose={goBack} />;
|
||||
return <EditorDialog node={node} onRequestClose={goBack} onSubmit={onSubmit} />;
|
||||
};
|
||||
|
||||
export { EditorEditDialog };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue