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 }) { export function onChange({ target }) {
return { return {
type: ON_CHANGE, type: ON_CHANGE,
key: target.name, keys: ['modifiedData'].concat(target.name.split('.')),
value: target.value, value: target.value,
}; };
} }

View File

@ -129,12 +129,7 @@ export class HomePage extends React.Component {
return ( return (
<div> <div>
<form <form onSubmit={(e) => e.preventDefault()}>
onSubmit={(e) => {
e.preventDefault();
this.props.submit(match.params.settingType);
}}
>
<div className={cn('container-fluid', styles.containerFluid)}> <div className={cn('container-fluid', styles.containerFluid)}>
<PluginHeader <PluginHeader
title={{ id: 'users-permissions.HomePage.header.title' }} 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)); return state.set('data', List(action.data));
case ON_CHANGE: case ON_CHANGE:
return state return state
.updateIn(['modifiedData', action.key], () => action.value); .updateIn(action.keys, () => action.value);
case SET_FORM: case SET_FORM:
return state return state
.set('initialData', action.form) .set('initialData', action.form)

View File

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