2016-04-12 15:10:07 +02:00
|
|
|
const options = (state = [], action) => {
|
|
|
|
switch (action.type) {
|
2016-04-12 15:31:07 +02:00
|
|
|
case 'ADD_OPTION':
|
2016-04-14 15:43:36 +02:00
|
|
|
return [...state, {
|
2016-04-17 13:02:28 +02:00
|
|
|
id: action.id,
|
2016-04-16 18:06:27 +02:00
|
|
|
groupId: action.groupId,
|
2016-04-12 15:31:07 +02:00
|
|
|
value: action.value,
|
2016-04-16 18:06:27 +02:00
|
|
|
label: action.label,
|
2016-04-12 15:31:07 +02:00
|
|
|
disabled: false,
|
2016-04-16 18:06:27 +02:00
|
|
|
selected: false,
|
2016-04-14 15:43:36 +02:00
|
|
|
}];;
|
2016-04-12 21:16:36 +02:00
|
|
|
|
|
|
|
case 'SELECT_OPTION':
|
|
|
|
return state.map((option) => {
|
|
|
|
if(option.id === parseInt(action.id)) {
|
2016-04-12 23:42:56 +02:00
|
|
|
option.selected = action.selected;
|
2016-04-12 21:16:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return option;
|
|
|
|
});
|
|
|
|
|
2016-04-14 15:43:36 +02:00
|
|
|
case 'REMOVE_ITEM':
|
|
|
|
// When an item is removed and it has an associated option,
|
|
|
|
// we want to re-enable it so it can be chosen again
|
|
|
|
if(action.optionId > -1) {
|
|
|
|
return state.map((option) => {
|
|
|
|
if(option.id === parseInt(action.optionId)) {
|
|
|
|
option.selected = action.selected;
|
|
|
|
}
|
|
|
|
return option;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-12 15:10:07 +02:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default options;
|