patch SET_EPOCH reducer action with index undefined check

This commit is contained in:
Sorrel Bri 2019-12-16 14:29:44 -08:00
parent 53c9abe317
commit cabf342b4a

View file

@ -11,14 +11,15 @@ export type epochAction = {
}
export const addEpoch = (state: stateType, action: epochAction): stateType => {
const newEpoch = { ...action.value, changes: ['']};
const newEpoch = { name: action.value.name, changes: action.value.changes || [''] };
return {...state, epochs: [...state.epochs, newEpoch]}
}
export const setEpoch = (state: stateType, action: epochAction): stateType => {
let mutatedEpochs = state.epochs;
const index = action.value.index
if (!index) return state;
const index = action.value.index;
if (typeof index !== 'number') return state;
const mutatedEpochs = state.epochs;
mutatedEpochs[index].name = action.value.name
? action.value.name
: mutatedEpochs[index].name;