bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/connection-status/status-helper/component.jsx

119 lines
3.0 KiB
React
Raw Normal View History

2021-10-19 04:52:59 +08:00
import React, { Fragment, PureComponent } from 'react';
import { defineMessages, injectIntl } from 'react-intl';
import Styled from './styles';
import Icon from '/imports/ui/components/connection-status/icon/component';
import SettingsMenuContainer from '/imports/ui/components/settings/container';
2023-12-06 20:12:25 +08:00
import Auth from '/imports/ui/services/auth';
2021-10-19 04:52:59 +08:00
const intlMessages = defineMessages({
label: {
id: 'app.connection-status.label',
description: 'Connection status label',
},
settings: {
id: 'app.connection-status.settings',
description: 'Connection settings label',
},
});
class ConnectionStatusIcon extends PureComponent {
constructor(props) {
super(props);
this.state = { isSettingsMenuModalOpen: false };
this.setSettingsMenuModalIsOpen = this.setSettingsMenuModalIsOpen.bind(this);
}
2021-10-19 04:52:59 +08:00
renderIcon(level = 'normal') {
return(
<Styled.IconWrapper>
<Icon
level={level}
grayscale
/>
</Styled.IconWrapper>
);
}
openAdjustSettings() {
this.setSettingsMenuModalIsOpen(true);
}
2021-10-19 04:52:59 +08:00
setSettingsMenuModalIsOpen(value) {
const {closeModal} = this.props;
this.setState({isSettingsMenuModalOpen: value})
if (!value) {
closeModal();
}
2021-10-19 04:52:59 +08:00
}
render() {
const {
intl,
2023-12-06 20:12:25 +08:00
connectionData,
2021-10-19 04:52:59 +08:00
} = this.props;
2023-12-06 20:12:25 +08:00
const ownConnectionData = connectionData.filter((curr) => curr.user.userId === Auth.userID);
const currentStatus = ownConnectionData && ownConnectionData.length > 0
? ownConnectionData[0].currentStatus
: 'normal';
2021-10-19 04:52:59 +08:00
let color;
2023-12-06 20:12:25 +08:00
switch (currentStatus) {
2021-10-19 04:52:59 +08:00
case 'warning':
color = 'success';
break;
case 'danger':
color = 'warning';
break;
case 'critical':
color = 'danger';
break;
default:
color = 'success';
}
const { isSettingsMenuModalOpen } = this.state;
2021-10-19 04:52:59 +08:00
return (
<Fragment>
<Styled.StatusIconWrapper color={color}>
2023-12-06 20:12:25 +08:00
{this.renderIcon(currentStatus)}
2021-10-19 04:52:59 +08:00
</Styled.StatusIconWrapper>
<Styled.Label>
{intl.formatMessage(intlMessages.label)}
</Styled.Label>
2023-12-06 20:12:25 +08:00
{(currentStatus === 'critical' || currentStatus === 'danger') || isSettingsMenuModalOpen
? (
2021-10-19 04:52:59 +08:00
<div>
<Styled.Settings
onClick={this.openAdjustSettings.bind(this)}
role="button"
>
{intl.formatMessage(intlMessages.settings)}
</Styled.Settings>
{isSettingsMenuModalOpen ? <SettingsMenuContainer
selectedTab={2}
{...{
onRequestClose: () => this.setSettingsMenuModalIsOpen(false),
2023-05-27 02:29:29 +08:00
priority: "medium",
setIsOpen: this.setSettingsMenuModalIsOpen,
isOpen: isSettingsMenuModalOpen,
}}
/> : null}
2021-10-19 04:52:59 +08:00
</div>
)
: (
<div>&nbsp;</div>
)
2021-10-19 04:52:59 +08:00
}
</Fragment>
);
}
}
export default injectIntl(ConnectionStatusIcon);