()
| 38 | } |
| 39 | |
| 40 | initialize () { |
| 41 | this.state = new State({ |
| 42 | fatalError: null, |
| 43 | // Possible errors: |
| 44 | // 'signed-in': They are logged in |
| 45 | // 'missing-input': Required query parameters are not provided |
| 46 | // 'email-exists': Given email exists in our system |
| 47 | // Any other string will be shown directly to user |
| 48 | |
| 49 | formError: null, |
| 50 | loading: true, |
| 51 | submitting: false, |
| 52 | queryParams: _.pick(utils.getQueryVariables(), |
| 53 | 'israelId', |
| 54 | 'firstName', |
| 55 | 'lastName', |
| 56 | 'email', |
| 57 | 'school', |
| 58 | 'city', |
| 59 | 'state', |
| 60 | 'district' |
| 61 | ), |
| 62 | name: '', |
| 63 | password: '' |
| 64 | }) |
| 65 | |
| 66 | const { israelId, email } = this.state.get('queryParams') |
| 67 | |
| 68 | // sanity checks |
| 69 | if (!me.isAnonymous()) { |
| 70 | this.state.set({ fatalError: 'signed-in', loading: false }) |
| 71 | } else if (!israelId) { |
| 72 | this.state.set({ fatalError: 'missing-input', loading: false }) |
| 73 | } else if (email && !forms.validateEmail(email)) { |
| 74 | this.state.set({ fatalError: 'invalid-email', loading: false }) |
| 75 | } else if (!email) { |
| 76 | this.state.set({ loading: false }) |
| 77 | } else { |
| 78 | User.checkEmailExists(email) |
| 79 | .then(({ exists }) => { |
| 80 | this.state.set({ loading: false }) |
| 81 | if (exists) { |
| 82 | return this.state.set({ fatalError: 'email-exists' }) |
| 83 | } |
| 84 | }).catch(() => { |
| 85 | return this.state.set({ fatalError: $.i18n.t('loading_error.unknown'), loading: false }) |
| 86 | }) |
| 87 | } |
| 88 | |
| 89 | return this.listenTo(this.state, 'change', _.debounce(this.render)) |
| 90 | } |
| 91 | |
| 92 | getRenderData () { |
| 93 | const c = super.getRenderData() |
nothing calls this directly
no test coverage detected