budget-demo/client/src/data/context/BudgetReducer.js

21 lines
612 B
JavaScript
Raw Normal View History

const BudgetReducer = (state, action) => {
if (action.type === 'budget/populate') {
return {
...state,
budgetPeriods: action.data
};
}
if (action.type === 'budget/period/bills/update') {
return {
...state,
budgetPeriods: state.budgetPeriods.map(bp => ({...bp,
bills: bp.bills.map(b => ({...b,
paid: (bp.id === action.data.periodId && b.id === action.data.billId) ? !b.paid : b.paid
}))
}))
};
}
return {...state };
};
export default BudgetReducer;