Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ProfileTab.tsx 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /* eslint-disable lines-around-comment */
  2. import React from 'react';
  3. import { WithTranslation } from 'react-i18next';
  4. // @ts-expect-error
  5. import UIEvents from '../../../../../service/UI/UIEvents';
  6. import { createProfilePanelButtonEvent } from '../../../analytics/AnalyticsEvents';
  7. import { sendAnalytics } from '../../../analytics/functions';
  8. // @ts-ignore
  9. import { AbstractDialogTab } from '../../../base/dialog';
  10. // @ts-ignore
  11. import type { Props as AbstractDialogTabProps } from '../../../base/dialog';
  12. import { translate } from '../../../base/i18n/functions';
  13. import { Button } from '../../../base/ui/components/web';
  14. import Input from '../../../base/ui/components/web/Input';
  15. // @ts-ignore
  16. import { openLogoutDialog } from '../../actions';
  17. declare let APP: any;
  18. /**
  19. * The type of the React {@code Component} props of {@link ProfileTab}.
  20. */
  21. export type Props = AbstractDialogTabProps & WithTranslation & {
  22. /**
  23. * Whether or not server-side authentication is available.
  24. */
  25. authEnabled: boolean;
  26. /**
  27. * The name of the currently (server-side) authenticated user.
  28. */
  29. authLogin: string;
  30. /**
  31. * The display name to display for the local participant.
  32. */
  33. displayName: string;
  34. /**
  35. * The email to display for the local participant.
  36. */
  37. email: string;
  38. /**
  39. * Whether to hide the email input in the profile settings.
  40. */
  41. hideEmailInSettings?: boolean;
  42. /**
  43. * If the display name is read only.
  44. */
  45. readOnlyName: boolean;
  46. /**
  47. * Invoked to obtain translated strings.
  48. */
  49. t: Function;
  50. };
  51. /**
  52. * React {@code Component} for modifying the local user's profile.
  53. *
  54. * @augments Component
  55. */
  56. class ProfileTab extends AbstractDialogTab<Props> {
  57. static defaultProps = {
  58. displayName: '',
  59. email: ''
  60. };
  61. /**
  62. * Initializes a new {@code ConnectedSettingsDialog} instance.
  63. *
  64. * @param {Props} props - The React {@code Component} props to initialize
  65. * the new {@code ConnectedSettingsDialog} instance with.
  66. */
  67. constructor(props: Props) {
  68. super(props);
  69. // Bind event handlers so they are only bound once for every instance.
  70. this._onAuthToggle = this._onAuthToggle.bind(this);
  71. this._onDisplayNameChange = this._onDisplayNameChange.bind(this);
  72. this._onEmailChange = this._onEmailChange.bind(this);
  73. }
  74. /**
  75. * Changes display name of the user.
  76. *
  77. * @param {string} value - The key event to handle.
  78. *
  79. * @returns {void}
  80. */
  81. _onDisplayNameChange(value: string) {
  82. super._onChange({ displayName: value });
  83. }
  84. /**
  85. * Changes email of the user.
  86. *
  87. * @param {string} value - The key event to handle.
  88. *
  89. * @returns {void}
  90. */
  91. _onEmailChange(value: string) {
  92. super._onChange({ email: value });
  93. }
  94. /**
  95. * Implements React's {@link Component#render()}.
  96. *
  97. * @inheritdoc
  98. * @returns {ReactElement}
  99. */
  100. render() {
  101. const {
  102. authEnabled,
  103. displayName,
  104. email,
  105. hideEmailInSettings,
  106. readOnlyName,
  107. t // @ts-ignore
  108. } = this.props;
  109. return (
  110. <div>
  111. <div className = 'profile-edit'>
  112. <div className = 'profile-edit-field'>
  113. <Input
  114. disabled = { readOnlyName }
  115. id = 'setDisplayName'
  116. label = { t('profile.setDisplayNameLabel') }
  117. name = 'name'
  118. onChange = { this._onDisplayNameChange }
  119. placeholder = { t('settings.name') }
  120. type = 'text'
  121. value = { displayName } />
  122. </div>
  123. {!hideEmailInSettings && <div className = 'profile-edit-field'>
  124. <Input
  125. id = 'setEmail'
  126. label = { t('profile.setEmailLabel') }
  127. name = 'email'
  128. onChange = { this._onEmailChange }
  129. placeholder = { t('profile.setEmailInput') }
  130. type = 'text'
  131. value = { email } />
  132. </div>}
  133. </div>
  134. { authEnabled && this._renderAuth() }
  135. </div>
  136. );
  137. }
  138. /**
  139. * Shows the dialog for logging in or out of a server and closes this
  140. * dialog.
  141. *
  142. * @private
  143. * @returns {void}
  144. */
  145. _onAuthToggle() {
  146. // @ts-ignore
  147. if (this.props.authLogin) {
  148. sendAnalytics(createProfilePanelButtonEvent('logout.button'));
  149. APP.store.dispatch(openLogoutDialog(
  150. () => APP.UI.emitEvent(UIEvents.LOGOUT)
  151. ));
  152. } else {
  153. sendAnalytics(createProfilePanelButtonEvent('login.button'));
  154. APP.UI.emitEvent(UIEvents.AUTH_CLICKED);
  155. }
  156. }
  157. /**
  158. * Returns a React Element for interacting with server-side authentication.
  159. *
  160. * @private
  161. * @returns {ReactElement}
  162. */
  163. _renderAuth() {
  164. const {
  165. authLogin,
  166. t
  167. // @ts-ignore
  168. } = this.props;
  169. return (
  170. <div>
  171. <h2 className = 'mock-atlaskit-label'>
  172. { t('toolbar.authenticate') }
  173. </h2>
  174. { authLogin
  175. && <div className = 'auth-name'>
  176. { t('settings.loggedIn', { name: authLogin }) }
  177. </div> }
  178. <Button
  179. accessibilityLabel = { authLogin ? t('toolbar.logout') : t('toolbar.login') }
  180. id = 'login_button'
  181. label = { authLogin ? t('toolbar.logout') : t('toolbar.login') }
  182. onClick = { this._onAuthToggle } />
  183. </div>
  184. );
  185. }
  186. }
  187. // @ts-ignore
  188. export default translate(ProfileTab);