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

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