Advertisement
Guest User

Untitled

a guest
Jul 12th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. @connect((store) => ({
  2. errors: store.adminLogin.error
  3. })
  4. class Login extends React.Component {
  5. constructor(props){
  6. super(props)
  7. this.state = {
  8. user:{
  9. email:'',
  10. password:''
  11. },
  12. };
  13. this.home = this.home.bind(this);
  14. this.onChange = this.onChange.bind(this);
  15. this.processForm = this.processForm.bind(this);
  16. }
  17.  
  18. home(){
  19. this.props.history.push('/')
  20. }
  21.  
  22. onChange(e){
  23. const user = this.state.user;
  24. const name = e.target.name;
  25. user[name] = e.target.value;
  26. this.setState({ user });
  27. }
  28.  
  29. processForm(event) {
  30. event.preventDefault();
  31.  
  32. // create a string for an HTTP body message
  33. const email = encodeURIComponent(this.state.user.email);
  34. const password = encodeURIComponent(this.state.user.password);
  35. const formData = `email=${email}&password=${password}`;
  36. this.props.dispatch(postLogin(formData));
  37. }
  38.  
  39. render() {
  40. return (
  41. <LoginCompo
  42. onSubmit={this.processForm}
  43. home={this.home}
  44. user={this.state.user}
  45. onChange={this.onChange}
  46. errors={this.props.errors}
  47. />
  48. );
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement