Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. import { Link, withRouter } from 'react-router-dom';
  2. import { withFirebase, firebase, FirebaseContext, db } from '../../Firebase/firebase';
  3. import * as ROUTES from "../../../Constants/routes";
  4. import { compose } from 'recompose';
  5.  
  6. const SignUpPage = () => (
  7. <div>
  8. <h1>SignUp</h1>
  9. <SignUpForm/>
  10. </div>
  11. );
  12.  
  13. const INITIAL_STATE = {
  14. username: "",
  15. email: "",
  16. passwordOne: "",
  17. passwordTwo: "",
  18. error: null
  19. };
  20. class SignUpFormBase extends Component {
  21. constructor(props) {
  22. super(props);
  23. this.state = { ...INITIAL_STATE };
  24. }
  25.  
  26. onSubmit = event => {
  27. const { username, email, passwordOne } = this.state;
  28. this.props.firebase
  29. .doCreateUserWithEmailAndPassword(email, passwordOne)
  30. .then(authUser => {
  31. console.log("old sign up")
  32. return this.props.firebase
  33. .user(authUser.uid)
  34. .update({
  35. username,
  36. email,
  37. joinDate: new Date().toLocaleDateString("en-US"),
  38. accountType:'USER',
  39. userProfile:{paid:false, phyxes:{posture:{currentVideo:'video2'}}}
  40. });
  41. })
  42. .then(authUser => {
  43.  
  44. this.setState({ ...INITIAL_STATE });
  45. this.props.history.push(ROUTES.HOME);
  46. })
  47. .catch(error => {
  48. this.setState({ error });
  49. });
  50.  
  51. event.preventDefault();
  52. };
  53.  
  54. onChange = event => {
  55. this.setState({ [event.target.name]: event.target.value });
  56. };
  57.  
  58. render() {
  59. const {
  60. username,
  61. email,
  62. passwordOne,
  63. passwordTwo,
  64. error,
  65. } = this.state;
  66.  
  67. const isInvalid =
  68. passwordOne !== passwordTwo ||
  69. passwordOne === '' ||
  70. email === '' ||
  71. username === '';
  72.  
  73. return (
  74. <form onSubmit={this.onSubmit}>
  75. <input
  76. name="username"
  77. value={username}
  78. onChange={this.onChange}
  79. type="text"
  80. placeholder="Full Name"
  81. />
  82. <input
  83. name="email"
  84. value={email}
  85. onChange={this.onChange}
  86. type="text"
  87. placeholder="Email Address"
  88. />
  89. <input
  90. name="passwordOne"
  91. value={passwordOne}
  92. onChange={this.onChange}
  93. type="password"
  94. placeholder="Password"
  95. />
  96. <input
  97. name="passwordTwo"
  98. value={passwordTwo}
  99. onChange={this.onChange}
  100. type="password"
  101. placeholder="Confirm Password"
  102. />
  103. <button disabled={isInvalid} type="submit">Sign Up</button>
  104.  
  105. {error && <p>{error.message}</p>}
  106. </form>
  107. );
  108. }
  109. }
  110.  
  111. const SignUpLink = () => (
  112. <p>
  113. Don't have an account? <Link to={ROUTES.SIGN_UP}>Sign Up</Link>
  114. </p>
  115. );
  116. const SignUpForm = compose(
  117. withRouter,
  118. withFirebase,
  119. )(SignUpFormBase)
  120. export default SignUpPage;
  121. export { SignUpForm, SignUpLink };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement