File tree Expand file tree Collapse file tree 5 files changed +72
-2
lines changed
my-money-app/frontend/src Expand file tree Collapse file tree 5 files changed +72
-2
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import TabsContent from '../common/tab/tabsContent'
1010import TabHeader from '../common/tab/tabHeader'
1111import TabContent from '../common/tab/tabContent'
1212import { selectTab , showTabs } from '../common/tab/tabActions'
13+ import List from './billingCycleList'
1314
1415class 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 >
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -2,10 +2,12 @@ import { combineReducers } from 'redux'
22
33import DashboardReducer from '../dashboard/dashboardReducer'
44import TabReducer from '../common/tab/tabReducer'
5+ import BillingCycleReducer from '../billingCycle/billingCycleReducer'
56
67const rootReducer = combineReducers ( {
78 dashboard : DashboardReducer ,
8- tab : TabReducer
9+ tab : TabReducer ,
10+ billingCycle : BillingCycleReducer
911} )
1012
1113export default rootReducer
You can’t perform that action at this time.
0 commit comments