Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {Component} from 'react';
- import {Button, Form, Message} from 'semantic-ui-react';
- import {signUp} from '../../actions/auth';
- class SignUp extends Component {
- constructor(props) {
- super(props);
- this.handleSubmit = this.handleSubmit.bind(this);
- }
- handleSubmit(e, {formData}) {
- e.preventDefault();
- //
- // Potentially need to manually validate fields here?
- //
- // Send a POST request to the server with the formData
- this.props.dispatch(signUp(formData)).then(({isAuthenticated}) => {
- if (isAuthenticated) {
- // Redirect to the home page if the user is authenticated
- this.props.router.push('/');
- }
- }
- }
- render() {
- const {err} = this.props;
- return (
- <Form onSubmit={this.handleSubmit}>
- <Form.Input label="Email" name="email" type="text"/>
- <Form.Input label="Password" name="password" type="password"/>
- <Form.Input label="Confirm Password" name="confirmPassword" type="password"/>
- {err &&
- <Message header="Error" content={err.message} error/>
- }
- <Button size="huge" type="submit" primary>Sign Up</Button>
- </Form>
- );
- }
- }
- $('.ui.form').form({
- fields: {
- email: {
- identifier: 'email',
- rules: [{
- type: 'empty',
- prompt: 'Please enter your email address'
- }, {
- type: 'regExp',
- 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])?",
- prompt: 'Please enter a valid email address'
- }]
- },
- password: {
- identifier: 'password',
- rules: [{
- type: 'empty',
- prompt: 'Please enter your password'
- }, {
- type: 'minLength[8]',
- prompt: 'Your password must be at least {ruleValue} characters'
- }]
- },
- confirmPassword: {
- identifier: 'confirmPassword',
- rules: [{
- type: 'match[password]',
- prompt: 'The password you provided does not match'
- }]
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement