2018-06-27 19:32:51 +02:00
|
|
|
import React from 'react';
|
2018-06-28 09:30:14 +02:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import getContext from 'recompose/getContext';
|
2018-06-27 19:32:51 +02:00
|
|
|
import { registerComponent } from 'meteor/vulcan:core';
|
|
|
|
import { FormattedMessage } from 'meteor/vulcan:i18n';
|
|
|
|
|
2018-06-28 09:30:14 +02:00
|
|
|
const FormError = ({ error, context, getLabel }) => error.message || (
|
2018-06-27 19:32:51 +02:00
|
|
|
<FormattedMessage
|
|
|
|
id={error.id}
|
|
|
|
values={{
|
|
|
|
context,
|
2018-06-28 09:30:14 +02:00
|
|
|
label: error.properties.name && getLabel(error.properties.name),
|
2018-06-27 19:32:51 +02:00
|
|
|
...error.data, // backwards compatibility
|
|
|
|
...error.properties,
|
|
|
|
}}
|
|
|
|
defaultMessage={JSON.stringify(error)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
FormError.defaultProps = {
|
|
|
|
context: '', // default context so format message does not complain
|
2018-06-28 09:30:14 +02:00
|
|
|
getLabel: name => name,
|
2018-06-27 19:32:51 +02:00
|
|
|
};
|
|
|
|
|
2018-06-28 09:30:14 +02:00
|
|
|
registerComponent('FormError', FormError, getContext({
|
|
|
|
getLabel: PropTypes.func,
|
|
|
|
}));
|