1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-26 05:16:41 +07:00

flow redux

This commit is contained in:
muerwre 2019-08-24 17:58:39 +07:00
parent 9691504af6
commit 95443635b4
11 changed files with 118 additions and 10 deletions

View file

@ -2,14 +2,24 @@ import { api, configWithToken, resultMiddleware, errorMiddleware } from '~/utils
import { INode, IResultWithStatus } from '../types';
import { API } from '~/constants/api';
export const postNode = ({
export const postNode = ({
access,
node,
}: {
access: string,
node: INode,
}): Promise<IResultWithStatus<INode>> => (
api.post(API.NODE.SAVE, { node }, configWithToken(access))
access: string;
node: INode;
}): Promise<IResultWithStatus<INode>> =>
api
.post(API.NODE.SAVE, { node }, configWithToken(access))
.then(resultMiddleware)
.catch(errorMiddleware)
);
.catch(errorMiddleware);
export const getNodes = ({
skip = 0,
}: {
skip?: number;
}): Promise<IResultWithStatus<{ nodes: INode[] }>> =>
api
.get(API.NODE.GET, { params: { skip } })
.then(resultMiddleware)
.catch(errorMiddleware);

View file

@ -1,11 +1,20 @@
import { takeLatest, call } from 'redux-saga/effects';
import { takeLatest, call, put } from 'redux-saga/effects';
import { NODE_ACTIONS } from './constants';
import { nodeSave } from './actions';
import { nodeSave, nodeSetSaveErrors } from './actions';
import { postNode } from './api';
import { reqWrapper } from '../auth/sagas';
function* onNodeSave({ node }: ReturnType<typeof nodeSave>) {
const { data, errors } = yield call(reqWrapper, postNode, { node });
yield put(nodeSetSaveErrors({}));
const {
data,
data: { errors },
} = yield call(reqWrapper, postNode, { node });
if (errors && Object.values(errors).length > 0) {
return yield put(nodeSetSaveErrors(errors));
}
console.log({ data, errors });
}