Skip to content

Commit f4bda19

Browse files
Evil
1 parent 97e2b2f commit f4bda19

File tree

5 files changed

+72
-2
lines changed

5 files changed

+72
-2
lines changed

my-money-app/frontend/src/billingCycle/billingCycle.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import TabsContent from '../common/tab/tabsContent'
1010
import TabHeader from '../common/tab/tabHeader'
1111
import TabContent from '../common/tab/tabContent'
1212
import { selectTab, showTabs } from '../common/tab/tabActions'
13+
import List from './billingCycleList'
1314

1415
class BillingCycle extends Component {
1516

@@ -31,7 +32,9 @@ class BillingCycle extends Component {
3132
<TabHeader label='Excluir' icon='trash-o' target='tabDelete' />
3233
</TabsHeader>
3334
<TabsContent>
34-
<TabContent id='tabList'><h1>Lista</h1></TabContent>
35+
<TabContent id='tabList'>
36+
<List />
37+
</TabContent>
3538
<TabContent id='tabCreate'><h1>Incluir</h1></TabContent>
3639
<TabContent id='tabUpdate'><h1>Alterar</h1></TabContent>
3740
<TabContent id='tabDelete'><h1>Excluir</h1></TabContent>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import axios from 'axios'
2+
const BASE_URL = 'http://localhost:3003/api'
3+
4+
export function getList() {
5+
const request = axios.get(`${BASE_URL}/billingCycles`)
6+
return {
7+
type: 'BILLING_CYCLES_FETCHED',
8+
payload: request
9+
}
10+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React, { Component } from 'react'
2+
import { bindActionCreators } from 'redux'
3+
import { connect } from 'react-redux'
4+
import { getList } from './billingCycleActions'
5+
6+
class BillingCycleList extends Component {
7+
8+
componentWillMount() {
9+
this.props.getList()
10+
}
11+
12+
renderRows() {
13+
const list = this.props.list || []
14+
return list.map(bc => (
15+
<tr key={bc._id}>
16+
<td>{bc.name}</td>
17+
<td>{bc.month}</td>
18+
<td>{bc.year}</td>
19+
</tr>
20+
))
21+
}
22+
23+
render() {
24+
return (
25+
<div>
26+
<table className='table'>
27+
<thead>
28+
<tr>
29+
<th>Nome</th>
30+
<th>Mês</th>
31+
<th>Ano</th>
32+
</tr>
33+
</thead>
34+
<tbody>
35+
{this.renderRows()}
36+
</tbody>
37+
</table>
38+
</div>
39+
)
40+
}
41+
}
42+
43+
const mapStateToProps = state => ({list: state.billingCycle.list})
44+
const mapDispatchToProps = dispatch => bindActionCreators({getList}, dispatch)
45+
export default connect(mapStateToProps, mapDispatchToProps)(BillingCycleList)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const INITIAL_STATE = {list: []}
2+
3+
export default (state = INITIAL_STATE, action) => {
4+
switch (action.type) {
5+
case 'BILLING_CYCLES_FETCHED':
6+
return { ...state, list: action.payload.data }
7+
default:
8+
return state
9+
}
10+
}

my-money-app/frontend/src/main/reducers.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { combineReducers } from 'redux'
22

33
import DashboardReducer from '../dashboard/dashboardReducer'
44
import TabReducer from '../common/tab/tabReducer'
5+
import BillingCycleReducer from '../billingCycle/billingCycleReducer'
56

67
const rootReducer = combineReducers({
78
dashboard: DashboardReducer,
8-
tab: TabReducer
9+
tab: TabReducer,
10+
billingCycle: BillingCycleReducer
911
})
1012

1113
export default rootReducer

0 commit comments

Comments
 (0)