Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <ButtonToolbar>
  2.                   <Button
  3.                     bsStyle="danger"
  4.                     onClick={e => {
  5.                       props.deleteRecipe(index);
  6.                     }}
  7.                   >
  8.                     Delete
  9.                   </Button>
  10.                   <EditRecipe
  11.                     currentRecipe={index}
  12.                     recipes={props.recipes}
  13.                     handleEditName={props.handleEditName}
  14.                     handleEditProduct={props.handleEditProduct}
  15.                   />
  16.                 </ButtonToolbar>
  17.  
  18.  
  19.  
  20. class EditRecipe extends React.Component {
  21.   constructor(props) {
  22.     super(props);
  23.  
  24.     this.state = {
  25.       showModal: false
  26.     };
  27.     this.handleShow = this.handleShow.bind(this);
  28.     this.handleClose = this.handleClose.bind(this);
  29.   }
  30.  
  31.   handleClose() {
  32.     this.setState({ showModal: false });
  33.   }
  34.  
  35.   handleShow() {
  36.     this.setState({ showModal: true });
  37.   }
  38.  
  39.   editName(i, event) {
  40.     this.props.handleEditName(i, event);
  41.   }
  42.  
  43.   editProduct(i, event) {
  44.     this.props.handleEditProduct(i, event);
  45.   }
  46.  
  47.   render() {
  48.     let id = this.props.currentRecipe;
  49.     let recipes = this.props.recipes[id];
  50.     console.log(recipes);
  51.  
  52.     return (
  53.       <div>
  54.         <Button bsStyle="primary" bsSize="medium" onClick={this.handleShow}>
  55.           Edit Recipe
  56.         </Button>
  57.         <Modal show={this.state.showModal} onHide={this.handleClose}>
  58.           <Modal.Header closeButton>
  59.             <Modal.Title>Edit Recipe</Modal.Title>
  60.           </Modal.Header>
  61.           <form onSubmit={this.props.onSubmit}>
  62.             <Modal.Body>
  63.               <FormGroup controlId="RecipeName">
  64.                 <ControlLabel>Recipe</ControlLabel>
  65.                 <FormControl
  66.                   type="text"
  67.                   placeholder="Recipe Name"
  68.                   value={recipes.name}
  69.                   onChange={this.editName.bind(this, id)}
  70.                 />
  71.               </FormGroup>
  72.               <FormGroup controlId="formControlsTextarea">
  73.                 <ControlLabel>Products</ControlLabel>
  74.                 {recipes.products.map((product, id) => {
  75.                   return (
  76.                     <FormControl
  77.                       key={product + "_" + id}
  78.                       type="text"
  79.                       value={product}
  80.                       onChange={this.editProduct.bind(this, id)}
  81.                       placeholder={"Product " + (id + 1)}
  82.                     />
  83.                   );
  84.                 })}
  85.               </FormGroup>
  86.               <Button onClick={this.props.addInput}>Add Product</Button>
  87.             </Modal.Body>
  88.             <Modal.Footer>
  89.               <Button bsStyle="success" type="submit">
  90.                 Next station: Kitchen
  91.               </Button>
  92.               <Button onClick={this.handleClose}>Close</Button>
  93.             </Modal.Footer>
  94.           </form>
  95.         </Modal>
  96.       </div>
  97.     );
  98.   }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement