Fix add compo to dz action

This commit is contained in:
soupette 2020-01-15 12:35:26 +01:00
parent 89568007f6
commit 16a6975af1
3 changed files with 10 additions and 10 deletions

View File

@ -81,8 +81,6 @@
"dz": { "dz": {
"type": "dynamiczone", "type": "dynamiczone",
"components": [ "components": [
"default.closingperiod",
"default.dish",
"default.openingtimes", "default.openingtimes",
"default.restaurantservice" "default.restaurantservice"
] ]

View File

@ -138,7 +138,7 @@ const MultipleMenuList = ({
const handleChange = ({ target }) => { const handleChange = ({ target }) => {
const dataTarget = { const dataTarget = {
name, name,
components: target.name, components: [target.name],
shouldAddComponents: target.value, shouldAddComponents: target.value,
}; };

View File

@ -1,4 +1,4 @@
import { fromJS } from 'immutable'; import { fromJS, List } from 'immutable';
import pluralize from 'pluralize'; import pluralize from 'pluralize';
import { snakeCase } from 'lodash'; import { snakeCase } from 'lodash';
import makeUnique from '../../utils/makeUnique'; import makeUnique from '../../utils/makeUnique';
@ -22,15 +22,17 @@ const reducer = (state, action) => {
const { name, components, shouldAddComponents } = action; const { name, components, shouldAddComponents } = action;
return state.updateIn(['modifiedData', name], list => { return state.updateIn(['modifiedData', name], list => {
let updatedList = list;
if (shouldAddComponents) { if (shouldAddComponents) {
return makeUnique(list.concat(components)); updatedList = list.concat(components);
} else { } else {
return makeUnique( updatedList = list.filter(comp => {
list.filter(comp => { return components.indexOf(comp) === -1;
return components.indexOf(comp) === -1; });
})
);
} }
return List(makeUnique(updatedList.toJS()));
}); });
} }
case 'ON_CHANGE': case 'ON_CHANGE':