Skip to content

Commit 601916d

Browse files
Cadastro de Ciclos de Pagamentos
1 parent 62b3db9 commit 601916d

File tree

6 files changed

+90
-19
lines changed

6 files changed

+90
-19
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +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 { create } from './billingCycleActions'
13+
import { create, update, remove } from './billingCycleActions'
1414

1515
import List from './billingCycleList'
1616
import Form from './billingCycleForm'
@@ -39,21 +39,26 @@ class BillingCycle extends Component {
3939
<List />
4040
</TabContent>
4141
<TabContent id='tabCreate'>
42-
<Form onSubmit={this.props.create} />
42+
<Form onSubmit={this.props.create}
43+
submitLabel='Incluir' submitClass='primary' />
4344
</TabContent>
4445
<TabContent id='tabUpdate'>
45-
<Form />
46+
<Form onSubmit={this.props.update}
47+
submitLabel='Alterar' submitClass='info' />
48+
</TabContent>
49+
<TabContent id='tabDelete'>
50+
<Form onSubmit={this.props.remove} readOnly={true}
51+
submitLabel='Excluir' submitClass='danger' />
4652
</TabContent>
47-
<TabContent id='tabDelete'><h1>Excluir</h1></TabContent>
4853
</TabsContent>
4954
</Tabs>
5055
</Content>
51-
</div>
56+
</div>
5257
)
5358
}
5459
}
5560

5661
const mapDispatchToProps = dispatch => bindActionCreators({
57-
selectTab, showTabs, create
62+
selectTab, showTabs, create, update, remove
5863
}, dispatch)
5964
export default connect(null, mapDispatchToProps)(BillingCycle)

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

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,21 @@ export function getList() {
1414
}
1515

