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,4 +1,5 @@
export const ERRORS = { export const ERRORS = {
NOT_AN_EMAIL: 'Not_An_Email', NOT_AN_EMAIL: 'Not_An_Email',
TOO_SHIRT: 'Is_Too_Shirt', TOO_SHIRT: 'Is_Too_Shirt',
EMPTY_RESPONSE: 'Empty_Response',
}; };

View file

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

View file

@ -3,20 +3,27 @@ import { NODE_ACTIONS } from './constants';
import { nodeSave, nodeSetSaveErrors } from './actions'; import { nodeSave, nodeSetSaveErrors } from './actions';
import { postNode } from './api'; import { postNode } from './api';
import { reqWrapper } from '../auth/sagas'; 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>) { function* onNodeSave({ node }: ReturnType<typeof nodeSave>) {
yield put(nodeSetSaveErrors({})); yield put(nodeSetSaveErrors({}));
const { const {
data, data: { errors, node: result },
data: { errors },
} = yield call(reqWrapper, postNode, { node }); } = yield call(reqWrapper, postNode, { node });
if (errors && Object.values(errors).length > 0) { if (errors && Object.values(errors).length > 0) {
return yield put(nodeSetSaveErrors(errors)); 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() { export default function* nodeSaga() {

View file

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