Skip to content

Commit 62b3db9

Browse files
Cadastro de Ciclos de Pagamentos: inclusão
1 parent f4bda19 commit 62b3db9

File tree

9 files changed

+116
-7
lines changed

9 files changed

+116
-7
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ 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 { create } from './billingCycleActions'
14+
1315
import List from './billingCycleList'
16+
import Form from './billingCycleForm'
1417

1518
class BillingCycle extends Component {
1619

@@ -35,8 +38,12 @@ class BillingCycle extends Component {
3538
<TabContent id='tabList'>
3639
<List />
3740
</TabContent>
38-
<TabContent id='tabCreate'><h1>Incluir</h1></TabContent>
39-
<TabContent id='tabUpdate'><h1>Alterar</h1></TabContent>
41+
<TabContent id='tabCreate'>
42+
<Form onSubmit={this.props.create} />
43+
</TabContent>
44+
<TabContent id='tabUpdate'>
45+
<Form />
46+
</TabContent>
4047
<TabContent id='tabDelete'><h1>Excluir</h1></TabContent>
4148
</TabsContent>
4249
</Tabs>
@@ -46,5 +53,7 @@ class BillingCycle extends Component {
4653
}
4754
}
4855

49-
const mapDispatchToProps = dispatch => bindActionCreators({selectTab, showTabs}, dispatch)
56+
const mapDispatchToProps = dispatch => bindActionCreators({
57+
selectTab, showTabs, create
58+
}, dispatch)
5059
export default connect(null, mapDispatchToProps)(BillingCycle)

my-money-app/frontend/src/billingCycle/billingCycleActions.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import axios from 'axios'
2+
import { toastr } from 'react-redux-toastr'
3+
import { reset as resetForm, initialize } from 'redux-form'
4+
import { showTabs, selectTab } from '../common/tab/tabActions'
5+
26
const BASE_URL = 'http://localhost:3003/api'
37

48
export function getList() {
@@ -7,4 +11,30 @@ export function getList() {
711
type: 'BILLING_CYCLES_FETCHED',
812
payload: request
913
}
14+
}
15+
16+
export function create(values) {
17+
return dispatch => {
18+
axios.post(`${BASE_URL}/billingCycles`, values)
19+
.then(resp => {
20+
toastr.success('Sucesso', 'Operação Realizada com sucesso.')
21+
dispatch([
22+
resetForm('billingCycleForm'),
23+
getList(),
24+
selectTab('tabList'),
25+
showTabs('tabList', 'tabCreate')
26+
])
27+
})
28+
.catch(e => {
29+
e.response.data.errors.forEach(error => toastr.error('Erro', error))
30+
})
31+
}
32+
}
33+
34+
export function showUpdate(billingCycle) {
35+
return [
36+
showTabs('tabUpdate'),
37+
selectTab('tabUpdate'),
38+
initialize('billingCycleForm', billingCycle)
39+
]
1040
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React, { Component } from 'react'
2+
import { reduxForm, Field } from 'redux-form'
3+
import labelAndInput from '../common/form/labelAndInput'
4+
5+
class BillingCycleForm extends Component {
6+
7+
render() {
8+
const { handleSubmit } = this.props
9+
return (
10+
<form role='form' onSubmit={handleSubmit}>
11+
<div className='box-body'>
12+
<Field name='name' component={labelAndInput}
13+
label='Nome' cols='12 4' placeholder='Informe o nome' />
14+
<Field name='month' component={labelAndInput} type='number'
15+
label='Mês' cols='12 4' placeholder='Informe o mês' />
16+
<Field name='year' component={labelAndInput} type='number'
17+
label='Ano' cols='12 4' placeholder='Informe o ano' />
18+
</div>
19+
<div className='box-footer'>
20+
<button type='submit' className='btn btn-primary'>Submit</button>
21+
</div>
22+
</form>
23+
)
24+
}
25+
}
26+
27+
export default reduxForm({form: 'billingCycleForm'})(BillingCycleForm)

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from 'react'
22
import { bindActionCreators } from 'redux'
33
import { connect } from 'react-redux'
4-
import { getList } from './billingCycleActions'
4+
import { getList, showUpdate } from './billingCycleActions'
55

66
class BillingCycleList extends Component {
77

@@ -16,6 +16,11 @@ class BillingCycleList extends Component {
1616
<td>{bc.name}</td>
1717
<td>{bc.month}</td>
1818
<td>{bc.year}</td>
19+
<td>
20+
<button className='btn btn-warning' onClick={() => this.props.showUpdate(bc)}>
21+
<i className='fa fa-pencil'></i>
22+
</button>
23+
</td>
1924
</tr>
2025
))
2126
}
@@ -29,6 +34,7 @@ class BillingCycleList extends Component {
2934
<th>Nome</th>
3035
<th>Mês</th>
3136
<th>Ano</th>
37+
<th>Ações</th>
3238
</tr>
3339
</thead>
3440
<tbody>
@@ -41,5 +47,7 @@ class BillingCycleList extends Component {
4147
}
4248

4349
const mapStateToProps = state => ({list: state.billingCycle.list})
44-
const mapDispatchToProps = dispatch => bindActionCreators({getList}, dispatch)
50+
const mapDispatchToProps = dispatch => bindActionCreators({
51+
getList, showUpdate
52+
}, dispatch)
4553
export default connect(mapStateToProps, mapDispatchToProps)(BillingCycleList)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react'
2+
import Grid from '../layout/grid'
3+
4+
export default props => (
5+
<Grid cols={props.cols}>
6+
<div className='form-group'>
7+
<label htmlFor={props.name}>{props.label}</label>
8+
<input {...props.input} className='form-control'
9+
placeholder={props.placeholder}
10+
readOnly={props.readOnly} type={props.type} />
11+
</div>
12+
</Grid>
13+
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react'
2+
import ReduxToastr from 'react-redux-toastr'
3+
import 'modules/react-redux-toastr/lib/css/react-redux-toastr.css'
4+
5+
export default props => (
6+
<ReduxToastr
7+
timeOut={4000}
8+
newestOnTop={false}
9+
preventDuplicates={true}
10+
position='top-right'
11+
transitionIn='fadeIn'
12+
transitionOut='fadeOut'
13+
progressBar />
14+
)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import { applyMiddleware, createStore } from 'redux'
44
import { Provider } from 'react-redux'
55

66
import promise from 'redux-promise'
7+
import multi from 'redux-multi'
8+
import thunk from 'redux-thunk'
79

810
import App from './main/app'
911
import reducers from './main/reducers'
1012

1113
const devTools = window.__REDUX_DEVTOOLS_EXTENSION__
1214
&& window.__REDUX_DEVTOOLS_EXTENSION__()
13-
const store = applyMiddleware(promise)(createStore)(reducers, devTools)
15+
const store = applyMiddleware(multi, thunk, promise)(createStore)(reducers, devTools)
1416
ReactDOM.render(
1517
<Provider store={store}>
1618
<App />

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Header from '../common/template/header'
55
import SideBar from '../common/template/sideBar'
66
import Footer from '../common/template/footer'
77
import Routes from './routes'
8+
import Messages from '../common/msg/messages'
89

910
export default props => (
1011
<div className='wrapper'>
@@ -14,5 +15,6 @@ export default props => (
1415
<Routes />
1516
</div>
1617
<Footer />
18+
<Messages />
1719
</div>
1820
)
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { combineReducers } from 'redux'
2+
import { reducer as formReducer } from 'redux-form'
3+
import { reducer as toastrReducer } from 'react-redux-toastr'
24

35
import DashboardReducer from '../dashboard/dashboardReducer'
46
import TabReducer from '../common/tab/tabReducer'
@@ -7,7 +9,9 @@ import BillingCycleReducer from '../billingCycle/billingCycleReducer'
79
const rootReducer = combineReducers({
810
dashboard: DashboardReducer,
911
tab: TabReducer,
10-
billingCycle: BillingCycleReducer
12+
billingCycle: BillingCycleReducer,
13+
form: formReducer,
14+
toastr: toastrReducer
1115
})
1216

1317
export default rootReducer

0 commit comments

Comments
 (0)