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.tsx 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. /* eslint-disable lines-around-comment */
  2. import { Theme } from '@mui/material';
  3. import { withStyles } from '@mui/styles';
  4. import React, { Component } from 'react';
  5. import { IReduxState } from '../../../app/types';
  6. import { getAvailableDevices } from '../../../base/devices/actions';
  7. // @ts-ignore
  8. import { DialogWithTabs } from '../../../base/dialog';
  9. import { hideDialog } from '../../../base/dialog/actions';
  10. import { connect } from '../../../base/redux/functions';
  11. import { withPixelLineHeight } from '../../../base/styles/functions.web';
  12. // @ts-ignore
  13. import { isCalendarEnabled } from '../../../calendar-sync';
  14. import {
  15. DeviceSelection,
  16. getDeviceSelectionDialogProps,
  17. submitDeviceSelectionTab
  18. // @ts-ignore
  19. } from '../../../device-selection';
  20. import {
  21. submitModeratorTab,
  22. submitMoreTab,
  23. submitProfileTab,
  24. submitSoundsTab
  25. } from '../../actions';
  26. import { SETTINGS_TABS } from '../../constants';
  27. import {
  28. getModeratorTabProps,
  29. getMoreTabProps,
  30. getProfileTabProps,
  31. getSoundsTabProps
  32. } from '../../functions';
  33. // @ts-ignore
  34. import CalendarTab from './CalendarTab';
  35. import ModeratorTab from './ModeratorTab';
  36. import MoreTab from './MoreTab';
  37. import ProfileTab from './ProfileTab';
  38. import SoundsTab from './SoundsTab';
  39. /* eslint-enable lines-around-comment */
  40. /**
  41. * The type of the React {@code Component} props of
  42. * {@link ConnectedSettingsDialog}.
  43. */
  44. interface IProps {
  45. /**
  46. * Information about the tabs to be rendered.
  47. */
  48. _tabs: Array<{
  49. name: string;
  50. onMount: () => void;
  51. submit: () => void;
  52. }>;
  53. /**
  54. * An object containing the CSS classes.
  55. */
  56. classes: Object;
  57. /**
  58. * Which settings tab should be initially displayed. If not defined then
  59. * the first tab will be displayed.
  60. */
  61. defaultTab: string;
  62. /**
  63. * Invoked to save changed settings.
  64. */
  65. dispatch: Function;
  66. /**
  67. * Indicates whether the device selection dialog is displayed on the
  68. * welcome page or not.
  69. */
  70. isDisplayedOnWelcomePage: boolean;
  71. }
  72. /**
  73. * Creates the styles for the component.
  74. *
  75. * @param {Object} theme - The current UI theme.
  76. *
  77. * @returns {Object}
  78. */
  79. const styles = (theme: Theme) => {
  80. return {
  81. settingsDialog: {
  82. display: 'flex',
  83. width: '100%',
  84. '&.profile-pane': {
  85. flexDirection: 'column'
  86. },
  87. '& .auth-name': {
  88. marginBottom: theme.spacing(1)
  89. },
  90. '& .calendar-tab, & .device-selection': {
  91. marginTop: '20px'
  92. },
  93. '& .mock-atlaskit-label': {
  94. color: '#b8c7e0',
  95. fontSize: '12px',
  96. fontWeight: 600,
  97. lineHeight: 1.33,
  98. padding: `20px 0px ${theme.spacing(1)} 0px`
  99. },
  100. '& .checkbox-label': {
  101. color: theme.palette.text01,
  102. ...withPixelLineHeight(theme.typography.bodyShortRegular),
  103. marginBottom: theme.spacing(2),
  104. display: 'block',
  105. marginTop: '20px'
  106. },
  107. '& input[type="checkbox"]:checked + svg': {
  108. '--checkbox-background-color': '#6492e7',
  109. '--checkbox-border-color': '#6492e7'
  110. },
  111. '& input[type="checkbox"] + svg + span': {
  112. color: '#9FB0CC'
  113. },
  114. // @ts-ignore
  115. [[ '& .calendar-tab',
  116. '& .more-tab',
  117. '& .box' ]]: {
  118. display: 'flex',
  119. justifyContent: 'space-between',
  120. width: '100%'
  121. },
  122. '& .profile-edit': {
  123. display: 'flex',
  124. width: '100%'
  125. },
  126. '& .profile-edit-field': {
  127. flex: 0.5,
  128. marginRight: '20px',
  129. marginTop: theme.spacing(3)
  130. },
  131. '& .settings-sub-pane': {
  132. flex: 1
  133. },
  134. '& .settings-sub-pane .right': {
  135. flex: 1
  136. },
  137. '& .settings-sub-pane .left': {
  138. flex: 1
  139. },
  140. '& .settings-sub-pane-element': {
  141. textAlign: 'left',
  142. flex: 1
  143. },
  144. '& .dropdown-menu': {
  145. marginTop: '20px'
  146. },
  147. '& .settings-checkbox': {
  148. display: 'flex',
  149. marginBottom: theme.spacing(2)
  150. },
  151. '& .moderator-settings-wrapper': {
  152. paddingTop: '20px'
  153. },
  154. '& .calendar-tab': {
  155. alignItems: 'center',
  156. flexDirection: 'column',
  157. fontSize: '14px',
  158. minHeight: '100px',
  159. textAlign: 'center'
  160. },
  161. '& .calendar-tab-sign-in': {
  162. marginTop: '20px'
  163. },
  164. '& .sign-out-cta': {
  165. marginBottom: '20px'
  166. },
  167. '& .sign-out-cta-button': {
  168. display: 'flex',
  169. justifyContent: 'center'
  170. },
  171. '@media only screen and (max-width: 700px)': {
  172. '& .device-selection': {
  173. display: 'flex',
  174. flexDirection: 'column'
  175. },
  176. '& .more-tab': {
  177. flexDirection: 'column'
  178. }
  179. }
  180. }
  181. };
  182. };
  183. /**
  184. * A React {@code Component} for displaying a dialog to modify local settings
  185. * and conference-wide (moderator) settings. This version is connected to
  186. * redux to get the current settings.
  187. *
  188. * @augments Component
  189. */
  190. class SettingsDialog extends Component<IProps> {
  191. /**
  192. * Initializes a new {@code ConnectedSettingsDialog} instance.
  193. *
  194. * @param {IProps} props - The React {@code Component} props to initialize
  195. * the new {@code ConnectedSettingsDialog} instance with.
  196. */
  197. constructor(props: IProps) {
  198. super(props);
  199. // Bind event handlers so they are only bound once for every instance.
  200. this._closeDialog = this._closeDialog.bind(this);
  201. }
  202. /**
  203. * Implements React's {@link Component#render()}.
  204. *
  205. * @inheritdoc
  206. * @returns {ReactElement}
  207. */
  208. render() {
  209. const { _tabs, defaultTab, dispatch } = this.props;
  210. const onSubmit = this._closeDialog;
  211. const defaultTabIdx
  212. = _tabs.findIndex(({ name }) => name === defaultTab);
  213. const tabs = _tabs.map(tab => {
  214. return {
  215. ...tab,
  216. onMount: tab.onMount
  217. // @ts-ignore
  218. ? (...args: any) => dispatch(tab.onMount(...args))
  219. : undefined,
  220. submit: (...args: any) => tab.submit
  221. // @ts-ignore
  222. && dispatch(tab.submit(...args))
  223. };
  224. });
  225. return (
  226. <DialogWithTabs
  227. closeDialog = { this._closeDialog }
  228. cssClassName = 'settings-dialog'
  229. defaultTab = {
  230. defaultTabIdx === -1 ? undefined : defaultTabIdx
  231. }
  232. onSubmit = { onSubmit }
  233. tabs = { tabs }
  234. titleKey = 'settings.title' />
  235. );
  236. }
  237. /**
  238. * Callback invoked to close the dialog without saving changes.
  239. *
  240. * @private
  241. * @returns {void}
  242. */
  243. _closeDialog() {
  244. this.props.dispatch(hideDialog());
  245. }
  246. }
  247. /**
  248. * Maps (parts of) the Redux state to the associated props for the
  249. * {@code ConnectedSettingsDialog} component.
  250. *
  251. * @param {Object} state - The Redux state.
  252. * @param {Object} ownProps - The props passed to the component.
  253. * @private
  254. * @returns {{
  255. * tabs: Array<Object>
  256. * }}
  257. */
  258. function _mapStateToProps(state: IReduxState, ownProps: any) {
  259. const { classes, isDisplayedOnWelcomePage } = ownProps;
  260. const configuredTabs = interfaceConfig.SETTINGS_SECTIONS || [];
  261. // The settings sections to display.
  262. const showDeviceSettings = configuredTabs.includes('devices');
  263. const moreTabProps = getMoreTabProps(state);
  264. const moderatorTabProps = getModeratorTabProps(state);
  265. const { showModeratorSettings } = moderatorTabProps;
  266. const showMoreTab = configuredTabs.includes('more');
  267. const showProfileSettings
  268. = configuredTabs.includes('profile') && !state['features/base/config'].disableProfile;
  269. const showCalendarSettings
  270. = configuredTabs.includes('calendar') && isCalendarEnabled(state);
  271. const showSoundsSettings = configuredTabs.includes('sounds');
  272. const tabs = [];
  273. if (showDeviceSettings) {
  274. tabs.push({
  275. name: SETTINGS_TABS.DEVICES,
  276. component: DeviceSelection,
  277. label: 'settings.devices',
  278. onMount: getAvailableDevices,
  279. props: getDeviceSelectionDialogProps(state, isDisplayedOnWelcomePage),
  280. propsUpdateFunction: (tabState: any, newProps: any) => {
  281. // Ensure the device selection tab gets updated when new devices
  282. // are found by taking the new props and only preserving the
  283. // current user selected devices. If this were not done, the
  284. // tab would keep using a copy of the initial props it received,
  285. // leaving the device list to become stale.
  286. return {
  287. ...newProps,
  288. selectedAudioInputId: tabState.selectedAudioInputId,
  289. selectedAudioOutputId: tabState.selectedAudioOutputId,
  290. selectedVideoInputId: tabState.selectedVideoInputId
  291. };
  292. },
  293. styles: `settings-pane ${classes.settingsDialog} devices-pane`,
  294. submit: (newState: any) => submitDeviceSelectionTab(newState, isDisplayedOnWelcomePage)
  295. });
  296. }
  297. if (showProfileSettings) {
  298. tabs.push({
  299. name: SETTINGS_TABS.PROFILE,
  300. component: ProfileTab,
  301. label: 'profile.title',
  302. props: getProfileTabProps(state),
  303. styles: `settings-pane ${classes.settingsDialog} profile-pane`,
  304. submit: submitProfileTab
  305. });
  306. }
  307. if (showModeratorSettings) {
  308. tabs.push({
  309. name: SETTINGS_TABS.MODERATOR,
  310. component: ModeratorTab,
  311. label: 'settings.moderator',
  312. props: moderatorTabProps,
  313. propsUpdateFunction: (tabState: any, newProps: any) => {
  314. // Updates tab props, keeping users selection
  315. return {
  316. ...newProps,
  317. followMeEnabled: tabState?.followMeEnabled,
  318. startAudioMuted: tabState?.startAudioMuted,
  319. startVideoMuted: tabState?.startVideoMuted,
  320. startReactionsMuted: tabState?.startReactionsMuted
  321. };
  322. },
  323. styles: `settings-pane ${classes.settingsDialog} moderator-pane`,
  324. submit: submitModeratorTab
  325. });
  326. }
  327. if (showCalendarSettings) {
  328. tabs.push({
  329. name: SETTINGS_TABS.CALENDAR,
  330. component: CalendarTab,
  331. label: 'settings.calendar.title',
  332. styles: `settings-pane ${classes.settingsDialog} calendar-pane`
  333. });
  334. }
  335. if (showSoundsSettings) {
  336. tabs.push({
  337. name: SETTINGS_TABS.SOUNDS,
  338. component: SoundsTab,
  339. label: 'settings.sounds',
  340. props: getSoundsTabProps(state),
  341. styles: `settings-pane ${classes.settingsDialog} profile-pane`,
  342. submit: submitSoundsTab
  343. });
  344. }
  345. if (showMoreTab) {
  346. tabs.push({
  347. name: SETTINGS_TABS.MORE,
  348. component: MoreTab,
  349. label: 'settings.more',
  350. props: moreTabProps,
  351. propsUpdateFunction: (tabState: any, newProps: any) => {
  352. // Updates tab props, keeping users selection
  353. return {
  354. ...newProps,
  355. currentFramerate: tabState?.currentFramerate,
  356. currentLanguage: tabState?.currentLanguage,
  357. hideSelfView: tabState?.hideSelfView,
  358. showPrejoinPage: tabState?.showPrejoinPage,
  359. enabledNotifications: tabState?.enabledNotifications || {},
  360. maxStageParticipants: tabState?.maxStageParticipants
  361. };
  362. },
  363. styles: `settings-pane ${classes.settingsDialog} more-pane`,
  364. submit: submitMoreTab
  365. });
  366. }
  367. return { _tabs: tabs };
  368. }
  369. export default withStyles(styles)(connect(_mapStateToProps)(SettingsDialog));