]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/common/ErrorMessage.js
tracker medallion controler
[alttp.git] / resources / js / components / common / ErrorMessage.js
1 import PropTypes from 'prop-types';
2 import React from 'react';
3 import { Alert } from 'react-bootstrap';
4 import { withTranslation } from 'react-i18next';
5
6 import i18n from '../../i18n';
7
8 const ErrorMessage = ({ error }) => {
9         if (error.response) {
10                 return <Alert variant="danger">
11                         <Alert.Heading>{i18n.t(`error.${error.response.status}.heading`)}</Alert.Heading>
12                         <p className="mb-0">{i18n.t(`error.${error.response.status}.description`)}</p>
13                 </Alert>;
14         }
15         if (error.message) {
16                 return <Alert variant="danger">
17                         <Alert.Heading>Error</Alert.Heading>
18                         <p className="mb-0">{error.message}</p>
19                 </Alert>;
20         }
21         return <div className="error">Error</div>;
22 };
23
24 ErrorMessage.propTypes = {
25         error: PropTypes.shape({
26                 message: PropTypes.string,
27                 request: PropTypes.shape({}),
28                 response: PropTypes.shape({
29                         status: PropTypes.number,
30                 }),
31         }),
32 };
33
34 export default withTranslation()(ErrorMessage);