2020-10-04 07:36:51 +02:00
|
|
|
import React from 'react';
|
2021-02-24 15:21:59 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2020-10-04 07:36:51 +02:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
import Icon from './Icon';
|
|
|
|
import Exclamation from 'assets/exclamation-triangle.svg';
|
|
|
|
import styles from './ErrorMessage.module.css';
|
|
|
|
|
2021-02-24 15:21:59 +01:00
|
|
|
const DEFAULT_ID = 'message.failure';
|
|
|
|
const DEFAULT_MESSAGE = 'Something went wrong';
|
|
|
|
|
|
|
|
function ErrorMessage({ error }) {
|
|
|
|
const [id, defaultMessage] =
|
|
|
|
typeof error === 'string' ? error.split('\t') : [DEFAULT_ID, DEFAULT_MESSAGE];
|
|
|
|
|
2020-10-04 07:36:51 +02:00
|
|
|
return (
|
|
|
|
<div className={styles.error}>
|
|
|
|
<Icon icon={<Exclamation />} className={styles.icon} size="large" />
|
2021-02-24 15:21:59 +01:00
|
|
|
<FormattedMessage id={id} defaultMessage={defaultMessage} />
|
2020-10-04 07:36:51 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2021-02-24 15:21:59 +01:00
|
|
|
|
|
|
|
ErrorMessage.propTypes = {
|
|
|
|
error: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Error)]),
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ErrorMessage;
|