bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/error-screen/component.jsx

96 lines
2.1 KiB
React
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
2017-03-11 04:47:23 +08:00
import { defineMessages, injectIntl } from 'react-intl';
import { Meteor } from 'meteor/meteor';
import Button from '/imports/ui/components/button/component';
import logoutRouteHandler from '/imports/utils/logoutRouteHandler';
2019-01-08 00:26:23 +08:00
import { Session } from 'meteor/session';
import { styles } from './styles';
2017-03-11 04:47:23 +08:00
const intlMessages = defineMessages({
500: {
id: 'app.error.500',
defaultMessage: 'Ops, something went wrong',
2017-03-11 04:47:23 +08:00
},
404: {
id: 'app.error.404',
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
},
400: {
id: 'app.error.400',
},
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,
};
class ErrorScreen extends React.PureComponent {
componentDidMount() {
Meteor.disconnect();
}
2017-03-11 04:47:23 +08:00
render() {
const {
intl,
code,
children,
} = this.props;
2017-03-11 04:47:23 +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}>
2019-01-08 00:26:23 +08:00
<h1 className={styles.codeError}>
2017-03-11 04:47:23 +08:00
{code}
</h1>
<h1 className={styles.message}>
{formatedMessage}
</h1>
2019-01-08 00:26:23 +08:00
<div className={styles.separator} />
2018-12-06 01:42:31 +08:00
<div>
2017-03-11 04:47:23 +08:00
{children}
</div>
2019-01-08 00:26:23 +08:00
{
!Session.get('errorMessageDescription') || (
2019-01-08 00:26:23 +08:00
<div className={styles.sessionMessage}>
{Session.get('errorMessageDescription')}
2019-01-08 00:26:23 +08:00
</div>)
}
2018-12-06 01:42:31 +08:00
<div>
<Button
size="sm"
2019-01-08 00:26:23 +08:00
color="primary"
className={styles.button}
onClick={logoutRouteHandler}
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>
);
}
}
export default injectIntl(ErrorScreen);
2017-03-11 04:47:23 +08:00
ErrorScreen.propTypes = propTypes;
ErrorScreen.defaultProps = defaultProps;