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 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. // @flow
  2. import Button from '@atlaskit/button/standard-button';
  3. import Checkbox from '@atlaskit/checkbox';
  4. import { FieldTextStateless } from '@atlaskit/field-text';
  5. import React from 'react';
  6. import UIEvents from '../../../../../service/UI/UIEvents';
  7. import {
  8. sendAnalytics,
  9. createProfilePanelButtonEvent
  10. } from '../../../analytics';
  11. import { AbstractDialogTab } from '../../../base/dialog';
  12. import type { Props as AbstractDialogTabProps } from '../../../base/dialog';
  13. import { translate } from '../../../base/i18n';
  14. import { openLogoutDialog } from '../../actions';
  15. declare var APP: Object;
  16. /**
  17. * The type of the React {@code Component} props of {@link ProfileTab}.
  18. */
  19. export type Props = {
  20. ...$Exact<AbstractDialogTabProps>,
  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. * Whether or not to hide the self view.
  31. */
  32. disableSelfView: boolean,
  33. /**
  34. * The display name to display for the local participant.
  35. */
  36. displayName: string,
  37. /**
  38. * The email to display for the local participant.
  39. */
  40. email: string,
  41. /**
  42. * If the display name is read only.
  43. */
  44. readOnlyName: boolean,
  45. /**
  46. * Whether to hide the email input in the profile settings.
  47. */
  48. hideEmailInSettings?: boolean,
  49. /**
  50. * Invoked to obtain translated strings.
  51. */
  52. t: Function
  53. }
  54. /**
  55. * React {@code Component} for modifying the local user's profile.
  56. *
  57. * @augments Component
  58. */
  59. class ProfileTab extends AbstractDialogTab<Props> {
  60. static defaultProps = {
  61. displayName: '',
  62. email: ''
  63. };
  64. /**
  65. * Initializes a new {@code ConnectedSettingsDialog} instance.
  66. *
  67. * @param {Props} props - The React {@code Component} props to initialize
  68. * the new {@code ConnectedSettingsDialog} instance with.
  69. */
  70. constructor(props: Props) {
  71. super(props);
  72. // Bind event handlers so they are only bound once for every instance.
  73. this._onAuthToggle = this._onAuthToggle.bind(this);
  74. this._onDisplayNameChange = this._onDisplayNameChange.bind(this);
  75. this._onEmailChange = this._onEmailChange.bind(this);
  76. this._onChange = this._onChange.bind(this);
  77. }
  78. _onDisplayNameChange: (Object) => void;
  79. /**
  80. * Changes display name of the user.
  81. *
  82. * @param {Object} e - The key event to handle.
  83. *
  84. * @returns {void}
  85. */
  86. _onDisplayNameChange({ target: { value } }) {
  87. super._onChange({ displayName: value });
  88. }
  89. _onEmailChange: (Object) => void;
  90. /**
  91. * Changes email of the user.
  92. *
  93. * @param {Object} e - The key event to handle.
  94. *
  95. * @returns {void}
  96. */
  97. _onEmailChange({ target: { value } }) {
  98. super._onChange({ email: value });
  99. }
  100. _onChange: (Object) => void;
  101. /**
  102. * Changes the disable self view state.
  103. *
  104. * @param {Object} e - The key event to handle.
  105. *
  106. * @returns {void}
  107. */
  108. _onChange({ target }) {
  109. super._onChange({ disableSelfView: target.checked });
  110. }
  111. /**
  112. * Implements React's {@link Component#render()}.
  113. *
  114. * @inheritdoc
  115. * @returns {ReactElement}
  116. */
  117. render() {
  118. const {
  119. authEnabled,
  120. displayName,
  121. disableSelfView,
  122. email,
  123. hideEmailInSettings,
  124. readOnlyName,
  125. t
  126. } = this.props;
  127. return (
  128. <div>
  129. <div className = 'profile-edit'>
  130. <div className = 'profile-edit-field'>
  131. <FieldTextStateless
  132. autoComplete = 'name'
  133. compact = { true }
  134. id = 'setDisplayName'
  135. isReadOnly = { readOnlyName }
  136. label = { t('profile.setDisplayNameLabel') }
  137. onChange = { this._onDisplayNameChange }
  138. placeholder = { t('settings.name') }
  139. shouldFitContainer = { true }
  140. type = 'text'
  141. value = { displayName } />
  142. </div>
  143. {!hideEmailInSettings && <div className = 'profile-edit-field'>
  144. <FieldTextStateless
  145. compact = { true }
  146. id = 'setEmail'
  147. label = { t('profile.setEmailLabel') }
  148. onChange = { this._onEmailChange }
  149. placeholder = { t('profile.setEmailInput') }
  150. shouldFitContainer = { true }
  151. type = 'text'
  152. value = { email } />
  153. </div>}
  154. </div>
  155. <br />
  156. <Checkbox
  157. isChecked = { disableSelfView }
  158. label = { t('videothumbnail.hideSelfView') }
  159. name = 'disableSelfView'
  160. onChange = { this._onChange } />
  161. { authEnabled && this._renderAuth() }
  162. </div>
  163. );
  164. }
  165. _onAuthToggle: () => void;
  166. /**
  167. * Shows the dialog for logging in or out of a server and closes this
  168. * dialog.
  169. *
  170. * @private
  171. * @returns {void}
  172. */
  173. _onAuthToggle() {
  174. if (this.props.authLogin) {
  175. sendAnalytics(createProfilePanelButtonEvent('logout.button'));
  176. APP.store.dispatch(openLogoutDialog(
  177. () => APP.UI.emitEvent(UIEvents.LOGOUT)
  178. ));
  179. } else {
  180. sendAnalytics(createProfilePanelButtonEvent('login.button'));
  181. APP.UI.emitEvent(UIEvents.AUTH_CLICKED);
  182. }
  183. }
  184. /**
  185. * Returns a React Element for interacting with server-side authentication.
  186. *
  187. * @private
  188. * @returns {ReactElement}
  189. */
  190. _renderAuth() {
  191. const {
  192. authLogin,
  193. t
  194. } = this.props;
  195. return (
  196. <div>
  197. <h2 className = 'mock-atlaskit-label'>
  198. { t('toolbar.authenticate') }
  199. </h2>
  200. { authLogin
  201. && <div className = 'auth-name'>
  202. { t('settings.loggedIn', { name: authLogin }) }
  203. </div> }
  204. <Button
  205. appearance = 'primary'
  206. id = 'login_button'
  207. onClick = { this._onAuthToggle }
  208. type = 'button'>
  209. { authLogin ? t('toolbar.logout') : t('toolbar.login') }
  210. </Button>
  211. </div>
  212. );
  213. }
  214. }
  215. export default translate(ProfileTab);