選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ProfileTab.tsx 6.0KB

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