Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. import {Component} from 'react';
  2. import {Button, Form, Message} from 'semantic-ui-react';
  3. import {signUp} from '../../actions/auth';
  4.  
  5. class SignUp extends Component {
  6. constructor(props) {
  7. super(props);
  8. this.handleSubmit = this.handleSubmit.bind(this);
  9. }
  10. handleSubmit(e, {formData}) {
  11. e.preventDefault();
  12.  
  13. //
  14. // Potentially need to manually validate fields here?
  15. //
  16.  
  17. // Send a POST request to the server with the formData
  18. this.props.dispatch(signUp(formData)).then(({isAuthenticated}) => {
  19. if (isAuthenticated) {
  20. // Redirect to the home page if the user is authenticated
  21. this.props.router.push('/');
  22. }
  23. }
  24. }
  25. render() {
  26. const {err} = this.props;
  27.  
  28. return (
  29. <Form onSubmit={this.handleSubmit}>
  30. <Form.Input label="Email" name="email" type="text"/>
  31. <Form.Input label="Password" name="password" type="password"/>
  32. <Form.Input label="Confirm Password" name="confirmPassword" type="password"/>
  33.  
  34. {err &&
  35. <Message header="Error" content={err.message} error/>
  36. }
  37.  
  38. <Button size="huge" type="submit" primary>Sign Up</Button>
  39. </Form>
  40. );
  41. }
  42. }
  43.  
  44. $('.ui.form').form({
  45. fields: {
  46. email: {
  47. identifier: 'email',
  48. rules: [{
  49. type: 'empty',
  50. prompt: 'Please enter your email address'
  51. }, {
  52. type: 'regExp',
  53. value: "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?",
  54. prompt: 'Please enter a valid email address'
  55. }]
  56. },
  57. password: {
  58. identifier: 'password',
  59. rules: [{
  60. type: 'empty',
  61. prompt: 'Please enter your password'
  62. }, {
  63. type: 'minLength[8]',
  64. prompt: 'Your password must be at least {ruleValue} characters'
  65. }]
  66. },
  67. confirmPassword: {
  68. identifier: 'confirmPassword',
  69. rules: [{
  70. type: 'match[password]',
  71. prompt: 'The password you provided does not match'
  72. }]
  73. }
  74. }
  75. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement