-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEdit.js
84 lines (77 loc) · 1.89 KB
/
Edit.js
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
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import injectSheet from 'react-jss';
import { Formik } from 'formik';
import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
import DialogTitle from '@material-ui/core/DialogTitle';
import Button from 'material-ui/Button';
import AddOrEdit from './AddOrEdit';
const styles = {
appBar: {
position: 'relative',
},
flex: {
flex: 1,
},
input: {
margin: 5,
},
form: {
display: 'grid',
gridTemplateColumns: 'auto',
gridTemplateRows: 'auto',
gridTemplateAreas: "'label' 'currency' 'people'",
},
formControl: {
margin: 5,
minWidth: 120,
},
};
const Edit = ({ spending, updateSpending, handleClose, classes }) => {
console.log(spending);
return (
<Formik
initialValues={{
...spending,
}}
validate={values => {
let errors = {};
if (!values.label) {
errors.label = 'Name is required';
}
return errors;
}}
onSubmit={values => {
const newSpending = {
...values,
};
updateSpending(newSpending);
handleClose();
}}
render={({ handleSubmit }) => (
<Fragment>
<DialogTitle>Edit the form</DialogTitle>
<DialogContent>
<AddOrEdit classes={classes} />
</DialogContent>
<DialogActions>
<Button onClick={handleClose} color="primary">
Cancel
</Button>
<Button onClick={handleSubmit} color="primary">
Ok
</Button>
</DialogActions>
</Fragment>
)}
/>
);
};
Edit.propTypes = {
spending: PropTypes.object,
updateSpending: PropTypes.func,
handleClose: PropTypes.func,
classes: PropTypes.object,
};
export default injectSheet(styles)(Edit);