1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import {
fetchAction,
addAction,
closeAction,
submitAction,
removeAction,
editAction,
closeNotifAction
} from 'ba-actions/CrudTbFrmActions';
import { CrudTableForm2, Notification } from 'ba-components';
import {
Paper,
RadioGroup,
} from '@material-ui/core';
import { anchorTable, dataApi } from './sampleData';
import FormPedido from './FormPedido';
//actions
import { getPedidos } from '../../../../actions/pedido';
const branch = 'crudPedido';
const renderRadioGroup = ({ input, ...rest }) => (
<RadioGroup
{...input}
{...rest}
valueselected={input.value}
onChange={(event, value) => input.onChange(value)}
/>
);
const styles = ({
root: {
flexGrow: 1,
}
});
class CrudPedido extends Component {
render() {
//console.log("render ps")
const {
classes,
fetchData,
addNew,
closeForm,
submit,
removeRow,
editRow,
dataTable,
openForm,
initValues,
closeNotif,
messageNotif,
title,
dataReal,
dispatch,
editingId
} = this.props;
//console.log("render ps DATA", dataReal)
//console.log("original", dataApi)
return (
<div>
<Notification close={() => closeNotif(branch)} variant = "success" message={messageNotif} />
<Paper className={classes.root}>
<CrudTableForm2
dataTable={dataTable}
openForm={openForm}
dataInit={dataReal}
anchor={anchorTable}
title={title}
fetchData={fetchData}
addNew={addNew}
closeForm={closeForm}
submit={submit}
removeRow={removeRow}
editRow={editRow}
branch={branch}
initValues={initValues}
addNewAPI={getPedidos}
removeRowAPI={getPedidos}
editRowAPI={getPedidos}
dispatch = {dispatch}
editingId = {editingId}
>
{/* Create Your own form, then arrange or custom it as You like */}
<FormPedido/>
{/* No need create button or submit, because that already made in this component */}
</CrudTableForm2>
</Paper>
</div>
);
}
}
renderRadioGroup.propTypes = {
input: PropTypes.object.isRequired,
};
CrudPedido.propTypes = {
dataTable: PropTypes.object.isRequired,
openForm: PropTypes.bool.isRequired,
classes: PropTypes.object.isRequired,
fetchData: PropTypes.func.isRequired,
addNew: PropTypes.func.isRequired,
closeForm: PropTypes.func.isRequired,
submit: PropTypes.func.isRequired,
removeRow: PropTypes.func.isRequired,
editRow: PropTypes.func.isRequired,
initValues: PropTypes.object.isRequired,
closeNotif: PropTypes.func.isRequired,
messageNotif: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
};
const mapStateToProps = state => ({
force: state, // force state from reducer
initValues: state.getIn([branch, 'formValues']),
dataTable: state.getIn([branch, 'dataTable']),
openForm: state.getIn([branch, 'showFrm']),
messageNotif: state.getIn([branch, 'notifMsg']),
editingId: state.getIn([branch, 'editingId']),
pedidosLista : state.getIn(['pedido','pedidos']),
});
const mapDispatchToProps = dispatch => ({
fetchData: bindActionCreators(fetchAction, dispatch),
addNew: bindActionCreators(addAction, dispatch),
closeForm: bindActionCreators(closeAction, dispatch),
submit: bindActionCreators(submitAction, dispatch),
removeRow: bindActionCreators(removeAction, dispatch),
editRow: bindActionCreators(editAction, dispatch),
closeNotif: bindActionCreators(closeNotifAction, dispatch),
dispatch
});
const CrudPedidoMapped = connect(
mapStateToProps,
mapDispatchToProps
)(CrudPedido);
export default withStyles(styles)(CrudPedidoMapped);
|