soupette a147590cad Add conditions to reducer
Signed-off-by: soupette <cyril.lpz@gmail.com>
2021-02-12 09:52:06 +01:00

20 lines
670 B
JavaScript

import createArrayOfValues from './createArrayOfValues';
import removeConditionKeyFromData from './removeConditionKeyFromData';
const getCheckboxState = dataObj => {
const dataWithoutCondition = removeConditionKeyFromData(dataObj);
const arrayOfValues = createArrayOfValues(dataWithoutCondition);
if (!arrayOfValues.length) {
return { hasAllActionsSelected: false, hasSomeActionsSelected: false };
}
const hasAllActionsSelected = arrayOfValues.every(val => val);
const hasSomeActionsSelected = arrayOfValues.some(val => val) && !hasAllActionsSelected;
return { hasAllActionsSelected, hasSomeActionsSelected };
};
export default getCheckboxState;