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 12KB

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