|
@@ -4,27 +4,42 @@ import PropTypes from 'prop-types';
|
|
|
import { withTranslation } from 'react-i18next';
|
|
import { withTranslation } from 'react-i18next';
|
|
|
|
|
|
|
|
const ApiErrorMessage = (props) => {
|
|
const ApiErrorMessage = (props) => {
|
|
|
- const { t, errorCode, linkPath } = props;
|
|
|
|
|
|
|
+ const {
|
|
|
|
|
+ t, errorCode, errorMessage, linkPath,
|
|
|
|
|
+ } = props;
|
|
|
|
|
|
|
|
- function renderMessage() {
|
|
|
|
|
|
|
+ function renderMessageByErrorCode() {
|
|
|
switch (errorCode) {
|
|
switch (errorCode) {
|
|
|
case 'already_exists':
|
|
case 'already_exists':
|
|
|
return (
|
|
return (
|
|
|
- <span className="text-danger">
|
|
|
|
|
|
|
+ <>
|
|
|
<strong><i className="icon-fw icon-ban"></i>{ t('page_api_error.already_exists') }</strong>
|
|
<strong><i className="icon-fw icon-ban"></i>{ t('page_api_error.already_exists') }</strong>
|
|
|
<small><a href={linkPath}>{linkPath} <i className="icon-login"></i></a></small>
|
|
<small><a href={linkPath}>{linkPath} <i className="icon-login"></i></a></small>
|
|
|
- </span>
|
|
|
|
|
|
|
+ </>
|
|
|
);
|
|
);
|
|
|
default:
|
|
default:
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return (
|
|
|
|
|
- <>
|
|
|
|
|
- {renderMessage()}
|
|
|
|
|
- </>
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ if (errorCode != null) {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <span className="text-danger">
|
|
|
|
|
+ {renderMessageByErrorCode()}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (errorMessage != null) {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <span className="text-danger">
|
|
|
|
|
+ {errorMessage}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // render null if no error has occurred
|
|
|
|
|
+ return null;
|
|
|
|
|
|
|
|
// TODO GW-79 Set according to error message
|
|
// TODO GW-79 Set according to error message
|
|
|
// <div>
|
|
// <div>
|
|
@@ -51,9 +66,11 @@ const ApiErrorMessage = (props) => {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
ApiErrorMessage.propTypes = {
|
|
ApiErrorMessage.propTypes = {
|
|
|
- t: PropTypes.func.isRequired, // i18next
|
|
|
|
|
- errorCode: PropTypes.string,
|
|
|
|
|
- linkPath: PropTypes.string,
|
|
|
|
|
|
|
+ t: PropTypes.func.isRequired, // i18next
|
|
|
|
|
+
|
|
|
|
|
+ errorCode: PropTypes.string,
|
|
|
|
|
+ errorMessage: PropTypes.string,
|
|
|
|
|
+ linkPath: PropTypes.string,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
export default withTranslation()(ApiErrorMessage);
|
|
export default withTranslation()(ApiErrorMessage);
|