您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ProfileTab.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. // @flow
  2. import Button from '@atlaskit/button';
  3. import { FieldTextStateless } from '@atlaskit/field-text';
  4. import React from 'react';
  5. import { AbstractDialogTab } from '../../../base/dialog';
  6. import type { Props as AbstractDialogTabProps } from '../../../base/dialog';
  7. import { translate } from '../../../base/i18n';
  8. import UIEvents from '../../../../../service/UI/UIEvents';
  9. import {
  10. sendAnalytics,
  11. createProfilePanelButtonEvent
  12. } from '../../../analytics';
  13. declare var APP: Object;
  14. /**
  15. * The type of the React {@code Component} props of {@link ProfileTab}.
  16. */
  17. export type Props = {
  18. ...$Exact<AbstractDialogTabProps>,
  19. /**
  20. * Whether or not server-side authentication is available.
  21. */
  22. authEnabled: boolean,
  23. /**
  24. * The name of the currently (server-side) authenticated user.
  25. */
  26. authLogin: string,
  27. /**
  28. * The display name to display for the local participant.
  29. */
  30. displayName: string,
  31. /**
  32. * The email to display for the local participant.
  33. */
  34. email: string,
  35. /**
  36. * Invoked to obtain translated strings.
  37. */
  38. t: Function
  39. }
  40. /**
  41. * React {@code Component} for modifying the local user's profile.
  42. *
  43. * @extends Component
  44. */
  45. class ProfileTab extends AbstractDialogTab<Props> {
  46. /**
  47. * Initializes a new {@code ConnectedSettingsDialog} instance.
  48. *
  49. * @param {Props} props - The React {@code Component} props to initialize
  50. * the new {@code ConnectedSettingsDialog} instance with.
  51. */
  52. constructor(props: Props) {
  53. super(props);
  54. // Bind event handlers so they are only bound once for every instance.
  55. this._onAuthToggle = this._onAuthToggle.bind(this);
  56. }
  57. /**
  58. * Implements React's {@link Component#render()}.
  59. *
  60. * @inheritdoc
  61. * @returns {ReactElement}
  62. */
  63. render() {
  64. const {
  65. authEnabled,
  66. displayName,
  67. email,
  68. t
  69. } = this.props;
  70. return (
  71. <div>
  72. <div className = 'profile-edit'>
  73. <div className = 'profile-edit-field'>
  74. <FieldTextStateless
  75. autoFocus = { true }
  76. compact = { true }
  77. id = 'setDisplayName'
  78. label = { t('profile.setDisplayNameLabel') }
  79. // eslint-disable-next-line react/jsx-no-bind
  80. onChange = {
  81. ({ target: { value } }) =>
  82. super._onChange({ displayName: value })
  83. }
  84. placeholder = { t('settings.name') }
  85. shouldFitContainer = { true }
  86. type = 'text'
  87. value = { displayName } />
  88. </div>
  89. <div className = 'profile-edit-field'>
  90. <FieldTextStateless
  91. compact = { true }
  92. id = 'setEmail'
  93. label = { t('profile.setEmailLabel') }
  94. // eslint-disable-next-line react/jsx-no-bind
  95. onChange = {
  96. ({ target: { value } }) =>
  97. super._onChange({ email: value })
  98. }
  99. placeholder = { t('profile.setEmailInput') }
  100. shouldFitContainer = { true }
  101. type = 'text'
  102. value = { email } />
  103. </div>
  104. </div>
  105. { authEnabled && this._renderAuth() }
  106. </div>
  107. );
  108. }
  109. _onAuthToggle: () => void;
  110. /**
  111. * Shows the dialog for logging in or out of a server and closes this
  112. * dialog.
  113. *
  114. * @private
  115. * @returns {void}
  116. */
  117. _onAuthToggle() {
  118. if (this.props.authLogin) {
  119. sendAnalytics(createProfilePanelButtonEvent('logout.button'));
  120. APP.UI.messageHandler.openTwoButtonDialog({
  121. leftButtonKey: 'dialog.Yes',
  122. msgKey: 'dialog.logoutQuestion',
  123. submitFunction(evt, yes) {
  124. if (yes) {
  125. APP.UI.emitEvent(UIEvents.LOGOUT);
  126. }
  127. },
  128. titleKey: 'dialog.logoutTitle'
  129. });
  130. } else {
  131. sendAnalytics(createProfilePanelButtonEvent('login.button'));
  132. APP.UI.emitEvent(UIEvents.AUTH_CLICKED);
  133. }
  134. this.props.closeDialog();
  135. }
  136. /**
  137. * Returns a React Element for interacting with server-side authentication.
  138. *
  139. * @private
  140. * @returns {ReactElement}
  141. */
  142. _renderAuth() {
  143. const {
  144. authLogin,
  145. t
  146. } = this.props;
  147. return (
  148. <div>
  149. <div className = 'mock-atlaskit-label'>
  150. { t('toolbar.authenticate') }
  151. </div>
  152. { authLogin
  153. && <div className = 'auth-name'>
  154. { t('settings.loggedIn', { name: authLogin }) }
  155. </div> }
  156. <Button
  157. appearance = 'primary'
  158. id = 'login_button'
  159. onClick = { this._onAuthToggle }
  160. type = 'button'>
  161. { authLogin ? t('toolbar.logout') : t('toolbar.login') }
  162. </Button>
  163. </div>
  164. );
  165. }
  166. }
  167. export default translate(ProfileTab);