Guest User

Untitled

a guest
Apr 1st, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. import React from 'react'
  2. import { css } from 'glamor'
  3. import { withRouter } from 'react-router-dom'
  4.  
  5. import { Auth } from 'aws-amplify'
  6.  
  7. class SignUp extends React.Component {
  8. state = {
  9. username: '',
  10. password: '',
  11. email: '',
  12. phone_number: '',
  13. authCode: '',
  14. showConfirmation: false
  15. }
  16. onChange = (key, value) => {
  17. this.setState({
  18. [key]: value
  19. })
  20. }
  21. signUp = () => {
  22. const { username, password, email, phone_number } = this.state
  23. Auth.signUp({
  24. username,
  25. password,
  26. attributes: {
  27. email,
  28. phone_number
  29. }
  30. })
  31. .then(() => this.setState({ showConfirmation: true }))
  32. .catch(err => console.log('error signing up: ', err))
  33. }
  34. confirmSignUp = () => {
  35. Auth.confirmSignUp(this.state.username, this.state.authCode)
  36. .then(() => this.props.history.push('/'))
  37. .catch(err => console.log('error confirming signing up: ', err))
  38. }
  39. render() {
  40. const { showConfirmation } = this.state
  41. return (
  42. <div {...css(styles.container)}>
  43. {
  44. !showConfirmation && (
  45. <div {...css(styles.container)}>
  46. <input
  47. {...css(styles.input)}
  48. placeholder='Username'
  49. onChange={evt => this.onChange('username', evt.target.value)}
  50. />
  51. <input
  52. {...css(styles.input)}
  53. placeholder='Password'
  54. type='password'
  55. onChange={evt => this.onChange('password', evt.target.value)}
  56. />
  57. <input
  58. {...css(styles.input)}
  59. placeholder='Email'
  60. onChange={evt => this.onChange('email', evt.target.value)}
  61. />
  62. <input
  63. {...css(styles.input)}
  64. placeholder='Phone Number'
  65. onChange={evt => this.onChange('phone_number', evt.target.value)}
  66. />
  67. <div {...css(styles.button)} onClick={this.signUp}>
  68. <p {...css(styles.buttonText)}>Sign Up</p>
  69. </div>
  70. </div>
  71. )
  72. }
  73. {
  74. showConfirmation && (
  75. <div>
  76. <input
  77. onChange={evt => this.onChange('authCode', evt.target.value)}
  78. {...css(styles.input)}
  79. placeholder='Confirmation Code'
  80. />
  81. <div {...css(styles.button)} onClick={this.confirmSignUp}>
  82. <p {...css(styles.buttonText)}>Confirm Sign Up</p>
  83. </div>
  84. </div>
  85. )
  86. }
  87. </div>
  88. )
  89. }
  90. }
  91.  
  92. const styles = {
  93. button: {
  94. padding: '10px 60px',
  95. backgroundColor: '#ddd',
  96. cursor: 'pointer',
  97. borderRadius: '3px',
  98. ':hover': {
  99. backgroundColor: '#ededed'
  100. }
  101. },
  102. buttonText: {
  103. margin: 0
  104. },
  105. container: {
  106. flex: 1,
  107. display: 'flex',
  108. alignItems: 'center',
  109. justifyContent: 'center',
  110. flexDirection: 'column',
  111. paddingTop: '15px'
  112. },
  113. input: {
  114. height: 40,
  115. marginBottom: '10px',
  116. border: 'none',
  117. outline: 'none',
  118. borderBottom: '2px solid #4CAF50',
  119. fontSize: '16px',
  120. '::placeholder': {
  121. color: 'rgba(0, 0, 0, .3)'
  122. }
  123. },
  124. }
  125.  
  126. export default withRouter(SignUp)
Add Comment
Please, Sign In to add comment