1616
export function create(values) {
17+
return submit(values, 'post')
18+
}
19+
20+
export function update(values) {
21+
return submit(values, 'put')
22+
}
23+
24+
export function remove(values) {
25+
return submit(values, 'delete')
26+
}
27+
28+
function submit(values, method) {
1729
return dispatch => {
18-
axios.post(`${BASE_URL}/billingCycles`, values)
30+
const id = values._id ? values._id : ''
31+
axios[method](`${BASE_URL}/billingCycles/${id}`, values)
1932
.then(resp => {
2033
toastr.success('Sucesso', 'Operação Realizada com sucesso.')
2134
dispatch([
@@ -35,6 +48,30 @@ export function showUpdate(billingCycle) {
3548
return [
3649
showTabs('tabUpdate'),
3750
selectTab('tabUpdate'),
38-
initialize('billingCycleForm', billingCycle)
51+
select(billingCycle)
52+
]
53+
}
54+
55+
export function showDelete(billingCycle) {
56+
return [
57+
showTabs('tabDelete'),
58+
selectTab('tabDelete'),
59+
select(billingCycle)
60+
]
61+
}
62+
63+
export function select(billingCycle) {
64+
return {
65+
type: 'BILLING_CYCLE_SELECTED',
66+
payload: billingCycle
67+
}
68+
}
69+
70+
export function cancel() {
71+
return [
72+
showTabs('tabList', 'tabCreate'),
73+
selectTab('tabList'),
74+
resetForm('billingCycleForm'),
75+
{ type: 'BILLING_CYCLE_CANCELED' }
3976
]
4077
}
Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,41 @@
11
import React, { Component } from 'react'
2-
import { reduxForm, Field } from 'redux-form'
2+
import { connect } from 'react-redux'
3+
import { bindActionCreators } from 'redux'
4+
import { reduxForm, Field, initialize } from 'redux-form'
35
import labelAndInput from '../common/form/labelAndInput'
6+
import { cancel } from './billingCycleActions'
47

58
class BillingCycleForm extends Component {
69

10+
componentWillMount() {
11+
initialize('billingCycleForm', this.props.initialValues)
12+
}
13+
714
render() {
8-
const { handleSubmit } = this.props
15+
const { handleSubmit, readOnly } = this.props
916
return (
1017
<form role='form' onSubmit={handleSubmit}>
1118
<div className='box-body'>
12-
<Field name='name' component={labelAndInput}
19+
<Field name='name' component={labelAndInput} readOnly={readOnly}
1320
label='Nome' cols='12 4' placeholder='Informe o nome' />
14-
<Field name='month' component={labelAndInput} type='number'
21+
<Field name='month' component={labelAndInput} type='number' readOnly={readOnly}
1522
label='Mês' cols='12 4' placeholder='Informe o mês' />
16-
<Field name='year' component={labelAndInput} type='number'
23+
<Field name='year' component={labelAndInput} type='number' readOnly={readOnly}
1724
label='Ano' cols='12 4' placeholder='Informe o ano' />
1825
</div>
1926
<div className='box-footer'>
20-
<button type='submit' className='btn btn-primary'>Submit</button>
27+
<button type='submit' className={`btn btn-${this.props.submitClass}`}>
28+
{this.props.submitLabel}
29+
</button>
30+
<button type='button' className='btn btn-default'
31+
onClick={this.props.cancel}>Cancelar</button>
2132
</div>
2233
</form>
2334
)
2435
}
2536
}
2637

27-
export default reduxForm({form: 'billingCycleForm'})(BillingCycleForm)
38+
BillingCycleForm = reduxForm({form: 'billingCycleForm'})(BillingCycleForm)
39+
const mapStateToProps = state => ({initialValues: state.billingCycle.initialValues})
40+
const mapDispatchToProps = dispatch => bindActionCreators({cancel}, dispatch)
41+
export default connect(mapStateToProps, mapDispatchToProps)(BillingCycleForm)

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

Lines changed: 6 additions & 3 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, showUpdate } from './billingCycleActions'
4+
import { getList, showUpdate, showDelete } from './billingCycleActions'
55

66
class BillingCycleList extends Component {
77

@@ -20,6 +20,9 @@ class BillingCycleList extends Component {
2020
<button className='btn btn-warning' onClick={() => this.props.showUpdate(bc)}>
2121
<i className='fa fa-pencil'></i>
2222
</button>
23+
<button className='btn btn-danger' onClick={() => this.props.showDelete(bc)}>
24+
<i className='fa fa-trash-o'></i>
25+
</button>
2326
</td>
2427
</tr>
2528
))
@@ -34,7 +37,7 @@ class BillingCycleList extends Component {
3437
<th>Nome</th>
3538
<th>Mês</th>
3639
<th>Ano</th>
37-
<th>Ações</th>
40+
<th className='table-actions'>Ações</th>
3841
</tr>
3942
</thead>
4043
<tbody>
@@ -48,6 +51,6 @@ class BillingCycleList extends Component {
4851

4952
const mapStateToProps = state => ({list: state.billingCycle.list})
5053
const mapDispatchToProps = dispatch => bindActionCreators({
51-
getList, showUpdate
54+
getList, showUpdate, showDelete
5255
}, dispatch)
5356
export default connect(mapStateToProps, mapDispatchToProps)(BillingCycleList)

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
const INITIAL_STATE = {list: []}
1+
const INITIAL_STATE = {list: [], initialValues: {}}
22

33
export default (state = INITIAL_STATE, action) => {
44
switch (action.type) {
55
case 'BILLING_CYCLES_FETCHED':
66
return { ...state, list: action.payload.data }
7+
case 'BILLING_CYCLE_SELECTED':
8+
return { ...state, initialValues: action.payload }
9+
case 'BILLING_CYCLE_CANCELED':
10+
return { ...state, initialValues: INITIAL_STATE.initialValues }
711
default:
812
return state
913
}

my-money-app/frontend/src/common/template/custom.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,12 @@
22
position: fixed;
33
bottom:0px;
44
width:100%;
5+
}
6+
7+
button {
8+
margin-left: 5px;
9+
}
10+
11+
.table-actions {
12+
width: 150px;
513
}

0 commit comments

Comments
 (0)