1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

saving node and showing dialog

This commit is contained in:
muerwre 2019-08-24 18:05:46 +07:00
parent 95443635b4
commit 05980ce440
4 changed files with 14 additions and 6 deletions

View file

@ -1,7 +1,7 @@
import { INode } from '../types';
import { FLOW_ACTIONS } from './constants';
import { IFlowState } from './reducer';
export const flowSetNodes = (nodes: INode[]) => ({
export const flowSetNodes = (nodes: IFlowState['nodes']) => ({
nodes,
type: FLOW_ACTIONS.SET_NODES,
});

View file

@ -3,20 +3,27 @@ import { NODE_ACTIONS } from './constants';
import { nodeSave, nodeSetSaveErrors } from './actions';
import { postNode } from './api';
import { reqWrapper } from '../auth/sagas';
import { flowSetNodes } from '../flow/actions';
import { ERRORS } from '~/constants/errors';
import { modalSetShown } from '../modal/actions';
function* onNodeSave({ node }: ReturnType<typeof nodeSave>) {
yield put(nodeSetSaveErrors({}));
const {
data,
data: { errors },
data: { errors, node: result },
} = yield call(reqWrapper, postNode, { node });
if (errors && Object.values(errors).length > 0) {
return yield put(nodeSetSaveErrors(errors));
}
console.log({ data, errors });
if (!result || !result.id) {
return yield put(nodeSetSaveErrors({ error: ERRORS.EMPTY_RESPONSE }));
}
yield put(flowSetNodes({ [result.id]: result }));
yield put(modalSetShown(false));
}
export default function* nodeSaga() {

View file

@ -114,4 +114,4 @@ export interface INode {
}
export type IUploadProgressHandler = (progress: ProgressEvent) => void;
export type IValidationErrors = Record<string, keyof typeof ERRORS>;
export type IValidationErrors = Record<string, ValueOf<typeof ERRORS>>;