Refetch roles after delete

This commit is contained in:
Aurelsicoko 2018-01-24 13:51:22 +01:00
parent cf1cb7050b
commit ed696f70a0
19 changed files with 27 additions and 24 deletions

View File

@ -55,4 +55,4 @@
"npm": ">= 5.3.0" "npm": ">= 5.3.0"
}, },
"license": "MIT" "license": "MIT"
} }

View File

@ -46,4 +46,4 @@
"npm": ">= 5.3.0" "npm": ">= 5.3.0"
}, },
"license": "MIT" "license": "MIT"
} }

View File

@ -43,4 +43,4 @@
"npm": ">= 5.3.0" "npm": ">= 5.3.0"
}, },
"license": "MIT" "license": "MIT"
} }

View File

@ -43,4 +43,4 @@
"npm": ">= 5.3.0" "npm": ">= 5.3.0"
}, },
"license": "MIT" "license": "MIT"
} }

View File

@ -43,4 +43,4 @@
"npm": ">= 5.3.0" "npm": ">= 5.3.0"
}, },
"license": "MIT" "license": "MIT"
} }

View File

@ -48,4 +48,4 @@
"npm": ">= 5.3.0" "npm": ">= 5.3.0"
}, },
"license": "MIT" "license": "MIT"
} }

View File

@ -44,4 +44,4 @@
"npm": ">= 5.3.0" "npm": ">= 5.3.0"
}, },
"license": "MIT" "license": "MIT"
} }

View File

@ -43,4 +43,4 @@
"npm": ">= 5.3.0" "npm": ">= 5.3.0"
}, },
"license": "MIT" "license": "MIT"
} }

View File

@ -43,4 +43,4 @@
"npm": ">= 5.3.0" "npm": ">= 5.3.0"
}, },
"license": "MIT" "license": "MIT"
} }

View File

@ -47,4 +47,4 @@
"npm": ">= 3.0.0" "npm": ">= 3.0.0"
}, },
"license": "MIT" "license": "MIT"
} }

View File

@ -49,4 +49,4 @@
"npm": ">= 3.0.0" "npm": ">= 3.0.0"
}, },
"license": "MIT" "license": "MIT"
} }

View File

@ -48,4 +48,4 @@
"npm": ">= 3.0.0" "npm": ">= 3.0.0"
}, },
"license": "MIT" "license": "MIT"
} }

View File

