21 lines
612 B
JavaScript
21 lines
612 B
JavaScript
|
|
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;
|