Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { Field, reduxForm } from 'redux-form';
  4. import { Link } from 'react-router';
  5. import { css, StyleSheet } from 'aphrodite';
  6. import Input from '../Input';
  7.  
  8. const styles = StyleSheet.create({
  9. card: {
  10. maxWidth: '500px',
  11. padding: '3rem 4rem',
  12. margin: '2rem auto',
  13. },
  14. });
  15.  
  16. type Props = {
  17. onSubmit: () => void,
  18. submitting: boolean,
  19. handleSubmit: () => void,
  20. }
  21.  
  22. class SignupForm extends Component {
  23. props: Props
  24.  
  25. handleSubmit = data => this.props.onSubmit(data);
  26.  
  27. render() {
  28. const { handleSubmit, submitting } = this.props;
  29.  
  30. return (
  31. <form
  32. className={`card ${css(styles.card)}`}
  33. onSubmit={handleSubmit(this.handleSubmit)}
  34. >
  35. <h3 style={{ marginBottom: '2rem', textAlign: 'center' }}>Create an account</h3>
  36. <Field
  37. name="username"
  38. type="text"
  39. component={Input}
  40. placeholder="Username"
  41. className="form-control"
  42. />
  43. <Field
  44. name="email"
  45. type="email"
  46. component={Input}
  47. placeholder="Email"
  48. className="form-control"
  49. />
  50. <Field
  51. name="password"
  52. type="password"
  53. component={Input}
  54. placeholder="Password"
  55. className="form-control"
  56. />
  57. <button
  58. type="submit"
  59. disabled={submitting}
  60. className="btn btn-block btn-primary"
  61. >
  62. {submitting ? 'Submitting...' : 'Sign up'}
  63. </button>
  64. <hr style={{ margin: '2rem 0' }} />
  65. <Link to="/login" className="btn btn-block btn-secondary">
  66. Login to your account
  67. </Link>
  68. </form>
  69. );
  70. }
  71. }
  72.  
  73. const validate = (values) => {
  74. const errors = {};
  75. if (!values.username) {
  76. errors.username = 'Required';
  77. }
  78. if (!values.email) {
  79. errors.email = 'Required';
  80. }
  81. if (!values.password) {
  82. errors.password = 'Required';
  83. } else if (values.password.length < 6) {
  84. errors.password = 'Minimum of 6 characters';
  85. }
  86. return errors;
  87. };
  88.  
  89. export default reduxForm({
  90. form: 'signup',
  91. validate,
  92. })(SignupForm);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement