2020-05-13 12:08:33 +02:00
|
|
|
/* eslint-disable consistent-return */
|
|
|
|
import produce from 'immer';
|
|
|
|
import { set } from 'lodash';
|
2021-02-11 15:49:12 +01:00
|
|
|
import formDataModel from 'ee_else_ce/components/Users/ModalCreateBody/utils/formDataModel';
|
2020-05-13 12:08:33 +02:00
|
|
|
|
|
|
|
const initialState = {
|
2020-05-13 18:25:03 +02:00
|
|
|
formErrors: {},
|
2021-02-11 15:49:12 +01:00
|
|
|
modifiedData: formDataModel,
|
2020-05-13 12:08:33 +02:00
|
|
|
};
|
|
|
|
|
2021-02-15 19:09:40 +01:00
|
|
|
const reducer = (state, action) =>
|
2020-05-13 12:08:33 +02:00
|
|
|
produce(state, draftState => {
|
|
|
|
switch (action.type) {
|
|
|
|
case 'ON_CHANGE': {
|
|
|
|
set(draftState.modifiedData, action.keys.split('.'), action.value);
|
|
|
|
break;
|
|
|
|
}
|
2020-05-13 18:25:03 +02:00
|
|
|
case 'SET_ERRORS': {
|
|
|
|
draftState.formErrors = action.errors;
|
|
|
|
break;
|
|
|
|
}
|
2020-05-13 12:08:33 +02:00
|
|
|
default:
|
|
|
|
return draftState;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export { initialState, reducer };
|