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.6KB

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