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':
|
|
|
|
// Add object to items array
|
|
|
|
let newState = [...state, {
|
|
|
|
id: parseInt(action.id),
|
|
|
|
value: action.value,
|
|
|
|
disabled: false,
|
|
|
|
selected: false
|
|
|
|
}];
|
|
|
|
|
|
|
|
return newState;
|
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-12 15:10:07 +02:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default options;
|