Guest User

Untitled

a guest
Feb 24th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. class SignupComponent extends Component {
  2. constructor (props) {
  3. super(props)
  4. this.state = {
  5. name: '',
  6. username: '',
  7. email: '',
  8. phone_number: '',
  9. password: '',
  10. smsVerificationCode: '',
  11. emailVerificationCode: '',
  12. loading: false,
  13. signup: false,
  14. showVerification: false,
  15. }
  16. }
  17.  
  18. changeName(e) { this.setState({ name: e.target.value }) }
  19.  
  20. blurUsername () {
  21. this.setState({usernameTouched: true, usernameError: usernamePolicy(this.state.username)})
  22. }
  23. changeUsername (e) {
  24. this.setState({ username: e.target.value })
  25. if(this.state.usernameTouched)
  26. this.setState({usernameError: usernamePolicy(this.state.username)})
  27. }
  28.  
  29. blurEmail () {
  30. this.setState({emailTouched: true, emailError: emailPolicy(this.state.email)})
  31. }
  32. changeEmail (e) {
  33. this.setState({ email: e.target.value })
  34. if(this.state.emailTouched)
  35. this.setState({emailError: emailPolicy(this.state.email)})
  36. }
  37.  
  38. blurPassword () {
  39. this.setState({passwordTouched: true, passwordError: passwordPolicy(this.state.password)})
  40. }
  41. changePassword (e) {
  42. this.setState({ password: e.target.value })
  43. if(this.state.passwordTouched)
  44. this.setState({passwordError: passwordPolicy(this.state.password)})
  45. }
  46.  
  47. blurPhone_Number () {
  48. this.setState({phone_numberTouched: true, phone_numberError: phone_numberPolicy(this.state.phone_number)})
  49. }
  50. changePhone_Number (e) {
  51. this.setState({ phone_number: e.target.value })
  52. if(this.state.phone_numberTouched)
  53. this.setState({phone_numberError: phone_numberPolicy(this.state.phone_number)})
  54. }
  55.  
  56. changeSMSverificationCode (e) { this.setState({ smsVerificationCode: e.target.value }) }
  57.  
  58. handleSignupSubmit (e) {
  59. e.preventDefault()
  60. const {dispatch} = this.props
  61. dispatch(userActions.signup(this.state.name, this.state.username, this.state.email, this.state.phone_number, this.state.password))
  62. }
  63.  
  64. handleVerifySMSsubmit (e) {
  65. e.preventDefault()
  66. const {dispatch} = this.props
  67. dispatch(userActions.verifyPhone(this.state.username, this.state.password, this.state.smsVerificationCode))
  68. }
  69.  
  70. submissionValid (e) {
  71. return (this.state.name.length > 0 && this.state.username.length > 0 && this.state.email.length > 0 && this.state.phone_number.length > 0 && this.state.password.length > 0 && !this.state.passwordError && !this.state.phone_numberError && !this.state.passwordError)
  72. }
  73.  
  74. render () {
  75. return (
  76. <div>
  77. <form onSubmit={this.handleSignupSubmit} autoComplete="off">
  78. <h2>Sign Up</h2>
  79. <div className="fieldsContainer">
  80. <TextField
  81. hintText="Name"
  82. value={this.state.name}
  83. onChange={this.changeName}
  84. errorStyle={errorStyle}
  85. autoFocus={'autofocus'}
  86. required />
  87.  
  88. <TextField
  89. style={{height: 55}}
  90. hintText="Username"
  91. value={this.state.username}
  92. onChange={this.changeUsername}
  93. onBlur={this.blurUsername}
  94. errorText={this.state.usernameError}
  95. errorStyle={errorStyle}
  96. required />
  97.  
  98. <TextField
  99. style={{height: 55}}
  100. type="email"
  101. hintText="Email"
  102. value={this.state.email}
  103. onChange={this.changeEmail}
  104. onBlur={this.blurEmail}
  105. errorText={this.state.emailError}
  106. errorStyle={errorStyle}
  107. required />
  108.  
  109. <TextField
  110. style={{height: 55}}
  111. type="number"
  112. hintText="Phone Number"
  113. value={this.state.phone_number}
  114. onChange={this.changePhone_Number}
  115. onBlur={this.blurPhone_Number}
  116. errorText={this.state.phone_numberError}
  117. errorStyle={errorStyle}
  118. required />
  119. <TextField
  120. style={{height: 55}}
  121. type="password"
  122. hintText="Password"
  123. value={this.state.password}
  124. onChange={this.changePassword}
  125. onBlur={this.blurPassword}
  126. errorText={this.state.passwordError}
  127. errorStyle={errorStyle}
  128. required />
  129.  
  130. <RaisedButton
  131. type="submit"
  132. label="Sign Up"
  133. className="submitButton"
  134. primary={true}
  135. disabled={!this.submissionValid()} />
  136.  
  137. <CircularProgress
  138. style={{position: 'absolute', padding: '27px 5px'}}
  139. size={20}
  140. hidden={!this.props.signingup}/>
  141. </div>
  142. </form>
  143. </div>
  144. )
  145. }
  146. }
Add Comment
Please, Sign In to add comment