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

ProfileTab.js 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. // @flow
  2. import Button from '@atlaskit/button/standard-button';
  3. import { FieldTextStateless } from '@atlaskit/field-text';
  4. import React from 'react';
  5. import UIEvents from '../../../../../service/UI/UIEvents';
  6. import {
  7. sendAnalytics,
  8. createProfilePanelButtonEvent
  9. } from '../../../analytics';
  10. import { AbstractDialogTab } from '../../../base/dialog';
  11. import type { Props as AbstractDialogTabProps } from '../../../base/dialog';
  12. import { translate } from '../../../base/i18n';
  13. import { openLogoutDialog } from '../../actions';
  14. declare var APP: Object;
  15. /**
  16. * The type of the React {@code Component} props of {@link ProfileTab}.
  17. */
  18. export type Props = {
  19. ...$Exact<AbstractDialogTabProps>,
  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. * If the display name is read only.
  38. */
  39. readOnlyName: boolean,
  40. /**
  41. * Whether to hide the email input in the profile settings.
  42. */
  43. hideEmailInSettings?: 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. _onDisplayNameChange: (Object) => void;
  73. /**
  74. * Changes display name of the user.
  75. *
  76. * @param {Object} e - The key event to handle.
  77. *
  78. * @returns {void}
  79. */
  80. _onDisplayNameChange({ target: { value } }) {
  81. super._onChange({ displayName: value });
  82. }
  83. _onEmailChange: (Object) => void;
  84. /**
  85. * Changes email of the user.
  86. *
  87. * @param {Object} e - The key event to handle.
  88. *
  89. * @returns {void}
  90. */
  91. _onEmailChange({ target: { value } }) {
  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
  108. } = this.props;
  109. return (
  110. <div>
  111. <div className = 'profile-edit'>
  112. <div className = 'profile-edit-field'>
  113. <FieldTextStateless
  114. autoComplete = 'name'
  115. compact = { true }
  116. id = 'setDisplayName'
  117. isReadOnly = { readOnlyName }
  118. label = { t('profile.setDisplayNameLabel') }
  119. onChange = { this._onDisplayNameChange }
  120. placeholder = { t('settings.name') }
  121. shouldFitContainer = { true }
  122. type = 'text'
  123. value = { displayName } />
  124. </div>
  125. {!hideEmailInSettings && <div className = 'profile-edit-field'>
  126. <FieldTextStateless
  127. compact = { true }
  128. id = 'setEmail'
  129. label = { t('profile.setEmailLabel') }
  130. onChange = { this._onEmailChange }
  131. placeholder = { t('profile.setEmailInput') }
  132. shouldFitContainer = { true }
  133. type = 'text'
  134. value = { email } />
  135. </div>}
  136. </div>
  137. { authEnabled && this._renderAuth() }
  138. </div>
  139. );
  140. }
  141. _onAuthToggle: () => void;
  142. /**
  143. * Shows the dialog for logging in or out of a server and closes this
  144. * dialog.
  145. *
  146. * @private
  147. * @returns {void}
  148. */
  149. _onAuthToggle() {
  150. if (this.props.authLogin) {
  151. sendAnalytics(createProfilePanelButtonEvent('logout.button'));
  152. APP.store.dispatch(openLogoutDialog(
  153. () => APP.UI.emitEvent(UIEvents.LOGOUT)
  154. ));
  155. } else {
  156. sendAnalytics(createProfilePanelButtonEvent('login.button'));
  157. APP.UI.emitEvent(UIEvents.AUTH_CLICKED);
  158. }
  159. }
  160. /**
  161. * Returns a React Element for interacting with server-side authentication.
  162. *
  163. * @private
  164. * @returns {ReactElement}
  165. */
  166. _renderAuth() {
  167. const {
  168. authLogin,
  169. t
  170. } = this.props;
  171. return (
  172. <div>
  173. <h2 className = 'mock-atlaskit-label'>
  174. { t('toolbar.authenticate') }
  175. </h2>
  176. { authLogin
  177. && <div className = 'auth-name'>
  178. { t('settings.loggedIn', { name: authLogin }) }
  179. </div> }
  180. <Button
  181. appearance = 'primary'
  182. id = 'login_button'
  183. onClick = { this._onAuthToggle }
  184. type = 'button'>
  185. { authLogin ? t('toolbar.logout') : t('toolbar.login') }
  186. </Button>
  187. </div>
  188. );
  189. }
  190. }
  191. export default translate(ProfileTab);