62 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-02-26 12:16:15 +01:00
// import { LOCATION_CHANGE } from 'react-router-redux';
2018-02-28 17:11:44 +01:00
import { call, fork, put, select, takeLatest } from 'redux-saga/effects';
import request from 'utils/request';
2018-02-26 12:16:15 +01:00
import {
getSettingsSucceeded,
2018-02-28 17:11:44 +01:00
submitSucceeded,
} from './actions';
import {
GET_SETTINGS,
2018-02-28 17:11:44 +01:00
SUBMIT,
} from './constants';
2018-02-28 17:11:44 +01:00
import {
makeSelectEnv,
makeSelectModifiedData,
} from './selectors';
export function* settingsGet(action) {
try {
const requestURL = `/upload/settings/${action.env}`;
2018-03-08 10:32:01 +01:00
const response = yield [
call(request, requestURL, { method: 'GET' }),
call(request, '/upload/environments', { method: 'GET' }),
];
yield put(getSettingsSucceeded(response[0], response[1].environments));
} 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));
} catch(err) {
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;