2018-01-17 02:26:57 +08:00
|
|
|
import React from 'react';
|
2017-06-04 10:40:14 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2017-03-11 04:47:23 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2017-05-16 23:37:17 +08:00
|
|
|
import Button from '/imports/ui/components/button/component';
|
2017-12-12 21:08:43 +08:00
|
|
|
import { withRouter } from 'react-router';
|
2018-01-17 02:26:57 +08:00
|
|
|
import { styles } from './styles';
|
2017-03-11 04:47:23 +08:00
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
500: {
|
|
|
|
id: 'app.error.500',
|
2017-04-15 07:26:34 +08:00
|
|
|
defaultMessage: 'Ops, something went wrong',
|
2017-03-11 04:47:23 +08:00
|
|
|
},
|
|
|
|
404: {
|
|
|
|
id: 'app.error.404',
|
2017-04-15 07:26:34 +08:00
|
|
|
defaultMessage: 'Not found',
|
2017-03-11 04:47:23 +08:00
|
|
|
},
|
|
|
|
401: {
|
2017-04-18 01:14:31 +08:00
|
|
|
id: 'app.error.401',
|
2017-03-11 04:47:23 +08:00
|
|
|
},
|
2017-04-29 04:16:07 +08:00
|
|
|
leave: {
|
2017-05-04 00:19:45 +08:00
|
|
|
id: 'app.error.leaveLabel',
|
2017-04-29 04:16:07 +08:00
|
|
|
description: 'aria-label for leaving',
|
|
|
|
},
|
2017-03-11 04:47:23 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
code: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
|
|
|
PropTypes.number,
|
|
|
|
]),
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
code: 500,
|
|
|
|
};
|
|
|
|
|
2018-01-17 02:26:57 +08:00
|
|
|
class ErrorScreen extends React.PureComponent {
|
2017-03-11 04:47:23 +08:00
|
|
|
render() {
|
2017-12-12 21:08:43 +08:00
|
|
|
const {
|
|
|
|
intl, code, children, router,
|
|
|
|
} = this.props;
|
2017-03-11 04:47:23 +08:00
|
|
|
|
2017-12-12 21:08:43 +08:00
|
|
|
let formatedMessage = intl.formatMessage(intlMessages[defaultProps.code]);
|
2017-03-11 04:47:23 +08:00
|
|
|
|
|
|
|
if (code in intlMessages) {
|
|
|
|
formatedMessage = intl.formatMessage(intlMessages[code]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.background}>
|
|
|
|
<h1 className={styles.code}>
|
|
|
|
{code}
|
|
|
|
</h1>
|
|
|
|
<h1 className={styles.message}>
|
|
|
|
{formatedMessage}
|
|
|
|
</h1>
|
|
|
|
<div className={styles.content}>
|
|
|
|
{children}
|
|
|
|
</div>
|
2017-04-29 04:16:07 +08:00
|
|
|
<div className={styles.content}>
|
2017-05-16 23:37:17 +08:00
|
|
|
<Button
|
2017-12-12 21:08:43 +08:00
|
|
|
size="sm"
|
|
|
|
onClick={() => router.push('/logout/')}
|
2017-05-19 07:16:17 +08:00
|
|
|
label={intl.formatMessage(intlMessages.leave)}
|
2017-06-03 03:25:02 +08:00
|
|
|
/>
|
2017-04-29 04:16:07 +08:00
|
|
|
</div>
|
2017-03-11 04:47:23 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-12 21:08:43 +08:00
|
|
|
export default withRouter(injectIntl(ErrorScreen));
|
2017-03-11 04:47:23 +08:00
|
|
|
|
|
|
|
ErrorScreen.propTypes = propTypes;
|
|
|
|
ErrorScreen.defaultProps = defaultProps;
|