Advertisement
Guest User

Untitled

a guest
Feb 12th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, {Component} from 'react';
  2. import { withStyles } from 'material-ui/styles';
  3. import classNames from 'classnames';
  4. import { Link } from 'react-router-dom'
  5. import UserRegisterComponent from '../Components/UserRegisterComponent'
  6. import UserListComponent from '../Components/UserListComponent'
  7. import axios from 'axios';
  8. import { withRouter } from 'react-router-dom'
  9.  
  10. const styles = {
  11.  
  12.  
  13. };
  14.  
  15.  
  16. class UserPage extends Component{
  17.   state = {
  18.     userInfoList: [],
  19.   }
  20.  
  21.   onRegisterSubmit = (event)=> {
  22.     event.preventDefault();
  23.     const username =event.target.username.value;
  24.     const firstName =event.target.firstName.value;
  25.     const lastName =event.target.lastName.value;
  26.     const password =event.target.password.value;
  27.     const userRoleId =event.target.userRoleId.value;
  28.     const  objectForSend={
  29.              firstName,
  30.               username,
  31.               lastName,
  32.               password,
  33.               userRoleId
  34.             };
  35.      axios.post('http://localhost:4000/users', objectForSend )
  36.    .then((response)=> {
  37.      console.log("onSucces");
  38.      this.users()
  39.    })
  40.    .catch(function (error) {
  41.      console.log(error);
  42.    });
  43.  
  44.   }
  45.   users=()=>{
  46.     console.log(this.state);
  47.     axios.get('http://localhost:4000/users')
  48.     .then(resp=>{
  49.       console.log(this.state);
  50.       this.setState({userInfoList:resp.data},()=>{
  51.         console.log(this.state);
  52.       });
  53.     }).catch(err=>{
  54.       console.log(err);
  55.     });
  56.   }
  57.  // users = ()=> {
  58.  //      console.log("Intra in showUsers");
  59.  //     axios.get('http://localhost:4000/users' )
  60.  //   .then(function (response) {
  61.  //     console.log("response",response);
  62.  //     this.setState({userInfoList:response.data},()=> console.log('asd'))
  63.  //   })
  64.  //   .catch(function (error) {
  65.  //     console.log(error);
  66.  //   });
  67.  //  }
  68.  
  69.  render() {
  70.  
  71.   return (
  72.       <center>
  73.     <div >
  74.  
  75.   <UserRegisterComponent onRegisterUserSubmit = {this.onRegisterSubmit} />
  76.   <UserListComponent/>
  77.  
  78.     </div>
  79.       </center>
  80.  
  81.   );
  82. }
  83. }
  84.  
  85.  
  86. export default withStyles(styles)(withRouter(UserPage));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement