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.js 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. * Invoked to obtain translated strings.
  38. */
  39. t: Function
  40. }
  41. /**
  42. * React {@code Component} for modifying the local user's profile.
  43. *
  44. * @extends Component
  45. */
  46. class ProfileTab extends AbstractDialogTab<Props> {
  47. static defaultProps = {
  48. displayName: '',
  49. email: ''
  50. };
  51. /**
  52. * Initializes a new {@code ConnectedSettingsDialog} instance.
  53. *
  54. * @param {Props} props - The React {@code Component} props to initialize
  55. * the new {@code ConnectedSettingsDialog} instance with.
  56. */
  57. constructor(props: Props) {
  58. super(props);
  59. // Bind event handlers so they are only bound once for every instance.
  60. this._onAuthToggle = this._onAuthToggle.bind(this);
  61. }
  62. /**
  63. * Implements React's {@link Component#render()}.
  64. *
  65. * @inheritdoc
  66. * @returns {ReactElement}
  67. */
  68. render() {
  69. const {
  70. authEnabled,
  71. displayName,
  72. email,
  73. t
  74. } = this.props;
  75. return (
  76. <div>
  77. <div className = 'profile-edit'>
  78. <div className = 'profile-edit-field'>
  79. <FieldTextStateless
  80. autoFocus = { true }
  81. compact = { true }
  82. id = 'setDisplayName'
  83. label = { t('profile.setDisplayNameLabel') }
  84. // eslint-disable-next-line react/jsx-no-bind
  85. onChange = {
  86. ({ target: { value } }) =>
  87. super._onChange({ displayName: value })
  88. }
  89. placeholder = { t('settings.name') }
  90. shouldFitContainer = { true }
  91. type = 'text'
  92. value = { displayName } />
  93. </div>
  94. <div className = 'profile-edit-field'>
  95. <FieldTextStateless
  96. compact = { true }
  97. id = 'setEmail'
  98. label = { t('profile.setEmailLabel') }
  99. // eslint-disable-next-line react/jsx-no-bind
  100. onChange = {
  101. ({ target: { value } }) =>
  102. super._onChange({ email: value })
  103. }
  104. placeholder = { t('profile.setEmailInput') }
  105. shouldFitContainer = { true }
  106. type = 'text'
  107. value = { email } />
  108. </div>
  109. </div>
  110. { authEnabled && this._renderAuth() }
  111. </div>
  112. );
  113. }
  114. _onAuthToggle: () => void;
  115. /**
  116. * Shows the dialog for logging in or out of a server and closes this
  117. * dialog.
  118. *
  119. * @private
  120. * @returns {void}
  121. */
  122. _onAuthToggle() {
  123. if (this.props.authLogin) {
  124. sendAnalytics(createProfilePanelButtonEvent('logout.button'));
  125. APP.store.dispatch(openLogoutDialog(
  126. () => APP.UI.emitEvent(UIEvents.LOGOUT)
  127. ));
  128. } else {
  129. sendAnalytics(createProfilePanelButtonEvent('login.button'));
  130. APP.UI.emitEvent(UIEvents.AUTH_CLICKED);
  131. }
  132. }
  133. /**
  134. * Returns a React Element for interacting with server-side authentication.
  135. *
  136. * @private
  137. * @returns {ReactElement}
  138. */
  139. _renderAuth() {
  140. const {
  141. authLogin,
  142. t
  143. } = this.props;
  144. return (
  145. <div>
  146. <div className = 'mock-atlaskit-label'>
  147. { t('toolbar.authenticate') }
  148. </div>
  149. { authLogin
  150. && <div className = 'auth-name'>
  151. { t('settings.loggedIn', { name: authLogin }) }
  152. </div> }
  153. <Button
  154. appearance = 'primary'
  155. id = 'login_button'
  156. onClick = { this._onAuthToggle }
  157. type = 'button'>
  158. { authLogin ? t('toolbar.logout') : t('toolbar.login') }
  159. </Button>
  160. </div>
  161. );
  162. }
  163. }
  164. export default translate(ProfileTab);