Refacto onChange action

This commit is contained in:
cyril lopez 2018-01-18 17:27:59 +01:00
parent 97d6f49f93
commit 405272eadf
4 changed files with 6 additions and 12 deletions

View File

@ -55,7 +55,7 @@ export function fetchDataSucceeded(data) {
export function onChange({ target }) {
return {
type: ON_CHANGE,
key: target.name,
keys: ['modifiedData'].concat(target.name.split('.')),
value: target.value,
};
}

View File

@ -129,12 +129,7 @@ export class HomePage extends React.Component {
return (
<div>
<form
onSubmit={(e) => {
e.preventDefault();
this.props.submit(match.params.settingType);
}}
>
<form onSubmit={(e) => e.preventDefault()}>
<div className={cn('container-fluid', styles.containerFluid)}>
<PluginHeader
title={{ id: 'users-permissions.HomePage.header.title' }}

View File

@ -42,7 +42,7 @@ function homePageReducer(state = initialState, action) {
return state.set('data', List(action.data));
case ON_CHANGE:
return state
.updateIn(['modifiedData', action.key], () => action.value);
.updateIn(action.keys, () => action.value);
case SET_FORM:
return state
.set('initialData', action.form)

View File

@ -67,11 +67,10 @@ export function* submitData(action) {
try {
const body = yield select(makeSelectModifiedData());
const opts = { method: 'PUT', body };
const response = yield call(request, `/users-permissions/${action.endPoint}`, opts, true);
if (response.ok) {
yield put(submitSucceeded());
}
yield call(request, `/users-permissions/${action.endPoint}`, opts, true);
yield put(submitSucceeded());
} catch(error) {
strapi.notification.error('notification.error');
}