mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
#58 fixed dialog routers
This commit is contained in:
parent
3e8c2d4b6e
commit
124719c243
15 changed files with 93 additions and 39 deletions
|
@ -1,17 +1,46 @@
|
|||
import { INode } from '~/redux/types';
|
||||
import { IComment, INode } from '~/redux/types';
|
||||
import { FileUploader } from '~/utils/hooks/fileUploader';
|
||||
import { useCallback, useEffect, useRef } from 'react';
|
||||
import { useFormik, useFormikContext } from 'formik';
|
||||
import { object } from 'yup';
|
||||
import { FormikHelpers, useFormik, useFormikContext } from 'formik';
|
||||
import { object, string } from 'yup';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { nodeSubmitLocal } from '~/redux/node/actions';
|
||||
import { keys } from 'ramda';
|
||||
|
||||
const validationSchema = object().shape({});
|
||||
|
||||
const onSuccess = ({ resetForm, setStatus, setSubmitting, setErrors }: FormikHelpers<INode>) => (
|
||||
e?: string,
|
||||
errors?: Record<string, string>
|
||||
) => {
|
||||
setSubmitting(false);
|
||||
|
||||
if (e) {
|
||||
setStatus(e);
|
||||
return;
|
||||
}
|
||||
|
||||
if (errors && keys(errors).length) {
|
||||
setErrors(errors);
|
||||
return;
|
||||
}
|
||||
|
||||
if (resetForm) {
|
||||
resetForm();
|
||||
}
|
||||
};
|
||||
|
||||
export const useNodeFormFormik = (
|
||||
values: INode,
|
||||
uploader: FileUploader,
|
||||
stopEditing: () => void
|
||||
) => {
|
||||
const onSubmit = useCallback(console.log, []);
|
||||
const dispatch = useDispatch();
|
||||
const onSubmit = useCallback((values: INode, helpers: FormikHelpers<INode>) => {
|
||||
helpers.setSubmitting(true);
|
||||
dispatch(nodeSubmitLocal(values, onSuccess(helpers)));
|
||||
}, []);
|
||||
|
||||
const { current: initialValues } = useRef(values);
|
||||
|
||||
const onReset = useCallback(() => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue