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 reactDom from 'react-dom';
|
||||
|
||||
|
@ -2765,13 +2765,13 @@ var lib_7 = lib.ToastType;
|
|||
var lib_8 = lib.toast;
|
||||
var lib_9 = lib.cssTransition;
|
||||
|
||||
var Form = function (_Component) {
|
||||
inherits(Form, _Component);
|
||||
var ContextAwareForm = function (_Component) {
|
||||
inherits(ContextAwareForm, _Component);
|
||||
|
||||
function Form(props) {
|
||||
classCallCheck(this, Form);
|
||||
function ContextAwareForm(props) {
|
||||
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) {
|
||||
e.preventDefault();
|
||||
|
@ -2789,7 +2789,7 @@ var Form = function (_Component) {
|
|||
return _this;
|
||||
}
|
||||
|
||||
createClass(Form, [{
|
||||
createClass(ContextAwareForm, [{
|
||||
key: 'componentWillReceiveProps',
|
||||
value: function componentWillReceiveProps(props) {
|
||||
this.handleError(props);
|
||||
|
@ -2801,8 +2801,7 @@ var Form = function (_Component) {
|
|||
key: 'handleError',
|
||||
value: function handleError(props) {
|
||||
if (props.data && props.data.error && props.toast && this.displayError == true) {
|
||||
var contextValue = useContext(FormTranslationContext);
|
||||
lib_8.error(contextValue.renderText(props.data.error));
|
||||
lib_8.error(this.props.translator.renderText(props.data.error));
|
||||
this.displayError = false;
|
||||
}
|
||||
}
|
||||
|
@ -2824,25 +2823,42 @@ var Form = function (_Component) {
|
|||
}, {
|
||||
key: 'renderError',
|
||||
value: function renderError() {
|
||||
var _this2 = this;
|
||||
|
||||
if (this.state.data && this.state.data.error && !this.props.toast) {
|
||||
return React.createElement(
|
||||
FormTranslationConsumer,
|
||||
null,
|
||||
function (translator) {
|
||||
return React.createElement(
|
||||
'p',
|
||||
{ className: 'alert alert-danger' },
|
||||
translator.renderText(_this2.state.data.error)
|
||||
);
|
||||
}
|
||||
'p',
|
||||
{ className: 'alert alert-danger' },
|
||||
this.props.translator.renderText(this.state.data.error)
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
}(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_9 = lib.cssTransition;
|
||||
|
||||
var Form = function (_Component) {
|
||||
inherits(Form, _Component);
|
||||
var ContextAwareForm = function (_Component) {
|
||||
inherits(ContextAwareForm, _Component);
|
||||
|
||||
function Form(props) {
|
||||
classCallCheck(this, Form);
|
||||
function ContextAwareForm(props) {
|
||||
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) {
|
||||
e.preventDefault();
|
||||
|
@ -2796,7 +2796,7 @@ var Form = function (_Component) {
|
|||
return _this;
|
||||
}
|
||||
|
||||
createClass(Form, [{
|
||||
createClass(ContextAwareForm, [{
|
||||
key: 'componentWillReceiveProps',
|
||||
value: function componentWillReceiveProps(props) {
|
||||
this.handleError(props);
|
||||
|
@ -2808,8 +2808,7 @@ var Form = function (_Component) {
|
|||
key: 'handleError',
|
||||
value: function handleError(props) {
|
||||
if (props.data && props.data.error && props.toast && this.displayError == true) {
|
||||
var contextValue = React.useContext(FormTranslationContext);
|
||||
lib_8.error(contextValue.renderText(props.data.error));
|
||||
lib_8.error(this.props.translator.renderText(props.data.error));
|
||||
this.displayError = false;
|
||||
}
|
||||
}
|
||||
|
@ -2831,25 +2830,42 @@ var Form = function (_Component) {
|
|||
}, {
|
||||
key: 'renderError',
|
||||
value: function renderError() {
|
||||
var _this2 = this;
|
||||
|
||||
if (this.state.data && this.state.data.error && !this.props.toast) {
|
||||
return React__default.createElement(
|
||||
FormTranslationConsumer,
|
||||
null,
|
||||
function (translator) {
|
||||
return React__default.createElement(
|
||||
'p',
|
||||
{ className: 'alert alert-danger' },
|
||||
translator.renderText(_this2.state.data.error)
|
||||
);
|
||||
}
|
||||
'p',
|
||||
{ className: 'alert alert-danger' },
|
||||
this.props.translator.renderText(this.state.data.error)
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
}(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 {toast, ToastContainer} from 'react-toastify';
|
||||
import FormTranslationContext, {FormTranslationConsumer} from './FormTranslationContext'
|
||||
export default class Form extends Component
|
||||
|
||||
class ContextAwareForm extends Component
|
||||
{
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
@ -25,8 +26,7 @@ export default class Form extends Component
|
|||
handleError(props)
|
||||
{
|
||||
if (props.data && props.data.error && props.toast && this.displayError == true) {
|
||||
const contextValue = useContext(FormTranslationContext);
|
||||
toast.error(contextValue.renderText(props.data.error))
|
||||
toast.error(this.props.translator.renderText(props.data.error))
|
||||
this.displayError = false
|
||||
}
|
||||
}
|
||||
|
@ -56,11 +56,7 @@ export default class Form extends Component
|
|||
if (this.state.data && this.state.data.error && !this.props.toast)
|
||||
{
|
||||
return (
|
||||
<FormTranslationConsumer>
|
||||
{(translator) => (
|
||||
<p className="alert alert-danger">{translator.renderText(this.state.data.error)}</p>
|
||||
)}
|
||||
</FormTranslationConsumer>
|
||||
<p className="alert alert-danger">{this.props.translator.renderText(this.state.data.error)}</p>
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -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 = {
|
||||
data: null,
|
||||
toast: false,
|
||||
|
|
Loading…
Reference in New Issue