Commit d60030a1 authored by Martin Fahl's avatar Martin Fahl
Browse files

refactors onChange calls

parent 42dfaf41
import React from "react"; import React from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import {Button, TextField, Dialog, DialogActions, DialogContent, DialogTitle, Grid } from '@material-ui/core/'; import {Button, TextField, Dialog, DialogActions, DialogContent, DialogTitle, Grid } from '@material-ui/core/';
const AddDialog = ({ name, quantity, isOpen, handleClose, handleCancel, handleAdd, updateName, updateQuantity }) => ( const AddDialog = ({ name, quantity, isOpen, handleClose, handleCancel, handleAdd, updateName, updateQuantity }) => (
<Dialog <Dialog
open={isOpen} open={isOpen}
...@@ -19,7 +19,7 @@ const AddDialog = ({ name, quantity, isOpen, handleClose, handleCancel, handleAd ...@@ -19,7 +19,7 @@ const AddDialog = ({ name, quantity, isOpen, handleClose, handleCancel, handleAd
id="name" id="name"
label="Name" label="Name"
type="string" type="string"
onChange={updateName} onChange={(event) => updateName(event.target.value)}
/> />
</Grid> </Grid>
<Grid item> <Grid item>
...@@ -28,7 +28,8 @@ const AddDialog = ({ name, quantity, isOpen, handleClose, handleCancel, handleAd ...@@ -28,7 +28,8 @@ const AddDialog = ({ name, quantity, isOpen, handleClose, handleCancel, handleAd
id="quantity" id="quantity"
label="Quantity" label="Quantity"
type="number" type="number"
onChange={updateQuantity} value={quantity}
onChange={(event) => updateQuantity(event.target.value)}
/> />
</Grid> </Grid>
</Grid> </Grid>
...@@ -52,6 +53,6 @@ AddDialog.propTypes = { ...@@ -52,6 +53,6 @@ AddDialog.propTypes = {
handleClose: PropTypes.func.isRequired, handleClose: PropTypes.func.isRequired,
handleCancel: PropTypes.func.isRequired, handleCancel: PropTypes.func.isRequired,
handleAdd: PropTypes.func.isRequired handleAdd: PropTypes.func.isRequired
}; }
export default AddDialog export default AddDialog
\ No newline at end of file
...@@ -43,8 +43,8 @@ const mapDispatchToProps = (dispatch) => ({ ...@@ -43,8 +43,8 @@ const mapDispatchToProps = (dispatch) => ({
handleClose: () => dispatch(closeAddDialog()), handleClose: () => dispatch(closeAddDialog()),
handleCancel: () => dispatch(closeAddDialog()), handleCancel: () => dispatch(closeAddDialog()),
handleAdd: (name, quantity) => handleAdd(name, quantity, dispatch), handleAdd: (name, quantity) => handleAdd(name, quantity, dispatch),
updateName: event => dispatch(updateAddDialogName(event.target.value)), updateName: newName => dispatch(updateAddDialogName(newName)),
updateQuantity: event => dispatch(updateAddDialogQuantity(Number(event.target.value))) updateQuantity: newQuantity => dispatch(updateAddDialogQuantity(Number(newQuantity)))
}) })
export default connect( export default connect(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment