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

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