Blame view

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