@ -40,11 +40,11 @@ class ListRow extends React.Component { // eslint-disable-line react/prefer-stat
switch (this.props.settingType) { switch (this.props.settingType) {
case 'roles': case 'roles':
if (includes(this.protectedRoleIDs, get(this.props.item, 'type').toString())) { if (includes(this.protectedRoleIDs, get(this.props.item, 'type', ''))) {
icons = []; icons = [];
} }
if (includes(this.undeletableIDs, get(this.props.item, 'type').toString())) { if (includes(this.undeletableIDs, get(this.props.item, 'type', ''))) {
icons = [{ icoType: 'pencil', onClick: this.handleClick }]; icons = [{ icoType: 'pencil', onClick: this.handleClick }];
} }
@ -129,7 +129,7 @@ class ListRow extends React.Component { // eslint-disable-line react/prefer-stat
handleClick = () => { handleClick = () => {
switch (this.props.settingType) { switch (this.props.settingType) {
case 'roles': { case 'roles': {
if (!includes(this.protectedRoleIDs, get(this.props.item, 'type').toString())) { if (!includes(this.protectedRoleIDs, get(this.props.item, 'type', ''))) {
return router.push(`${router.location.pathname}/edit/${this.props.item.id}`); return router.push(`${router.location.pathname}/edit/${this.props.item.id}`);
} }
return; return;

View File

@ -99,7 +99,7 @@ export function* submit() {
}; };
const requestURL = actionType === 'POST' ? '/users-permissions/roles' : `/users-permissions/roles/${roleId}`; const requestURL = actionType === 'POST' ? '/users-permissions/roles' : `/users-permissions/roles/${roleId}`;
const response = yield call(request, requestURL, opts, true); const response = yield call(request, requestURL, opts);
if (response.ok) { if (response.ok) {
yield put(submitSucceeded()); yield put(submitSucceeded());

View File

@ -57,6 +57,10 @@ export class HomePage extends React.Component {
if (shouldRedirect) { if (shouldRedirect) {
this.props.history.push('/404'); this.props.history.push('/404');
} }
if (nextProps.didDeleteData !== this.props.didDeleteData) {
this.props.fetchData(nextProps.match.params.settingType);
}
} }
componentDidUpdate(prevProps) { componentDidUpdate(prevProps) {
@ -161,6 +165,7 @@ HomePage.defaultProps = {};
HomePage.propTypes = { HomePage.propTypes = {
data: PropTypes.array.isRequired, data: PropTypes.array.isRequired,
deleteData: PropTypes.func.isRequired, deleteData: PropTypes.func.isRequired,
didDeleteData: PropTypes.bool.isRequired,
fetchData: PropTypes.func.isRequired, fetchData: PropTypes.func.isRequired,
history: PropTypes.object.isRequired, history: PropTypes.object.isRequired,
location: PropTypes.object.isRequired, location: PropTypes.object.isRequired,

View File

@ -21,6 +21,7 @@ const initialState = fromJS({
initialData: Map({}), initialData: Map({}),
modifiedData: Map({}), modifiedData: Map({}),
showButtons: false, showButtons: false,
didDeleteData: false,
}); });
function homePageReducer(state = initialState, action) { function homePageReducer(state = initialState, action) {
@ -33,7 +34,8 @@ function homePageReducer(state = initialState, action) {
return state return state
.update('data', list => list.splice(action.indexDataToDelete, 1)) .update('data', list => list.splice(action.indexDataToDelete, 1))
.set('deleteEndPoint', '') .set('deleteEndPoint', '')
.set('dataToDelete', Map({})); .set('dataToDelete', Map({}))
.update('didDeleteData', (v) => !v);
case FETCH_DATA_SUCCEEDED: case FETCH_DATA_SUCCEEDED:
return state.set('data', List(action.data)); return state.set('data', List(action.data));
case ON_CHANGE: case ON_CHANGE:

View File

@ -34,7 +34,7 @@ export function* dataDelete() {
if (indexDataToDelete !== -1) { if (indexDataToDelete !== -1) {
const id = dataToDelete.id; const id = dataToDelete.id;
const requestURL = `/users-permissions/${endPointAPI}/${id}`; const requestURL = `/users-permissions/${endPointAPI}/${id}`;
const response = yield call(request, requestURL, { method: 'DELETE' }, true); const response = yield call(request, requestURL, { method: 'DELETE' });
if (response.ok) { if (response.ok) {
yield put(deleteDataSucceeded(indexDataToDelete)); yield put(deleteDataSucceeded(indexDataToDelete));

View File

@ -20,14 +20,10 @@ module.exports = {
return ctx.badRequest(null, [{ messages: [{ id: 'Cannot be empty' }] }]); return ctx.badRequest(null, [{ messages: [{ id: 'Cannot be empty' }] }]);
} }
strapi.reload.isWatching = false;
try { try {
await strapi.plugins['users-permissions'].services.userspermissions.createRole(ctx.request.body); await strapi.plugins['users-permissions'].services.userspermissions.createRole(ctx.request.body);
ctx.send({ ok: true }); ctx.send({ ok: true });
strapi.reload();
} catch(err) { } catch(err) {
ctx.badRequest(null, [{ messages: [{ id: 'An error occured' }] }]); ctx.badRequest(null, [{ messages: [{ id: 'An error occured' }] }]);
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "strapi-plugin-users-permissions", "name": "strapi-plugin-users-permissions",
"version": "3.0.0-alpha.8", "version": "3.0.0-alpha.8.3",
"description": "Protect your API with a full-authentication process based on JWT", "description": "Protect your API with a full-authentication process based on JWT",
"strapi": { "strapi": {
"name": "Auth & Permissions", "name": "Auth & Permissions",
@ -55,4 +55,4 @@
"npm": ">= 3.0.0" "npm": ">= 3.0.0"
}, },
"license": "MIT" "license": "MIT"
} }