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

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