2017-11-02 16:49:10 +01:00
|
|
|
import { fork, call, put, select, takeLatest } from 'redux-saga/effects';
|
2017-11-02 11:36:38 +01:00
|
|
|
|
2017-11-02 16:49:10 +01:00
|
|
|
import { pluginDeleted } from 'containers/App/actions';
|
|
|
|
|
import request from 'utils/request';
|
|
|
|
|
|
|
|
|
|
import { deletePluginSucceeded } from './actions';
|
|
|
|
|
import { ON_DELETE_PLUGIN_CONFIRM } from './constants';
|
|
|
|
|
import { makeSelectPluginToDelete } from './selectors';
|
|
|
|
|
|
|
|
|
|
export function* deletePlugin() {
|
|
|
|
|
try {
|
|
|
|
|
const plugin = yield select(makeSelectPluginToDelete());
|
|
|
|
|
const requestUrl = `/admin/plugins/uninstall/${plugin}`;
|
|
|
|
|
|
|
|
|
|
const resp = yield call(request, requestUrl, { method: 'DELETE' });
|
|
|
|
|
|
|
|
|
|
if (resp.ok) {
|
|
|
|
|
yield put(deletePluginSucceeded());
|
|
|
|
|
yield put(pluginDeleted(plugin));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch(error) {
|
2017-11-02 17:05:37 +01:00
|
|
|
yield put(deletePluginSucceeded());
|
|
|
|
|
window.Strapi.notification.error('app.components.listPluginsPage.deletePlugin.error');
|
2017-11-02 16:49:10 +01:00
|
|
|
}
|
|
|
|
|
}
|
2017-11-02 11:36:38 +01:00
|
|
|
// Individual exports for testing
|
|
|
|
|
export default function* defaultSaga() {
|
2017-11-02 16:49:10 +01:00
|
|
|
yield fork(takeLatest, ON_DELETE_PLUGIN_CONFIRM, deletePlugin);
|
2017-11-02 11:36:38 +01:00
|
|
|
}
|