From 05980ce440c4c260c386a696e4267b01b3b4f025 Mon Sep 17 00:00:00 2001 From: muerwre Date: Sat, 24 Aug 2019 18:05:46 +0700 Subject: [PATCH] saving node and showing dialog --- src/constants/errors.ts | 1 + src/redux/flow/actions.ts | 4 ++-- src/redux/node/sagas.ts | 13 ++++++++++--- src/redux/types.ts | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/constants/errors.ts b/src/constants/errors.ts index 70e772f2..2df83f51 100644 --- a/src/constants/errors.ts +++ b/src/constants/errors.ts @@ -1,4 +1,5 @@ export const ERRORS = { NOT_AN_EMAIL: 'Not_An_Email', TOO_SHIRT: 'Is_Too_Shirt', + EMPTY_RESPONSE: 'Empty_Response', }; diff --git a/src/redux/flow/actions.ts b/src/redux/flow/actions.ts index 4092bddb..88998656 100644 --- a/src/redux/flow/actions.ts +++ b/src/redux/flow/actions.ts @@ -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, }); diff --git a/src/redux/node/sagas.ts b/src/redux/node/sagas.ts index f003b008..58fbe88f 100644 --- a/src/redux/node/sagas.ts +++ b/src/redux/node/sagas.ts @@ -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) { 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() { diff --git a/src/redux/types.ts b/src/redux/types.ts index c20c1774..0d39d4b2 100644 --- a/src/redux/types.ts +++ b/src/redux/types.ts @@ -114,4 +114,4 @@ export interface INode { } export type IUploadProgressHandler = (progress: ProgressEvent) => void; -export type IValidationErrors = Record; +export type IValidationErrors = Record>;