You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SettingsDialog.js 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import { DialogWithTabs, hideDialog } from '../../../base/dialog';
  5. import {
  6. DeviceSelection,
  7. getDeviceSelectionDialogProps,
  8. submitDeviceSelectionTab
  9. } from '../../../device-selection';
  10. import MoreTab from './MoreTab';
  11. import ProfileTab from './ProfileTab';
  12. import { getMoreTabProps, getProfileTabProps } from '../../functions';
  13. import { submitMoreTab, submitProfileTab } from '../../actions';
  14. import { SETTINGS_TABS } from '../../constants';
  15. declare var APP: Object;
  16. declare var interfaceConfig: Object;
  17. /**
  18. * The type of the React {@code Component} props of
  19. * {@link ConnectedSettingsDialog}.
  20. */
  21. type Props = {
  22. /**
  23. * Which settings tab should be initially displayed. If not defined then
  24. * the first tab will be displayed.
  25. */
  26. defaultTab: string,
  27. /**
  28. * Information about the tabs to be rendered.
  29. */
  30. _tabs: Array<Object>,
  31. /**
  32. * Invoked to save changed settings.
  33. */
  34. dispatch: Function,
  35. };
  36. /**
  37. * A React {@code Component} for displaying a dialog to modify local settings
  38. * and conference-wide (moderator) settings. This version is connected to
  39. * redux to get the current settings.
  40. *
  41. * @extends Component
  42. */
  43. class SettingsDialog extends Component<Props> {
  44. /**
  45. * Initializes a new {@code ConnectedSettingsDialog} instance.
  46. *
  47. * @param {Props} props - The React {@code Component} props to initialize
  48. * the new {@code ConnectedSettingsDialog} instance with.
  49. */
  50. constructor(props: Props) {
  51. super(props);
  52. // Bind event handlers so they are only bound once for every instance.
  53. this._closeDialog = this._closeDialog.bind(this);
  54. }
  55. /**
  56. * Implements React's {@link Component#render()}.
  57. *
  58. * @inheritdoc
  59. * @returns {ReactElement}
  60. */
  61. render() {
  62. const { _tabs, defaultTab, dispatch } = this.props;
  63. const onSubmit = this._closeDialog;
  64. const defaultTabIdx
  65. = _tabs.findIndex(({ name }) => name === defaultTab);
  66. const tabs = _tabs.map(tab => {
  67. return {
  68. ...tab,
  69. submit: (...args) => dispatch(tab.submit(...args))
  70. };
  71. });
  72. return (
  73. <DialogWithTabs
  74. closeDialog = { this._closeDialog }
  75. defaultTab = {
  76. defaultTabIdx === -1 ? undefined : defaultTabIdx
  77. }
  78. onSubmit = { onSubmit }
  79. tabs = { tabs } />
  80. );
  81. }
  82. _closeDialog: () => void;
  83. /**
  84. * Callback invoked to close the dialog without saving changes.
  85. *
  86. * @private
  87. * @returns {void}
  88. */
  89. _closeDialog() {
  90. this.props.dispatch(hideDialog());
  91. }
  92. }
  93. /**
  94. * Maps (parts of) the Redux state to the associated props for the
  95. * {@code ConnectedSettingsDialog} component.
  96. *
  97. * @param {Object} state - The Redux state.
  98. * @private
  99. * @returns {{
  100. * tabs: Array<Object>
  101. * }}
  102. */
  103. function _mapStateToProps(state) {
  104. const configuredTabs = interfaceConfig.SETTINGS_SECTIONS || [];
  105. const jwt = state['features/base/jwt'];
  106. // The settings sections to display.
  107. const showDeviceSettings = configuredTabs.includes('devices');
  108. const moreTabProps = getMoreTabProps(state);
  109. const { showModeratorSettings, showLanguageSettings } = moreTabProps;
  110. const showProfileSettings
  111. = configuredTabs.includes('profile') && jwt.isGuest;
  112. const tabs = [];
  113. if (showDeviceSettings) {
  114. tabs.push({
  115. name: SETTINGS_TABS.DEVICES,
  116. component: DeviceSelection,
  117. label: 'settings.devices',
  118. props: getDeviceSelectionDialogProps(state),
  119. styles: 'settings-pane devices-pane',
  120. submit: submitDeviceSelectionTab
  121. });
  122. }
  123. if (showProfileSettings) {
  124. tabs.push({
  125. name: SETTINGS_TABS.PROFILE,
  126. component: ProfileTab,
  127. label: 'profile.title',
  128. props: getProfileTabProps(state),
  129. styles: 'settings-pane profile-pane',
  130. submit: submitProfileTab
  131. });
  132. }
  133. if (showModeratorSettings || showLanguageSettings) {
  134. tabs.push({
  135. name: SETTINGS_TABS.MORE,
  136. component: MoreTab,
  137. label: 'settings.more',
  138. props: moreTabProps,
  139. styles: 'settings-pane more-pane',
  140. submit: submitMoreTab
  141. });
  142. }
  143. return { _tabs: tabs };
  144. }
  145. export default connect(_mapStateToProps)(SettingsDialog);