51 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-11-06 09:56:27 +01:00
import { all, call, fork, put, select, takeLatest } from 'redux-saga/effects';
2019-04-16 18:23:26 +02:00
import { request } from 'strapi-helper-plugin';
import { getSettingsSucceeded, submitSucceeded } from './actions';
import { GET_SETTINGS, SUBMIT } from './constants';
import { makeSelectEnv, makeSelectModifiedData } from './selectors';
export function* settingsGet(action) {
try {
const requestURL = `/upload/settings/${action.env}`;
2018-11-06 09:56:27 +01:00
const response = yield all([
2018-03-08 10:32:01 +01:00
call(request, requestURL, { method: 'GET' }),
call(request, '/upload/environments', { method: 'GET' }),
2018-11-06 09:56:27 +01:00
]);
2018-03-08 10:32:01 +01:00
yield put(getSettingsSucceeded(response[0], response[1].environments));
2019-04-16 18:23:26 +02:00
} catch (err) {
strapi.notification.error('notification.error');
}
}
2018-02-26 12:16:15 +01:00
2018-02-28 17:11:44 +01:00
export function* submit() {
try {
const env = yield select(makeSelectEnv());
let body = yield select(makeSelectModifiedData());
if (body.provider === 'local') {
body = {
enabled: body.enabled,
provider: 'local',
sizeLimit: body.sizeLimit,
};
}
const requestURL = `/upload/settings/${env}`;
yield call(request, requestURL, { method: 'PUT', body });
// Update reducer with optimisticResponse
2018-03-06 15:49:11 +01:00
strapi.notification.success('upload.notification.config.success');
2018-02-28 17:11:44 +01:00
yield put(submitSucceeded(body));
2019-04-16 18:23:26 +02:00
} catch (err) {
2018-02-28 17:11:44 +01:00
strapi.notification.error('notification.error');
// TODO handle error PUT
}
}
function* defaultSaga() {
yield fork(takeLatest, GET_SETTINGS, settingsGet);
2018-02-28 17:11:44 +01:00
yield fork(takeLatest, SUBMIT, submit);
2018-02-26 12:16:15 +01:00
}
export default defaultSaga;