Redirection after record deletion

This commit is contained in:
Pierre Burgy 2017-05-09 17:35:36 +02:00
parent 6267955b41
commit 1baf70727d
2 changed files with 17 additions and 1 deletions

View File

@ -25,7 +25,15 @@ import { translationMessages } from './i18n';
// Plugin identifier based on the package.json `name` value
const pluginId = require('../package.json').name.replace(/^strapi-plugin-/i, '');
// Define Strapi admin router
let router;
class comp extends React.Component { // eslint-disable-line react/prefer-stateless-function
componentWillMount() {
// Expose Strapi admin router
router = this.context.router;
}
render() {
return (
<Provider store={store}>
@ -35,6 +43,10 @@ class comp extends React.Component { // eslint-disable-line react/prefer-statele
}
}
comp.contextTypes = {
router: React.PropTypes.object.isRequired,
};
// Register the plugin
if (window.Strapi) {
window.Strapi.registerPlugin({
@ -71,4 +83,5 @@ export {
store,
apiUrl,
pluginId,
router,
};

View File

@ -2,6 +2,7 @@ import { takeLatest } from 'redux-saga';
import { put, select, fork, call } from 'redux-saga/effects';
import request from 'utils/request';
import { browserHistory } from 'react-router';
import { router } from 'app';
import {
recordLoaded,
@ -80,7 +81,9 @@ export function* deleteRecord() {
yield put(recordDeleted());
window.Strapi.notification.success('The entry has been successfully deleted.');
// TODO: Redirect to the list page.
// Redirect to the list page.
router.push(`/plugins/content-manager/${currentModelName}`);
} catch (err) {
yield put(recordDeleteError());
window.Strapi.notification.error('An error occurred during record deletion.');