Fix
This commit is contained in:
parent
0b0db31166
commit
e9fbdcfd2e
|
@ -1,4 +1,4 @@
|
||||||
import React, { Component, useContext } from 'react';
|
import React, { Component } from 'react';
|
||||||
import require$$1 from 'prop-types';
|
import require$$1 from 'prop-types';
|
||||||
import reactDom from 'react-dom';
|
import reactDom from 'react-dom';
|
||||||
|
|
||||||
|
@ -2765,13 +2765,13 @@ var lib_7 = lib.ToastType;
|
||||||
var lib_8 = lib.toast;
|
var lib_8 = lib.toast;
|
||||||
var lib_9 = lib.cssTransition;
|
var lib_9 = lib.cssTransition;
|
||||||
|
|
||||||
var Form = function (_Component) {
|
var ContextAwareForm = function (_Component) {
|
||||||
inherits(Form, _Component);
|
inherits(ContextAwareForm, _Component);
|
||||||
|
|
||||||
function Form(props) {
|
function ContextAwareForm(props) {
|
||||||
classCallCheck(this, Form);
|
classCallCheck(this, ContextAwareForm);
|
||||||
|
|
||||||
var _this = possibleConstructorReturn(this, (Form.__proto__ || Object.getPrototypeOf(Form)).call(this, props));
|
var _this = possibleConstructorReturn(this, (ContextAwareForm.__proto__ || Object.getPrototypeOf(ContextAwareForm)).call(this, props));
|
||||||
|
|
||||||
_this._onSubmit = function (e) {
|
_this._onSubmit = function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -2789,7 +2789,7 @@ var Form = function (_Component) {
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
|
|
||||||
createClass(Form, [{
|
createClass(ContextAwareForm, [{
|
||||||
key: 'componentWillReceiveProps',
|
key: 'componentWillReceiveProps',
|
||||||
value: function componentWillReceiveProps(props) {
|
value: function componentWillReceiveProps(props) {
|
||||||
this.handleError(props);
|
this.handleError(props);
|
||||||
|
@ -2801,8 +2801,7 @@ var Form = function (_Component) {
|
||||||
key: 'handleError',
|
key: 'handleError',
|
||||||
value: function handleError(props) {
|
value: function handleError(props) {
|
||||||
if (props.data && props.data.error && props.toast && this.displayError == true) {
|
if (props.data && props.data.error && props.toast && this.displayError == true) {
|
||||||
var contextValue = useContext(FormTranslationContext);
|
lib_8.error(this.props.translator.renderText(props.data.error));
|
||||||
lib_8.error(contextValue.renderText(props.data.error));
|
|
||||||
this.displayError = false;
|
this.displayError = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2824,25 +2823,42 @@ var Form = function (_Component) {
|
||||||
}, {
|
}, {
|
||||||
key: 'renderError',
|
key: 'renderError',
|
||||||
value: function renderError() {
|
value: function renderError() {
|
||||||
var _this2 = this;
|
|
||||||
|
|
||||||
if (this.state.data && this.state.data.error && !this.props.toast) {
|
if (this.state.data && this.state.data.error && !this.props.toast) {
|
||||||
return React.createElement(
|
return React.createElement(
|
||||||
FormTranslationConsumer,
|
|
||||||
null,
|
|
||||||
function (translator) {
|
|
||||||
return React.createElement(
|
|
||||||
'p',
|
'p',
|
||||||
{ className: 'alert alert-danger' },
|
{ className: 'alert alert-danger' },
|
||||||
translator.renderText(_this2.state.data.error)
|
this.props.translator.renderText(this.state.data.error)
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}]);
|
}]);
|
||||||
|
return ContextAwareForm;
|
||||||
|
}(Component);
|
||||||
|
|
||||||
|
var Form = function (_Component2) {
|
||||||
|
inherits(Form, _Component2);
|
||||||
|
|
||||||
|
function Form() {
|
||||||
|
classCallCheck(this, Form);
|
||||||
|
return possibleConstructorReturn(this, (Form.__proto__ || Object.getPrototypeOf(Form)).apply(this, arguments));
|
||||||
|
}
|
||||||
|
|
||||||
|
createClass(Form, [{
|
||||||
|
key: 'render',
|
||||||
|
value: function render() {
|
||||||
|
var _this3 = this;
|
||||||
|
|
||||||
|
return React.createElement(
|
||||||
|
FormTranslationConsumer,
|
||||||
|
null,
|
||||||
|
function (translator) {
|
||||||
|
return React.createElement(ContextAwareForm, _extends({ translator: translator }, _this3.props));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}]);
|
||||||
return Form;
|
return Form;
|
||||||
}(Component);
|
}(Component);
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -2772,13 +2772,13 @@ var lib_7 = lib.ToastType;
|
||||||
var lib_8 = lib.toast;
|
var lib_8 = lib.toast;
|
||||||
var lib_9 = lib.cssTransition;
|
var lib_9 = lib.cssTransition;
|
||||||
|
|
||||||
var Form = function (_Component) {
|
var ContextAwareForm = function (_Component) {
|
||||||
inherits(Form, _Component);
|
inherits(ContextAwareForm, _Component);
|
||||||
|
|
||||||
function Form(props) {
|
function ContextAwareForm(props) {
|
||||||
classCallCheck(this, Form);
|
classCallCheck(this, ContextAwareForm);
|
||||||
|
|
||||||
var _this = possibleConstructorReturn(this, (Form.__proto__ || Object.getPrototypeOf(Form)).call(this, props));
|
var _this = possibleConstructorReturn(this, (ContextAwareForm.__proto__ || Object.getPrototypeOf(ContextAwareForm)).call(this, props));
|
||||||
|
|
||||||
_this._onSubmit = function (e) {
|
_this._onSubmit = function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -2796,7 +2796,7 @@ var Form = function (_Component) {
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
|
|
||||||
createClass(Form, [{
|
createClass(ContextAwareForm, [{
|
||||||
key: 'componentWillReceiveProps',
|
key: 'componentWillReceiveProps',
|
||||||
value: function componentWillReceiveProps(props) {
|
value: function componentWillReceiveProps(props) {
|
||||||
this.handleError(props);
|
this.handleError(props);
|
||||||
|
@ -2808,8 +2808,7 @@ var Form = function (_Component) {
|
||||||
key: 'handleError',
|
key: 'handleError',
|
||||||
value: function handleError(props) {
|
value: function handleError(props) {
|
||||||
if (props.data && props.data.error && props.toast && this.displayError == true) {
|
if (props.data && props.data.error && props.toast && this.displayError == true) {
|
||||||
var contextValue = React.useContext(FormTranslationContext);
|
lib_8.error(this.props.translator.renderText(props.data.error));
|
||||||
lib_8.error(contextValue.renderText(props.data.error));
|
|
||||||
this.displayError = false;
|
this.displayError = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2831,25 +2830,42 @@ var Form = function (_Component) {
|
||||||
}, {
|
}, {
|
||||||
key: 'renderError',
|
key: 'renderError',
|
||||||
value: function renderError() {
|
value: function renderError() {
|
||||||
var _this2 = this;
|
|
||||||
|
|
||||||
if (this.state.data && this.state.data.error && !this.props.toast) {
|
if (this.state.data && this.state.data.error && !this.props.toast) {
|
||||||
return React__default.createElement(
|
return React__default.createElement(
|
||||||
FormTranslationConsumer,
|
|
||||||
null,
|
|
||||||
function (translator) {
|
|
||||||
return React__default.createElement(
|
|
||||||
'p',
|
'p',
|
||||||
{ className: 'alert alert-danger' },
|
{ className: 'alert alert-danger' },
|
||||||
translator.renderText(_this2.state.data.error)
|
this.props.translator.renderText(this.state.data.error)
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}]);
|
}]);
|
||||||
|
return ContextAwareForm;
|
||||||
|
}(React.Component);
|
||||||
|
|
||||||
|
var Form = function (_Component2) {
|
||||||
|
inherits(Form, _Component2);
|
||||||
|
|
||||||
|
function Form() {
|
||||||
|
classCallCheck(this, Form);
|
||||||
|
return possibleConstructorReturn(this, (Form.__proto__ || Object.getPrototypeOf(Form)).apply(this, arguments));
|
||||||
|
}
|
||||||
|
|
||||||
|
createClass(Form, [{
|
||||||
|
key: 'render',
|
||||||
|
value: function render() {
|
||||||
|
var _this3 = this;
|
||||||
|
|
||||||
|
return React__default.createElement(
|
||||||
|
FormTranslationConsumer,
|
||||||
|
null,
|
||||||
|
function (translator) {
|
||||||
|
return React__default.createElement(ContextAwareForm, _extends({ translator: translator }, _this3.props));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}]);
|
||||||
return Form;
|
return Form;
|
||||||
}(React.Component);
|
}(React.Component);
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
28
src/Form.js
28
src/Form.js
|
@ -1,8 +1,9 @@
|
||||||
import React, {Component, useContext} from 'react';
|
import React, {Component} from 'react';
|
||||||
import FormContext from './FormContext';
|
import FormContext from './FormContext';
|
||||||
import {toast, ToastContainer} from 'react-toastify';
|
import {toast, ToastContainer} from 'react-toastify';
|
||||||
import FormTranslationContext, {FormTranslationConsumer} from './FormTranslationContext'
|
import FormTranslationContext, {FormTranslationConsumer} from './FormTranslationContext'
|
||||||
export default class Form extends Component
|
|
||||||
|
class ContextAwareForm extends Component
|
||||||
{
|
{
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
@ -25,8 +26,7 @@ export default class Form extends Component
|
||||||
handleError(props)
|
handleError(props)
|
||||||
{
|
{
|
||||||
if (props.data && props.data.error && props.toast && this.displayError == true) {
|
if (props.data && props.data.error && props.toast && this.displayError == true) {
|
||||||
const contextValue = useContext(FormTranslationContext);
|
toast.error(this.props.translator.renderText(props.data.error))
|
||||||
toast.error(contextValue.renderText(props.data.error))
|
|
||||||
this.displayError = false
|
this.displayError = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,11 +56,7 @@ export default class Form extends Component
|
||||||
if (this.state.data && this.state.data.error && !this.props.toast)
|
if (this.state.data && this.state.data.error && !this.props.toast)
|
||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
<FormTranslationConsumer>
|
<p className="alert alert-danger">{this.props.translator.renderText(this.state.data.error)}</p>
|
||||||
{(translator) => (
|
|
||||||
<p className="alert alert-danger">{translator.renderText(this.state.data.error)}</p>
|
|
||||||
)}
|
|
||||||
</FormTranslationConsumer>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +64,20 @@ export default class Form extends Component
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default class Form extends Component
|
||||||
|
{
|
||||||
|
render()
|
||||||
|
{
|
||||||
|
return (
|
||||||
|
<FormTranslationConsumer>
|
||||||
|
{(translator) => (
|
||||||
|
<ContextAwareForm translator={translator} {...this.props}/>
|
||||||
|
)}
|
||||||
|
</FormTranslationConsumer>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Form.defaultProps = {
|
Form.defaultProps = {
|
||||||
data: null,
|
data: null,
|
||||||
toast: false,
|
toast: false,
|
||||||
|
|
Loading…
Reference in New Issue