Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. export class UpdateGame extends Component {
  2. state = {
  3. updateId: '',
  4. updateName: " ",
  5. updatePrice: " " ,
  6. updateOnStock: " "
  7.  
  8. }
  9.  
  10. handleChangeId = ( event ) => {
  11. let idITextbox = event.target.value;
  12. this.setState({ updateId: idITextbox });
  13. }
  14.  
  15. handleChangeName = ( event ) => {
  16. let nameITextbox = event.target.value;
  17.  
  18. this.setState( { updateName: nameITextbox});
  19. }
  20.  
  21. componentDidMount() {
  22. if(this.props.match.params.id) {
  23. this.setState({updateId: this.props.match.params.id});
  24. }
  25. }
  26.  
  27. handleChangePrice = ( event ) => {
  28. let priceITextbox = event.target.value;
  29. this.setState( { updatePrice: priceITextbox});
  30. }
  31.  
  32. handleChangeOnStock = ( event ) => {
  33. let onStockITextbox = event.target.value;
  34. this.setState( { updateOnStock: onStockITextbox});
  35. }
  36.  
  37. updateNewGame = ( event ) => {
  38. event.preventDefault();
  39. let updateGame = {
  40. name: this.state.updateName,
  41. price: this.state.updatePrice,
  42. onstock: this.state.updateOnStock,
  43. id: this.state.updateId - 0
  44. };
  45.  
  46. axios.put(`https://localhost:5001/games/`, updateGame)
  47. .then(response => {
  48. console.log(response);
  49. console.log(response.data);
  50. this.props.history.push("/deletegame");
  51. })
  52. }
  53.  
  54. render(){
  55. return (
  56. <section>
  57. <center><h3>Update Game</h3></center>
  58. <form onSubmit = { this.updateNewGame }>
  59. <ul class="sub-menu" type="none">
  60. <label>Update name of the game</label>
  61. <li><input onChange={ this.handleChangeName } type="text" value={ this.state.updateName} /></li>
  62. <label>Update price</label>
  63. <li><input onChange={ this.handleChangePrice } type="number" min="1" max="1000" value={ this.state.updatePrice} /></li>
  64. <p></p>
  65. <label>Update onstock by Available/Not Available</label>
  66. <li> <input onChange={ this.handleChangeOnStock } type="text" value={ this.state.updateOnStock} /></li>
  67. <p></p>
  68. <li> <button type="submit">Update</button></li>
  69. </ul>
  70. </form>
  71. </section>
  72. )
  73.  
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement