import React, { Fragment, Component } from 'react'; import { defineMessages, injectIntl } from 'react-intl'; import PropTypes from 'prop-types'; import Toggle from '/imports/ui/components/common/switch/component'; import Styled from './styles'; const intlMessages = defineMessages({ lockViewersTitle: { id: 'app.lock-viewers.title', description: 'lock-viewers title', }, closeLabel: { id: 'app.shortcut-help.closeLabel', description: 'label for close button', }, closeDesc: { id: 'app.shortcut-help.closeDesc', description: 'description for close button', }, lockViewersDescription: { id: 'app.lock-viewers.description', description: 'description for lock viewers feature', }, featuresLable: { id: 'app.lock-viewers.featuresLable', description: 'features label', }, lockStatusLabel: { id: 'app.lock-viewers.lockStatusLabel', description: 'description for close button', }, webcamLabel: { id: 'app.lock-viewers.webcamLabel', description: 'label for webcam toggle', }, otherViewersWebcamLabel: { id: 'app.lock-viewers.otherViewersWebcamLabel', description: 'label for other viewers webcam toggle', }, microphoneLable: { id: 'app.lock-viewers.microphoneLable', description: 'label for microphone toggle', }, publicChatLabel: { id: 'app.lock-viewers.PublicChatLabel', description: 'label for public chat toggle', }, privateChatLable: { id: 'app.lock-viewers.PrivateChatLable', description: 'label for private chat toggle', }, notesLabel: { id: 'app.lock-viewers.notesLabel', description: 'label for shared notes toggle', }, userListLabel: { id: 'app.lock-viewers.userListLabel', description: 'label for user list toggle', }, ariaModalTitle: { id: 'app.lock-viewers.ariaTitle', description: 'aria label for modal title', }, buttonApply: { id: 'app.lock-viewers.button.apply', description: 'label for apply button', }, buttonCancel: { id: 'app.lock-viewers.button.cancel', description: 'label for cancel button', }, lockedLabel: { id: 'app.lock-viewers.locked', description: 'locked element label', }, hideCursorsLabel: { id: "app.lock-viewers.hideViewersCursor", description: 'label for other viewers cursor', }, hideAnnotationsLabel: { id: "app.lock-viewers.hideAnnotationsLabel", description: 'label for other viewers annotation', } }); const propTypes = { closeModal: PropTypes.func.isRequired, intl: PropTypes.shape({ formatMessage: PropTypes.func.isRequired, }).isRequired, meeting: PropTypes.object.isRequired, showToggleLabel: PropTypes.bool.isRequired, updateLockSettings: PropTypes.func.isRequired, updateWebcamsOnlyForModerator: PropTypes.func.isRequired, }; class LockViewersComponent extends Component { constructor(props) { super(props); const { meeting: { lockSettings, usersPolicies } } = this.props; this.state = { lockSettingsProps: lockSettings, usersProp: usersPolicies, }; } toggleLockSettings(property) { const { lockSettingsProps } = this.state; lockSettingsProps[property] = !lockSettingsProps[property]; this.setState({ lockSettingsProps, }); } toggleUserProps(property) { const { usersProp } = this.state; usersProp[property] = !usersProp[property]; this.setState({ usersProp, }); } displayLockStatus(status) { const { intl } = this.props; return ( status && {intl.formatMessage(intlMessages.lockedLabel)} ); } componentWillUnmount() { const { closeModal } = this.props; closeModal(); } render() { const { closeModal, intl, showToggleLabel, updateLockSettings, updateWebcamsOnlyForModerator, isOpen, onRequestClose, priority, isChatEnabled, isSharedNotesEnabled, } = this.props; const { lockSettingsProps, usersProp } = this.state; const invertColors = true; return ( {`${intl.formatMessage(intlMessages.lockViewersDescription)}`} {intl.formatMessage(intlMessages.featuresLable)} {intl.formatMessage(intlMessages.lockStatusLabel)} {this.displayLockStatus(lockSettingsProps.disableCam)} { this.toggleLockSettings('disableCam'); }} ariaLabel={intl.formatMessage(intlMessages.webcamLabel)} showToggleLabel={showToggleLabel} invertColors={invertColors} data-test="lockShareWebcam" /> {this.displayLockStatus(usersProp.webcamsOnlyForModerator)} { this.toggleUserProps('webcamsOnlyForModerator'); }} ariaLabel={intl.formatMessage(intlMessages.otherViewersWebcamLabel)} showToggleLabel={showToggleLabel} invertColors={invertColors} data-test="lockSeeOtherViewersWebcam" /> {this.displayLockStatus(lockSettingsProps.disableMic)} { this.toggleLockSettings('disableMic'); }} ariaLabel={intl.formatMessage(intlMessages.microphoneLable)} showToggleLabel={showToggleLabel} invertColors={invertColors} data-test="lockShareMicrophone" /> {isChatEnabled ? ( {this.displayLockStatus(lockSettingsProps.disablePublicChat)} { this.toggleLockSettings('disablePublicChat'); }} ariaLabel={intl.formatMessage(intlMessages.publicChatLabel)} showToggleLabel={showToggleLabel} invertColors={invertColors} data-test="lockPublicChat" /> {this.displayLockStatus(lockSettingsProps.disablePrivateChat)} { this.toggleLockSettings('disablePrivateChat'); }} ariaLabel={intl.formatMessage(intlMessages.privateChatLable)} showToggleLabel={showToggleLabel} invertColors={invertColors} data-test="lockPrivateChat" /> ) : null } {isSharedNotesEnabled ? ( {this.displayLockStatus(lockSettingsProps.disableNotes)} { this.toggleLockSettings('disableNotes'); }} ariaLabel={intl.formatMessage(intlMessages.notesLabel)} showToggleLabel={showToggleLabel} invertColors={invertColors} data-test="lockEditSharedNotes" /> ) : null } {this.displayLockStatus(lockSettingsProps.hideUserList)} { this.toggleLockSettings('hideUserList'); }} ariaLabel={intl.formatMessage(intlMessages.userListLabel)} showToggleLabel={showToggleLabel} invertColors={invertColors} data-test="lockUserList" /> {this.displayLockStatus(lockSettingsProps.hideViewersCursor)} { this.toggleLockSettings('hideViewersCursor'); }} ariaLabel={intl.formatMessage(intlMessages.hideCursorsLabel)} showToggleLabel={showToggleLabel} invertColors={invertColors} data-test="hideViewersCursor" /> {this.displayLockStatus(lockSettingsProps.hideViewersAnnotation)} { this.toggleLockSettings('hideViewersAnnotation'); }} ariaLabel={intl.formatMessage(intlMessages.hideAnnotationsLabel)} showToggleLabel={showToggleLabel} invertColors={invertColors} data-test="hideViewersAnnotation" /> { updateLockSettings(lockSettingsProps); updateWebcamsOnlyForModerator(usersProp.webcamsOnlyForModerator); closeModal(); }} data-test="applyLockSettings" /> ); } } LockViewersComponent.propTypes = propTypes; export default injectIntl(LockViewersComponent);