2017-05-18 09:28:18 -04:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
2017-04-12 08:27:57 -04:00
|
|
|
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
2016-03-28 09:41:03 -04:00
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
|
|
export default class FormError extends React.Component {
|
|
|
|
|
static get propTypes() {
|
|
|
|
|
// accepts either a single error or an array of errors
|
|
|
|
|
return {
|
2017-05-18 09:28:18 -04:00
|
|
|
type: PropTypes.node,
|
|
|
|
|
error: PropTypes.node,
|
|
|
|
|
margin: PropTypes.bool,
|
|
|
|
|
errors: PropTypes.arrayOf(PropTypes.node)
|
2016-03-28 09:41:03 -04:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static get defaultProps() {
|
|
|
|
|
return {
|
|
|
|
|
error: null,
|
|
|
|
|
errors: []
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
if (!this.props.error && this.props.errors.length === 0) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// look for the first truthy error to display
|
|
|
|
|
let message = this.props.error;
|
|
|
|
|
|
|
|
|
|
if (!message) {
|
|
|
|
|
for (const error of this.props.errors) {
|
|
|
|
|
if (error) {
|
|
|
|
|
message = error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!message) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 00:56:38 +05:00
|
|
|
if (this.props.type === 'backstage') {
|
|
|
|
|
return (
|
|
|
|
|
<div className='pull-left has-error'>
|
|
|
|
|
<label className='control-label'>
|
|
|
|
|
{message}
|
|
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-07 02:32:27 +05:00
|
|
|
if (this.props.margin) {
|
|
|
|
|
return (
|
|
|
|
|
<div className='form-group has-error'>
|
|
|
|
|
<label className='control-label'>
|
|
|
|
|
{message}
|
|
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-28 09:41:03 -04:00
|
|
|
return (
|
2016-07-05 20:13:50 +05:00
|
|
|
<div className='col-sm-12 has-error'>
|
2016-03-28 09:41:03 -04:00
|
|
|
<label className='control-label'>
|
|
|
|
|
{message}
|
|
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|