From c6c6ef1e8f37aad9fac564367a6b4700d40455f1 Mon Sep 17 00:00:00 2001 From: Alexander Klein Date: Wed, 24 Feb 2021 15:21:59 +0100 Subject: [PATCH] feature: parse error to ErrorMessage component --- components/common/ErrorMessage.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/components/common/ErrorMessage.js b/components/common/ErrorMessage.js index 5747f226..b8b0b2ad 100644 --- a/components/common/ErrorMessage.js +++ b/components/common/ErrorMessage.js @@ -1,14 +1,27 @@ import React from 'react'; +import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; import Icon from './Icon'; import Exclamation from 'assets/exclamation-triangle.svg'; import styles from './ErrorMessage.module.css'; -export default function ErrorMessage() { +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]; + return (
} className={styles.icon} size="large" /> - +
); } + +ErrorMessage.propTypes = { + error: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Error)]), +}; + +export default ErrorMessage;