Advertisement
Guest User

Untitled

a guest
Nov 26th, 2016
76
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, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. import * as actions from '../../actions';
  4. import { Field, reduxForm } from 'redux-form';
  5. import InputField from '../input-field/index.js';
  6.  
  7. class Signup extends Component {
  8. handleFormSubmit(formProps) {
  9. // PROBLEM -> Uncaught TypeError: this.props.signupUser is not a function
  10. this.props.signupUser(formProps);
  11. }
  12.  
  13. render() {
  14. const { handleSubmit, submitting } = this.props;
  15.  
  16. return (
  17. <form onSubmit={ handleSubmit(this.handleFormSubmit.bind(this)) } >
  18. <Field name="username" type="text" component={ InputField } label="Username" />
  19. <Field name="email" type="email" component={ InputField } label="Email" />
  20. <Field name="password" type="password" component={ InputField } label="Password" />
  21. <Field name="password_confirmation" type="password" component={ InputField } label="Confirmation" />
  22. <div>
  23. <button type="submit" disabled={ submitting }>Submit</button>
  24. </div>
  25. </form>
  26. );
  27. }
  28. }
  29.  
  30. function mapStateToProps({ auth }) {
  31. return { errorMessage: auth.errors };
  32. }
  33.  
  34. export default reduxForm({
  35. form: 'signup',
  36. warn,
  37. validate
  38. }, mapStateToProps, actions)(Signup);
  39.  
  40. export function signupUser(props) {
  41. return dispatch => {
  42. axios.post(`${apiRoot}users`, { user: { ...props } })
  43. .then(response => {
  44. const { status, errors, access_token, username } = response.data;
  45.  
  46. if (status === 'created') {
  47. // handler
  48. }
  49. else {
  50. dispatch(authError(errors));
  51. }
  52. })
  53. .catch(err => dispatch(authError(err.message)));
  54. }
  55. }
  56.  
  57. class Signup extends Component {
  58. handleFormSubmit(formProps) {
  59. this.props.signupUser(formProps);
  60. }
  61.  
  62. render() {
  63. const {
  64. handleSubmit,
  65. fields: {
  66. email,
  67. password,
  68. password_confirmation,
  69. username,
  70. }
  71. } = this.props;
  72.  
  73. return (
  74. <form onSubmit={handleSubmit(this.handleFormSubmit.bind(this))}>
  75. <fieldset className="form-group">
  76. <label>Username:</label>
  77. <input className="form-control" {...username} />
  78. {username.touched && username.error && <div className="error">{username.error}</div>}
  79. </fieldset>
  80. <fieldset className="form-group">
  81. <label>Email:</label>
  82. <input className="form-control" {...email} />
  83. {email.touched && email.error && <div className="error">{email.error}</div>}
  84. </fieldset>
  85. <fieldset className="form-group">
  86. <label>Password:</label>
  87. <input type="password" className="form-control" {...password} />
  88. {password.touched && password.error && <div className="error">{password.error}</div>}
  89. </fieldset>
  90. <fieldset className="form-group">
  91. <label>Confirm Password:</label>
  92. <input type="password" className="form-control" {...password_confirmation} />
  93. {password_confirmation.touched && password_confirmation.error && <div className="error">{password_confirmation.error}</div>}
  94. </fieldset>
  95. <button action="submit">Sign up</button>
  96. </form>
  97. );
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement