Advertisement
Guest User

Untitled

a guest
May 11th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. import React, { Component } from 'react';
  2.  
  3. class SignupPage extends Component {
  4. constructor(props) {
  5. super(props);
  6. this.state = {
  7. user_name: "",
  8. email: "",
  9. password: ""
  10. }
  11. }
  12.  
  13.  
  14. componentDidUpdate(prevProps, prevState) {
  15. if(this.props.hasErrors && prevProps.isAuthenticating){
  16. displayErrors(this.props.errors, this.props.alert);
  17. } else if(this.props.isAuthenticated) {
  18. this.props.history.push('/');
  19. }
  20. }
  21.  
  22. handleOnChange = event => {
  23. this.setState({
  24. [event.target.name]: event.target.value
  25. })
  26. }
  27.  
  28. handleSubmit = event => {
  29. event.preventDefault();
  30. this.setState({
  31. user_name: this.state.user_name,
  32. email: this.state.email,
  33. password: this.state.password
  34. })
  35. const newUser = this.state;
  36. this.props.signupUser(newUser);
  37. this.setState({
  38. user_name: '',
  39. email: '',
  40. password: ''
  41. });
  42. }
  43.  
  44. render() {
  45. return (
  46. <div className='signupInput'>
  47.  
  48. <form id='signup-form' onSubmit={event => this.handleSubmit(event)} >
  49. <div id='signup-title'><h1>SIGN UP</h1></div>
  50. <div id='signup-form-div'>
  51. <input id='signup-user_name' onChange={event => this.handleOnChange(event)} name='user_name' type='text' value={this.state.user_name}
  52. placeholder='User Name'/>
  53.  
  54.  
  55. <input id='signup-email' onChange={event => this.handleOnChange(event)} name='email' type='text' value={this.state.email} placeholder='Email'/>
  56.  
  57.  
  58. <input id='signup-password' onChange={event => this.handleOnChange(event)} name='password' type='password' value={this.state.password} placeholder='Password' />
  59. </div>
  60. <input className='signup-user-btn' type='submit' value='SUBMIT'/>
  61. </form>
  62. </div>
  63. )
  64. }
  65. }
  66.  
  67. export default SignupPage;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement