mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 18:11:40 -05:00
33 lines
942 B
JavaScript
33 lines
942 B
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import getContext from 'recompose/getContext';
|
|
import { registerComponent } from 'meteor/vulcan:core';
|
|
import { FormattedMessage } from 'meteor/vulcan:i18n';
|
|
|
|
const FormError = ({ error, errorContext, getLabel }) => {
|
|
if (error.message) {
|
|
return error.message;
|
|
}
|
|
return (
|
|
<FormattedMessage
|
|
id={error.id}
|
|
values={{
|
|
errorContext,
|
|
label: error.properties && getLabel(error.properties.name, error.properties.locale),
|
|
...error.data, // backwards compatibility
|
|
...error.properties,
|
|
}}
|
|
defaultMessage={JSON.stringify(error)}
|
|
/>
|
|
)
|
|
;}
|
|
|
|
FormError.defaultProps = {
|
|
errorContext: '', // default context so format message does not complain
|
|
getLabel: name => name,
|
|
};
|
|
|
|
// TODO: pass getLabel as prop instead for consistency?
|
|
registerComponent('FormError', FormError, getContext({
|
|
getLabel: PropTypes.func,
|
|
}));
|