2017-03-23 04:10:49 +08:00
|
|
|
import React, { Component } from 'react';
|
2017-04-05 22:25:26 +08:00
|
|
|
import Modal from '/imports/ui/components/modal/fullscreen/component';
|
2019-01-04 01:14:45 +08:00
|
|
|
import {
|
|
|
|
Tab, Tabs, TabList, TabPanel,
|
|
|
|
} from 'react-tabs';
|
2020-05-26 04:00:13 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2018-02-06 21:33:48 +08:00
|
|
|
import DataSaving from '/imports/ui/components/settings/submenus/data-saving/component';
|
2019-01-04 01:14:45 +08:00
|
|
|
import Application from '/imports/ui/components/settings/submenus/application/component';
|
2020-03-19 22:19:40 +08:00
|
|
|
import Notification from '/imports/ui/components/settings/submenus/notification/component';
|
2017-04-05 01:51:05 +08:00
|
|
|
import _ from 'lodash';
|
2017-10-28 03:29:48 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2017-01-27 23:41:11 +08:00
|
|
|
|
2017-10-28 03:29:48 +08:00
|
|
|
import { withModalMounter } from '../modal/service';
|
2017-01-27 23:41:11 +08:00
|
|
|
import Icon from '../icon/component';
|
2018-01-08 14:17:18 +08:00
|
|
|
import { styles } from './styles';
|
2017-01-27 23:41:11 +08:00
|
|
|
|
2017-04-18 02:19:27 +08:00
|
|
|
const intlMessages = defineMessages({
|
|
|
|
appTabLabel: {
|
|
|
|
id: 'app.settings.applicationTab.label',
|
|
|
|
description: 'label for application tab',
|
|
|
|
},
|
|
|
|
audioTabLabel: {
|
|
|
|
id: 'app.settings.audioTab.label',
|
|
|
|
description: 'label for audio tab',
|
|
|
|
},
|
|
|
|
videoTabLabel: {
|
|
|
|
id: 'app.settings.videoTab.label',
|
|
|
|
description: 'label for video tab',
|
|
|
|
},
|
|
|
|
usersTabLabel: {
|
|
|
|
id: 'app.settings.usersTab.label',
|
|
|
|
description: 'label for participants tab',
|
|
|
|
},
|
2017-04-28 23:56:27 +08:00
|
|
|
SettingsLabel: {
|
|
|
|
id: 'app.settings.main.label',
|
|
|
|
description: 'General settings label',
|
|
|
|
},
|
|
|
|
CancelLabel: {
|
|
|
|
id: 'app.settings.main.cancel.label',
|
|
|
|
description: 'Discard the changes and close the settings menu',
|
|
|
|
},
|
2017-04-29 03:13:42 +08:00
|
|
|
CancelLabelDesc: {
|
|
|
|
id: 'app.settings.main.cancel.label.description',
|
|
|
|
description: 'Settings modal cancel button description',
|
|
|
|
},
|
2017-04-28 23:56:27 +08:00
|
|
|
SaveLabel: {
|
|
|
|
id: 'app.settings.main.save.label',
|
|
|
|
description: 'Save the changes and close the settings menu',
|
|
|
|
},
|
2017-04-29 03:13:42 +08:00
|
|
|
SaveLabelDesc: {
|
|
|
|
id: 'app.settings.main.save.label.description',
|
|
|
|
description: 'Settings modal save button label',
|
|
|
|
},
|
2021-02-01 23:57:43 +08:00
|
|
|
notificationLabel: {
|
|
|
|
id: 'app.submenu.notification.SectionTitle', // set menu label identical to section title
|
|
|
|
description: 'label for notification tab',
|
|
|
|
},
|
2018-02-01 19:31:17 +08:00
|
|
|
dataSavingLabel: {
|
2018-02-06 21:33:48 +08:00
|
|
|
id: 'app.settings.dataSavingTab.label',
|
2018-01-30 19:20:51 +08:00
|
|
|
description: 'label for data savings tab',
|
|
|
|
},
|
2019-05-08 23:50:00 +08:00
|
|
|
savedAlertLabel: {
|
|
|
|
id: 'app.settings.save-notification.label',
|
|
|
|
description: 'label shown in toast when settings are saved',
|
|
|
|
},
|
2021-05-01 03:06:28 +08:00
|
|
|
on: {
|
|
|
|
id: 'app.switch.onLabel',
|
|
|
|
description: 'label for toggle switch on state',
|
|
|
|
},
|
|
|
|
off: {
|
|
|
|
id: 'app.switch.offLabel',
|
|
|
|
description: 'label for toggle switch off state',
|
|
|
|
},
|
2017-04-18 02:19:27 +08:00
|
|
|
});
|
|
|
|
|
2017-01-27 23:41:11 +08:00
|
|
|
const propTypes = {
|
2021-01-28 03:50:48 +08:00
|
|
|
intl: PropTypes.shape({
|
|
|
|
formatMessage: PropTypes.func.isRequired,
|
|
|
|
}).isRequired,
|
2019-01-04 01:14:45 +08:00
|
|
|
dataSaving: PropTypes.shape({
|
|
|
|
viewParticipantsWebcams: PropTypes.bool,
|
|
|
|
viewScreenshare: PropTypes.bool,
|
|
|
|
}).isRequired,
|
|
|
|
application: PropTypes.shape({
|
|
|
|
chatAudioAlerts: PropTypes.bool,
|
|
|
|
chatPushAlerts: PropTypes.bool,
|
2019-11-06 04:08:26 +08:00
|
|
|
userJoinAudioAlerts: PropTypes.bool,
|
2020-07-16 02:50:56 +08:00
|
|
|
guestWaitingAudioAlerts: PropTypes.bool,
|
2021-03-04 03:20:19 +08:00
|
|
|
guestWaitingPushAlerts: PropTypes.bool,
|
2020-08-29 03:29:45 +08:00
|
|
|
paginationEnabled: PropTypes.bool,
|
2019-01-04 01:14:45 +08:00
|
|
|
fallbackLocale: PropTypes.string,
|
|
|
|
fontSize: PropTypes.string,
|
|
|
|
locale: PropTypes.string,
|
2021-01-23 03:30:42 +08:00
|
|
|
microphoneConstraints: PropTypes.objectOf(Object),
|
2019-01-04 01:14:45 +08:00
|
|
|
}).isRequired,
|
2017-10-28 03:29:48 +08:00
|
|
|
updateSettings: PropTypes.func.isRequired,
|
2019-01-04 01:14:45 +08:00
|
|
|
availableLocales: PropTypes.objectOf(PropTypes.array).isRequired,
|
2017-10-28 03:29:48 +08:00
|
|
|
mountModal: PropTypes.func.isRequired,
|
2021-05-01 03:06:28 +08:00
|
|
|
showToggleLabel: PropTypes.bool.isRequired,
|
2017-01-27 23:41:11 +08:00
|
|
|
};
|
2016-05-06 05:14:39 +08:00
|
|
|
|
2017-04-18 02:19:27 +08:00
|
|
|
class Settings extends Component {
|
2017-10-11 06:08:51 +08:00
|
|
|
static setHtmlFontSize(size) {
|
|
|
|
document.getElementsByTagName('html')[0].style.fontSize = size;
|
|
|
|
}
|
2019-01-04 01:14:45 +08:00
|
|
|
|
2016-05-06 05:14:39 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2017-02-22 04:29:36 +08:00
|
|
|
|
2017-12-19 19:13:37 +08:00
|
|
|
const {
|
2019-08-02 21:00:08 +08:00
|
|
|
dataSaving, application,
|
2017-12-19 19:13:37 +08:00
|
|
|
} = props;
|
2017-03-09 22:34:33 +08:00
|
|
|
|
2017-01-27 23:41:11 +08:00
|
|
|
this.state = {
|
|
|
|
current: {
|
2018-02-06 21:33:48 +08:00
|
|
|
dataSaving: _.clone(dataSaving),
|
2017-03-29 04:16:57 +08:00
|
|
|
application: _.clone(application),
|
2017-01-27 23:41:11 +08:00
|
|
|
},
|
2017-02-25 04:19:53 +08:00
|
|
|
saved: {
|
2018-02-06 21:33:48 +08:00
|
|
|
dataSaving: _.clone(dataSaving),
|
2017-03-09 22:34:33 +08:00
|
|
|
application: _.clone(application),
|
2017-02-25 04:19:53 +08:00
|
|
|
},
|
2017-03-14 04:03:18 +08:00
|
|
|
selectedTab: 0,
|
2016-05-06 05:14:39 +08:00
|
|
|
};
|
|
|
|
|
2017-03-29 02:41:48 +08:00
|
|
|
this.updateSettings = props.updateSettings;
|
2017-01-27 23:41:11 +08:00
|
|
|
this.handleUpdateSettings = this.handleUpdateSettings.bind(this);
|
2017-02-25 04:19:53 +08:00
|
|
|
this.handleSelectTab = this.handleSelectTab.bind(this);
|
2021-05-01 03:06:28 +08:00
|
|
|
this.displaySettingsStatus = this.displaySettingsStatus.bind(this);
|
2016-07-12 01:43:42 +08:00
|
|
|
}
|
|
|
|
|
2020-05-14 01:05:59 +08:00
|
|
|
componentDidMount() {
|
2019-01-04 01:14:45 +08:00
|
|
|
const { availableLocales } = this.props;
|
2021-01-28 03:50:48 +08:00
|
|
|
|
2019-01-04 01:14:45 +08:00
|
|
|
availableLocales.then((locales) => {
|
2021-01-28 03:50:48 +08:00
|
|
|
this.setState({ allLocales: locales });
|
2017-04-06 20:36:59 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-01-27 23:41:11 +08:00
|
|
|
handleUpdateSettings(key, newSettings) {
|
2017-06-03 03:25:02 +08:00
|
|
|
const settings = this.state;
|
2017-01-27 23:41:11 +08:00
|
|
|
settings.current[key] = newSettings;
|
2017-02-25 04:19:53 +08:00
|
|
|
this.setState(settings);
|
2017-01-27 23:41:11 +08:00
|
|
|
}
|
|
|
|
|
2017-02-25 04:19:53 +08:00
|
|
|
handleSelectTab(tab) {
|
2017-01-27 23:41:11 +08:00
|
|
|
this.setState({
|
|
|
|
selectedTab: tab,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-05-01 03:06:28 +08:00
|
|
|
displaySettingsStatus(status) {
|
|
|
|
const { intl } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<span className={styles.toggleLabel}>
|
|
|
|
{status ? intl.formatMessage(intlMessages.on)
|
|
|
|
: intl.formatMessage(intlMessages.off)}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-01-27 23:41:11 +08:00
|
|
|
renderModalContent() {
|
2019-01-26 02:19:54 +08:00
|
|
|
const {
|
|
|
|
intl,
|
2020-07-06 20:56:19 +08:00
|
|
|
isModerator,
|
2021-05-30 23:09:33 +08:00
|
|
|
showGuestNotification,
|
2021-05-01 03:06:28 +08:00
|
|
|
showToggleLabel,
|
2019-01-26 02:19:54 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2019-01-04 01:14:45 +08:00
|
|
|
const {
|
|
|
|
selectedTab,
|
|
|
|
current,
|
2021-01-30 00:17:35 +08:00
|
|
|
allLocales,
|
2019-01-04 01:14:45 +08:00
|
|
|
} = this.state;
|
2019-01-26 02:19:54 +08:00
|
|
|
|
2017-01-27 23:41:11 +08:00
|
|
|
return (
|
|
|
|
<Tabs
|
|
|
|
className={styles.tabs}
|
2017-02-25 04:19:53 +08:00
|
|
|
onSelect={this.handleSelectTab}
|
2019-01-04 01:14:45 +08:00
|
|
|
selectedIndex={selectedTab}
|
2017-04-18 02:19:27 +08:00
|
|
|
role="presentation"
|
2017-12-19 19:13:37 +08:00
|
|
|
selectedTabPanelClassName={styles.selectedTab}
|
2017-01-27 23:41:11 +08:00
|
|
|
>
|
2018-01-30 19:20:51 +08:00
|
|
|
<TabList className={styles.tabList}>
|
2017-12-19 19:13:37 +08:00
|
|
|
<Tab
|
|
|
|
className={styles.tabSelector}
|
|
|
|
aria-labelledby="appTab"
|
|
|
|
selectedClassName={styles.selected}
|
|
|
|
>
|
2017-06-03 03:25:02 +08:00
|
|
|
<Icon iconName="application" className={styles.icon} />
|
2017-04-18 02:19:27 +08:00
|
|
|
<span id="appTab">{intl.formatMessage(intlMessages.appTabLabel)}</span>
|
2017-03-09 22:34:33 +08:00
|
|
|
</Tab>
|
2020-03-19 22:19:40 +08:00
|
|
|
<Tab
|
|
|
|
className={styles.tabSelector}
|
|
|
|
selectedClassName={styles.selected}
|
|
|
|
>
|
|
|
|
<Icon iconName="alert" className={styles.icon} />
|
2021-02-01 23:57:43 +08:00
|
|
|
<span id="notificationTab">{intl.formatMessage(intlMessages.notificationLabel)}</span>
|
2020-03-19 22:19:40 +08:00
|
|
|
</Tab>
|
2018-01-30 19:20:51 +08:00
|
|
|
<Tab
|
|
|
|
className={styles.tabSelector}
|
2018-01-31 00:41:45 +08:00
|
|
|
aria-labelledby="dataSavingTab"
|
2018-01-30 19:20:51 +08:00
|
|
|
selectedClassName={styles.selected}
|
|
|
|
>
|
2018-02-06 21:33:48 +08:00
|
|
|
<Icon iconName="network" className={styles.icon} />
|
2018-02-01 19:31:17 +08:00
|
|
|
<span id="dataSaving">{intl.formatMessage(intlMessages.dataSavingLabel)}</span>
|
2018-01-30 19:20:51 +08:00
|
|
|
</Tab>
|
2017-01-27 23:41:11 +08:00
|
|
|
</TabList>
|
2017-03-09 22:34:33 +08:00
|
|
|
<TabPanel className={styles.tabPanel}>
|
|
|
|
<Application
|
2021-01-30 00:17:35 +08:00
|
|
|
allLocales={allLocales}
|
2017-03-09 22:34:33 +08:00
|
|
|
handleUpdateSettings={this.handleUpdateSettings}
|
2019-01-04 01:14:45 +08:00
|
|
|
settings={current.application}
|
2021-05-01 03:06:28 +08:00
|
|
|
showToggleLabel={showToggleLabel}
|
|
|
|
displaySettingsStatus={this.displaySettingsStatus}
|
2017-06-03 03:25:02 +08:00
|
|
|
/>
|
2017-03-09 22:34:33 +08:00
|
|
|
</TabPanel>
|
2020-03-19 22:19:40 +08:00
|
|
|
<TabPanel className={styles.tabPanel}>
|
|
|
|
<Notification
|
|
|
|
handleUpdateSettings={this.handleUpdateSettings}
|
|
|
|
settings={current.application}
|
2021-05-30 23:09:33 +08:00
|
|
|
showGuestNotification={showGuestNotification}
|
2021-05-01 03:06:28 +08:00
|
|
|
showToggleLabel={showToggleLabel}
|
|
|
|
displaySettingsStatus={this.displaySettingsStatus}
|
2020-07-06 20:56:19 +08:00
|
|
|
{...{ isModerator }}
|
2020-03-19 22:19:40 +08:00
|
|
|
/>
|
|
|
|
</TabPanel>
|
2018-01-30 19:20:51 +08:00
|
|
|
<TabPanel className={styles.tabPanel}>
|
2018-01-31 00:32:37 +08:00
|
|
|
<DataSaving
|
2019-01-04 01:14:45 +08:00
|
|
|
settings={current.dataSaving}
|
2018-01-31 00:32:37 +08:00
|
|
|
handleUpdateSettings={this.handleUpdateSettings}
|
2021-05-01 03:06:28 +08:00
|
|
|
showToggleLabel={showToggleLabel}
|
|
|
|
displaySettingsStatus={this.displaySettingsStatus}
|
2018-01-31 00:32:37 +08:00
|
|
|
/>
|
2018-01-30 19:20:51 +08:00
|
|
|
</TabPanel>
|
2017-01-27 23:41:11 +08:00
|
|
|
</Tabs>
|
|
|
|
);
|
|
|
|
}
|
2019-01-04 01:14:45 +08:00
|
|
|
|
2017-10-11 06:08:51 +08:00
|
|
|
render() {
|
2018-02-07 04:06:52 +08:00
|
|
|
const {
|
|
|
|
intl,
|
2018-07-03 23:09:20 +08:00
|
|
|
mountModal,
|
2018-02-07 04:06:52 +08:00
|
|
|
} = this.props;
|
2019-01-04 01:14:45 +08:00
|
|
|
const {
|
|
|
|
current,
|
|
|
|
saved,
|
|
|
|
} = this.state;
|
2017-10-11 06:08:51 +08:00
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
title={intl.formatMessage(intlMessages.SettingsLabel)}
|
|
|
|
confirm={{
|
2018-04-17 01:41:23 +08:00
|
|
|
callback: () => {
|
2019-05-23 02:54:30 +08:00
|
|
|
this.updateSettings(current, intl.formatMessage(intlMessages.savedAlertLabel));
|
2021-04-20 19:51:15 +08:00
|
|
|
document.getElementsByTagName('html')[0].lang = current.application.locale;
|
2018-04-17 23:06:19 +08:00
|
|
|
/* We need to use mountModal(null) here to prevent submenu state updates,
|
|
|
|
* from re-opening the modal.
|
|
|
|
*/
|
2018-07-03 23:09:20 +08:00
|
|
|
mountModal(null);
|
2018-04-17 01:41:23 +08:00
|
|
|
},
|
2017-10-11 06:08:51 +08:00
|
|
|
label: intl.formatMessage(intlMessages.SaveLabel),
|
|
|
|
description: intl.formatMessage(intlMessages.SaveLabelDesc),
|
|
|
|
}}
|
|
|
|
dismiss={{
|
2018-06-23 01:30:40 +08:00
|
|
|
callback: () => {
|
2019-01-04 01:14:45 +08:00
|
|
|
Settings.setHtmlFontSize(saved.application.fontSize);
|
2021-04-20 19:51:15 +08:00
|
|
|
document.getElementsByTagName('html')[0].lang = saved.application.locale;
|
2018-07-03 23:09:20 +08:00
|
|
|
mountModal(null);
|
2018-06-23 01:30:40 +08:00
|
|
|
},
|
2017-10-11 06:08:51 +08:00
|
|
|
label: intl.formatMessage(intlMessages.CancelLabel),
|
|
|
|
description: intl.formatMessage(intlMessages.CancelLabelDesc),
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{this.renderModalContent()}
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
2017-01-27 23:41:11 +08:00
|
|
|
}
|
|
|
|
|
2017-02-16 02:49:40 +08:00
|
|
|
Settings.propTypes = propTypes;
|
2017-05-04 05:39:07 +08:00
|
|
|
export default withModalMounter(injectIntl(Settings));
|