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.

ProfileTab.tsx 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. import { Theme } from '@mui/material';
  2. import { withStyles } from '@mui/styles';
  3. import React from 'react';
  4. import { WithTranslation } from 'react-i18next';
  5. // @ts-expect-error
  6. import UIEvents from '../../../../../service/UI/UIEvents';
  7. import { createProfilePanelButtonEvent } from '../../../analytics/AnalyticsEvents';
  8. import { sendAnalytics } from '../../../analytics/functions';
  9. // eslint-disable-next-line lines-around-comment
  10. // @ts-ignore
  11. import Avatar from '../../../base/avatar/components/Avatar';
  12. import AbstractDialogTab, {
  13. IProps as AbstractDialogTabProps } from '../../../base/dialog/components/web/AbstractDialogTab';
  14. import { translate } from '../../../base/i18n/functions';
  15. import { withPixelLineHeight } from '../../../base/styles/functions.web';
  16. import Button from '../../../base/ui/components/web/Button';
  17. import Checkbox from '../../../base/ui/components/web/Checkbox';
  18. import Input from '../../../base/ui/components/web/Input';
  19. import Select from '../../../base/ui/components/web/Select';
  20. import { openLogoutDialog } from '../../actions';
  21. /**
  22. * The type of the React {@code Component} props of {@link ProfileTab}.
  23. */
  24. export interface IProps extends AbstractDialogTabProps, WithTranslation {
  25. /**
  26. * Whether or not server-side authentication is available.
  27. */
  28. authEnabled: boolean;
  29. /**
  30. * The name of the currently (server-side) authenticated user.
  31. */
  32. authLogin: string;
  33. /**
  34. * CSS classes object.
  35. */
  36. classes: any;
  37. /**
  38. * The currently selected language to display in the language select
  39. * dropdown.
  40. */
  41. currentLanguage: string;
  42. /**
  43. * Whether to show hide self view setting.
  44. */
  45. disableHideSelfView: boolean;
  46. /**
  47. * The display name to display for the local participant.
  48. */
  49. displayName: string;
  50. /**
  51. * The email to display for the local participant.
  52. */
  53. email: string;
  54. /**
  55. * Whether to hide the email input in the profile settings.
  56. */
  57. hideEmailInSettings?: boolean;
  58. /**
  59. * Whether or not to hide self-view screen.
  60. */
  61. hideSelfView: boolean;
  62. /**
  63. * The id of the local participant.
  64. */
  65. id: string;
  66. /**
  67. * All available languages to display in the language select dropdown.
  68. */
  69. languages: Array<string>;
  70. /**
  71. * If the display name is read only.
  72. */
  73. readOnlyName: boolean;
  74. /**
  75. * Whether or not to display the language select dropdown.
  76. */
  77. showLanguageSettings: boolean;
  78. }
  79. const styles = (theme: Theme) => {
  80. return {
  81. container: {
  82. display: 'flex',
  83. flexDirection: 'column' as const,
  84. width: '100%',
  85. padding: '0 2px'
  86. },
  87. avatarContainer: {
  88. display: 'flex',
  89. width: '100%',
  90. justifyContent: 'center',
  91. marginBottom: theme.spacing(4)
  92. },
  93. bottomMargin: {
  94. marginBottom: theme.spacing(4)
  95. },
  96. label: {
  97. color: `${theme.palette.text01} !important`,
  98. ...withPixelLineHeight(theme.typography.bodyShortRegular),
  99. marginBottom: theme.spacing(2)
  100. },
  101. name: {
  102. marginBottom: theme.spacing(1)
  103. }
  104. };
  105. };
  106. /**
  107. * React {@code Component} for modifying the local user's profile.
  108. *
  109. * @augments Component
  110. */
  111. class ProfileTab extends AbstractDialogTab<IProps, any> {
  112. static defaultProps = {
  113. displayName: '',
  114. email: ''
  115. };
  116. /**
  117. * Initializes a new {@code ConnectedSettingsDialog} instance.
  118. *
  119. * @param {IProps} props - The React {@code Component} props to initialize
  120. * the new {@code ConnectedSettingsDialog} instance with.
  121. */
  122. constructor(props: IProps) {
  123. super(props);
  124. // Bind event handlers so they are only bound once for every instance.
  125. this._onAuthToggle = this._onAuthToggle.bind(this);
  126. this._onDisplayNameChange = this._onDisplayNameChange.bind(this);
  127. this._onEmailChange = this._onEmailChange.bind(this);
  128. this._onHideSelfViewChanged = this._onHideSelfViewChanged.bind(this);
  129. this._onLanguageItemSelect = this._onLanguageItemSelect.bind(this);
  130. }
  131. /**
  132. * Changes display name of the user.
  133. *
  134. * @param {string} value - The key event to handle.
  135. *
  136. * @returns {void}
  137. */
  138. _onDisplayNameChange(value: string) {
  139. super._onChange({ displayName: value });
  140. }
  141. /**
  142. * Changes email of the user.
  143. *
  144. * @param {string} value - The key event to handle.
  145. *
  146. * @returns {void}
  147. */
  148. _onEmailChange(value: string) {
  149. super._onChange({ email: value });
  150. }
  151. /**
  152. * Callback invoked to select if hide self view should be enabled.
  153. *
  154. * @param {Object} e - The key event to handle.
  155. *
  156. * @returns {void}
  157. */
  158. _onHideSelfViewChanged({ target: { checked } }: React.ChangeEvent<HTMLInputElement>) {
  159. super._onChange({ hideSelfView: checked });
  160. }
  161. /**
  162. * Callback invoked to select a language from select dropdown.
  163. *
  164. * @param {Object} e - The key event to handle.
  165. *
  166. * @returns {void}
  167. */
  168. _onLanguageItemSelect(e: React.ChangeEvent<HTMLSelectElement>) {
  169. const language = e.target.value;
  170. super._onChange({ currentLanguage: language });
  171. }
  172. /**
  173. * Returns the menu item for changing displayed language.
  174. *
  175. * @private
  176. * @returns {ReactElement}
  177. */
  178. _renderLanguageSelect() {
  179. const {
  180. classes,
  181. currentLanguage,
  182. languages,
  183. t
  184. } = this.props;
  185. const languageItems
  186. = languages.map((language: string) => {
  187. return {
  188. value: language,
  189. label: t(`languages:${language}`)
  190. };
  191. });
  192. return (
  193. <Select
  194. className = { classes.bottomMargin }
  195. label = { t('settings.language') }
  196. onChange = { this._onLanguageItemSelect }
  197. options = { languageItems }
  198. value = { currentLanguage } />
  199. );
  200. }
  201. /**
  202. * Implements React's {@link Component#render()}.
  203. *
  204. * @inheritdoc
  205. * @returns {ReactElement}
  206. */
  207. render() {
  208. const {
  209. authEnabled,
  210. classes,
  211. disableHideSelfView,
  212. displayName,
  213. email,
  214. hideEmailInSettings,
  215. hideSelfView,
  216. id,
  217. readOnlyName,
  218. showLanguageSettings,
  219. t
  220. } = this.props;
  221. return (
  222. <div className = { classes.container } >
  223. <div className = { classes.avatarContainer }>
  224. <Avatar
  225. participantId = { id }
  226. size = { 60 } />
  227. </div>
  228. <Input
  229. className = { classes.bottomMargin }
  230. disabled = { readOnlyName }
  231. id = 'setDisplayName'
  232. label = { t('profile.setDisplayNameLabel') }
  233. name = 'name'
  234. onChange = { this._onDisplayNameChange }
  235. placeholder = { t('settings.name') }
  236. type = 'text'
  237. value = { displayName } />
  238. {!hideEmailInSettings && <div className = 'profile-edit-field'>
  239. <Input
  240. className = { classes.bottomMargin }
  241. id = 'setEmail'
  242. label = { t('profile.setEmailLabel') }
  243. name = 'email'
  244. onChange = { this._onEmailChange }
  245. placeholder = { t('profile.setEmailInput') }
  246. type = 'text'
  247. value = { email } />
  248. </div>}
  249. {!disableHideSelfView && (
  250. <Checkbox
  251. checked = { hideSelfView }
  252. className = { classes.bottomMargin }
  253. label = { t('videothumbnail.hideSelfView') }
  254. name = 'hide-self-view'
  255. onChange = { this._onHideSelfViewChanged } />
  256. )}
  257. {showLanguageSettings && this._renderLanguageSelect()}
  258. { authEnabled && this._renderAuth() }
  259. </div>
  260. );
  261. }
  262. /**
  263. * Shows the dialog for logging in or out of a server and closes this
  264. * dialog.
  265. *
  266. * @private
  267. * @returns {void}
  268. */
  269. _onAuthToggle() {
  270. if (this.props.authLogin) {
  271. sendAnalytics(createProfilePanelButtonEvent('logout.button'));
  272. APP.store.dispatch(openLogoutDialog(
  273. () => APP.UI.emitEvent(UIEvents.LOGOUT)
  274. ));
  275. } else {
  276. sendAnalytics(createProfilePanelButtonEvent('login.button'));
  277. APP.UI.emitEvent(UIEvents.AUTH_CLICKED);
  278. }
  279. }
  280. /**
  281. * Returns a React Element for interacting with server-side authentication.
  282. *
  283. * @private
  284. * @returns {ReactElement}
  285. */
  286. _renderAuth() {
  287. const {
  288. authLogin,
  289. classes,
  290. t
  291. } = this.props;
  292. return (
  293. <div>
  294. <h2 className = { classes.label }>
  295. { t('toolbar.authenticate') }
  296. </h2>
  297. { authLogin
  298. && <div className = { classes.name }>
  299. { t('settings.loggedIn', { name: authLogin }) }
  300. </div> }
  301. <Button
  302. accessibilityLabel = { authLogin ? t('toolbar.logout') : t('toolbar.login') }
  303. id = 'login_button'
  304. label = { authLogin ? t('toolbar.logout') : t('toolbar.login') }
  305. onClick = { this._onAuthToggle } />
  306. </div>
  307. );
  308. }
  309. }
  310. export default withStyles(styles)(translate(ProfileTab));