Blame view

imports/modules/signup.js 1.52 KB
7df77f0fa   tmcdeveloper   finish wiring up ...
1
2
3
4
  import { browserHistory } from 'react-router';
  import { getInputValue } from './get-input-value';
  
  let component;
f0c912bf1   tmcdeveloper   add method tests ...
5
6
7
8
9
10
11
12
13
14
  const _getUserData = () => ({
    email: getInputValue(component, 'emailAddress', true),
    password: getInputValue(component, 'password', true),
    profile: {
      name: {
        first: getInputValue(component, 'firstName', true),
        last: getInputValue(component, 'lastName', true),
      },
    },
  });
7df77f0fa   tmcdeveloper   finish wiring up ...
15
16
17
  
  const _handleSignup = () => {
    const user = _getUserData();
f0c912bf1   tmcdeveloper   add method tests ...
18
19
20
    Accounts.createUser(user, (error) => {
      if (error) {
        Bert.alert(error.reason, 'danger');
7df77f0fa   tmcdeveloper   finish wiring up ...
21
      } else {
f0c912bf1   tmcdeveloper   add method tests ...
22
23
        browserHistory.push('/');
        Bert.alert('Welcome!', 'success');
7df77f0fa   tmcdeveloper   finish wiring up ...
24
25
26
27
28
      }
    });
  };
  
  const _validate = () => {
f0c912bf1   tmcdeveloper   add method tests ...
29
    $(component.refs.signup).validate({
7df77f0fa   tmcdeveloper   finish wiring up ...
30
31
      rules: {
        firstName: {
f0c912bf1   tmcdeveloper   add method tests ...
32
          required: true,
7df77f0fa   tmcdeveloper   finish wiring up ...
33
34
        },
        lastName: {
f0c912bf1   tmcdeveloper   add method tests ...
35
          required: true,
7df77f0fa   tmcdeveloper   finish wiring up ...
36
37
38
        },
        emailAddress: {
          required: true,
f0c912bf1   tmcdeveloper   add method tests ...
39
          email: true,
7df77f0fa   tmcdeveloper   finish wiring up ...
40
41
42
        },
        password: {
          required: true,
f0c912bf1   tmcdeveloper   add method tests ...
43
44
          minlength: 6,
        },
7df77f0fa   tmcdeveloper   finish wiring up ...
45
46
47
      },
      messages: {
        firstName: {
f0c912bf1   tmcdeveloper   add method tests ...
48
          required: 'First name?',
7df77f0fa   tmcdeveloper   finish wiring up ...
49
50
        },
        lastName: {
f0c912bf1   tmcdeveloper   add method tests ...
51
          required: 'Last name?',
7df77f0fa   tmcdeveloper   finish wiring up ...
52
53
54
        },
        emailAddress: {
          required: 'Need an email address here.',
f0c912bf1   tmcdeveloper   add method tests ...
55
          email: 'Is this email address legit?',
7df77f0fa   tmcdeveloper   finish wiring up ...
56
57
58
        },
        password: {
          required: 'Need a password here.',
f0c912bf1   tmcdeveloper   add method tests ...
59
60
          minlength: 'Use at least six characters, please.',
        },
7df77f0fa   tmcdeveloper   finish wiring up ...
61
      },
f0c912bf1   tmcdeveloper   add method tests ...
62
      submitHandler() { _handleSignup(); },
7df77f0fa   tmcdeveloper   finish wiring up ...
63
64
    });
  };
f0c912bf1   tmcdeveloper   add method tests ...
65
  export const handleSignup = (options) => {
7df77f0fa   tmcdeveloper   finish wiring up ...
66
67
68
    component = options.component;
    _validate();
  };