diff --git a/src/components/node/NodeImageBlock/index.tsx b/src/components/node/NodeImageBlock/index.tsx index 72a364d8..1e675602 100644 --- a/src/components/node/NodeImageBlock/index.tsx +++ b/src/components/node/NodeImageBlock/index.tsx @@ -12,9 +12,11 @@ interface IProps { } const NodeImageBlock: FC = ({ node, is_loading }) => { - const images = useMemo(() => node.files.filter(({ type }) => type === UPLOAD_TYPES.IMAGE), [ - node, - ]); + const images = useMemo( + () => + (node && node.files && node.files.filter(({ type }) => type === UPLOAD_TYPES.IMAGE)) || [], + [node] + ); return (
diff --git a/src/constants/api.ts b/src/constants/api.ts index 04e3fb17..8ddb366f 100644 --- a/src/constants/api.ts +++ b/src/constants/api.ts @@ -8,5 +8,6 @@ export const API = { NODE: { SAVE: '/node/', GET: '/node/', + GET_NODE: (id: number | string) => `/node/${id}`, }, }; diff --git a/src/redux/node/api.ts b/src/redux/node/api.ts index bc977744..cd798da6 100644 --- a/src/redux/node/api.ts +++ b/src/redux/node/api.ts @@ -23,3 +23,13 @@ export const getNodes = ({ .get(API.NODE.GET, { params: { skip } }) .then(resultMiddleware) .catch(errorMiddleware); + +export const getNode = ({ + id, +}: { + id: string | number; +}): Promise> => + api + .get(API.NODE.GET_NODE(id)) + .then(resultMiddleware) + .catch(errorMiddleware); diff --git a/src/redux/node/sagas.ts b/src/redux/node/sagas.ts index 2bc3e1aa..ad0c84a3 100644 --- a/src/redux/node/sagas.ts +++ b/src/redux/node/sagas.ts @@ -9,7 +9,7 @@ import { nodeSetLoading, nodeSetCurrent, } from './actions'; -import { postNode } from './api'; +import { postNode, getNode } from './api'; import { reqWrapper } from '../auth/sagas'; import { flowSetNodes } from '../flow/actions'; import { ERRORS } from '~/constants/errors'; @@ -45,10 +45,20 @@ function* onNodeLoad({ id, node_type }: ReturnType) { yield put(push(URLS.NODE_URL(id))); - yield delay(1000); + const { + data: { node, error }, + } = yield call(getNode, { id }); yield put(nodeSetLoading(false)); + + if (error) { + return yield put(nodeSetSaveErrors({ error })); + } + yield put(nodeSetSaveErrors({})); + yield put(nodeSetCurrent(node)); + + return; } export default function* nodeSaga() {