e.preventDefault()} className={`ar-${currentState}`}>
69 |
70 | {/* Title */}
71 | {title && }
72 |
73 | {/* Fields */}
74 |
75 | {fields.map((f, i) => {
76 |
77 | let Field = InputField // Defaults to input
78 | switch (f.type) {
79 | case 'select': Field = SelectField; break;
80 | case 'radio': Field = RadioField; break;
81 | }
82 |
83 | const props = {
84 | key: i,
85 | values,
86 | defaults,
87 | onChange: this.handleInputChange,
88 | error: errors ? errors.find((errField) => errField._id === f._id) : [],
89 | ...f
90 | }
91 |
92 | if (this.shouldFocusFirstInput(i)) {
93 | props.focusInput = true
94 | }
95 |
96 | return React.createElement(Field, props)
97 | })}
98 |
99 |
100 | {showReCaptcha && }
101 |
102 | {/* Submit Button */}
103 |
104 |
105 | {/* Errors Message */}
106 |
107 | {errors.length > 0 && }
108 |
109 |
110 |
111 | )
112 | }
113 |
114 | shouldFocusFirstInput = index => {
115 | return this.props.defaults.focusFirstInput && index === 0
116 | }
117 | }
118 |
119 | BaseForm.propTypes = {
120 | context: PropTypes.object.isRequired,
121 | currentState: PropTypes.string.isRequired,
122 | values: PropTypes.object.isRequired,
123 | defaults: PropTypes.object.isRequired,
124 | onSubmit: PropTypes.func.isRequired,
125 | errors: PropTypes.array.isRequired
126 | }
127 |
128 | export default BaseForm
129 |
--------------------------------------------------------------------------------
/lib/AccountsReactComponent/changePwd.js:
--------------------------------------------------------------------------------
1 | import React, { Component, Fragment } from 'react'
2 | import BaseForm from './baseForm'
3 | import { validateForm } from '../utils/'
4 | import { getModel, redirect } from './commonUtils'
5 | import { changePassword } from './methods'
6 |
7 | class ChangePwd extends Component {
8 | constructor () {
9 | super()
10 |
11 | this.state = {
12 | passwordUpdated: false,
13 | errors: []
14 | }
15 |
16 | this.getModel = getModel.bind(this)
17 | this.redirect = redirect.bind(this)
18 | }
19 |
20 | componentWillMount () {
21 | if (!Meteor.userId()) {
22 | this.redirect('signin', this.props.defaults.redirects.toSignIn)
23 | }
24 | }
25 |
26 | render () {
27 | const {
28 | currentState,
29 | defaults
30 | } = this.props
31 |
32 | const {
33 | texts
34 | } = defaults
35 |
36 | const {
37 | passwordUpdated,
38 | errors
39 | } = this.state
40 |
41 | const model = this.getModel()
42 |
43 | return (
44 |