2016-02-13 20:58:47 +05:30
|
|
|
/**
|
|
|
|
* Helps with form fields binding, form serialization and errors rendering
|
|
|
|
*/
|
|
|
|
import React, { Component, PropTypes } from 'react';
|
|
|
|
|
2016-03-13 14:20:09 +05:30
|
|
|
import AuthError from 'components/auth/authError/AuthError';
|
2016-03-13 14:06:31 +05:30
|
|
|
import { userShape } from 'components/user/User';
|
2016-05-02 15:08:45 +05:30
|
|
|
import { FormModel } from 'components/ui/form';
|
2016-02-13 20:58:47 +05:30
|
|
|
|
|
|
|
export default class BaseAuthBody extends Component {
|
2016-03-13 14:06:31 +05:30
|
|
|
static contextTypes = {
|
2016-02-13 20:58:47 +05:30
|
|
|
clearErrors: PropTypes.func.isRequired,
|
2016-03-02 02:06:14 +05:30
|
|
|
resolve: PropTypes.func.isRequired,
|
2016-05-22 18:37:51 +05:30
|
|
|
requestRedraw: PropTypes.func.isRequired,
|
2016-02-13 20:58:47 +05:30
|
|
|
auth: PropTypes.shape({
|
2016-03-13 14:06:31 +05:30
|
|
|
error: PropTypes.string,
|
|
|
|
scopes: PropTypes.array
|
|
|
|
}),
|
|
|
|
user: userShape
|
2016-02-13 20:58:47 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
renderErrors() {
|
2016-03-13 14:06:31 +05:30
|
|
|
return this.context.auth.error
|
|
|
|
? <AuthError error={this.context.auth.error} onClose={this.onClearErrors} />
|
2016-02-13 20:58:47 +05:30
|
|
|
: ''
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2016-03-02 02:06:14 +05:30
|
|
|
onFormSubmit() {
|
2016-03-13 14:06:31 +05:30
|
|
|
this.context.resolve(this.serialize());
|
2016-03-02 02:06:14 +05:30
|
|
|
}
|
|
|
|
|
2016-03-13 14:06:31 +05:30
|
|
|
onClearErrors = this.context.clearErrors;
|
2016-02-13 20:58:47 +05:30
|
|
|
|
2016-05-02 15:08:45 +05:30
|
|
|
form = new FormModel();
|
2016-02-13 20:58:47 +05:30
|
|
|
|
2016-05-01 12:48:34 +05:30
|
|
|
bindField = this.form.bindField.bind(this.form);
|
|
|
|
serialize = this.form.serialize.bind(this.form);
|
2016-02-13 20:58:47 +05:30
|
|
|
|
2016-03-28 10:35:18 +05:30
|
|
|
autoFocus() {
|
|
|
|
const fieldId = this.autoFocusField;
|
2016-03-12 19:53:55 +05:30
|
|
|
|
2016-05-01 12:48:34 +05:30
|
|
|
fieldId && this.form.focus(fieldId);
|
2016-02-13 20:58:47 +05:30
|
|
|
}
|
|
|
|
}
|