PromucFlow_constructor/app/client/src/sagas/PluginSagas.ts
2019-11-29 05:22:49 +00:00

31 lines
799 B
TypeScript

import { all, takeEvery, call, put } from "redux-saga/effects";
import { ReduxActionTypes } from "constants/ReduxActionConstants";
import PluginsApi from "api/PluginApi";
import { validateResponse } from "sagas/ErrorSagas";
function* fetchPluginsSaga() {
try {
const pluginsResponse = yield call(PluginsApi.fetchPlugins);
const isValid = yield validateResponse(pluginsResponse);
if (isValid) {
yield put({
type: ReduxActionTypes.FETCH_PLUGINS_SUCCESS,
payload: pluginsResponse.data,
});
}
} catch (error) {
yield put({
type: ReduxActionTypes.FETCH_PLUGINS_ERROR,
payload: { error },
});
}
}
function* root() {
yield all([
takeEvery(ReduxActionTypes.FETCH_PLUGINS_REQUEST, fetchPluginsSaga),
]);
}
export default root;