Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ProfileTab.tsx 9.5KB

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