Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

DisplayNamePrompt.web.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import AKFieldText from '@atlaskit/field-text';
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import { Dialog } from '../../base/dialog';
  5. import { translate } from '../../base/i18n';
  6. import {
  7. getLocalParticipant,
  8. participantDisplayNameChanged
  9. } from '../../base/participants';
  10. /**
  11. * Implements a React {@code Component} for displaying a dialog with an field
  12. * for setting the local participant's display name.
  13. *
  14. * @extends Component
  15. */
  16. class DisplayNamePrompt extends Component {
  17. /**
  18. * {@code DisplayNamePrompt} component's property types.
  19. *
  20. * @static
  21. */
  22. static propTypes = {
  23. /**
  24. * The current ID for the local participant. Used for setting the
  25. * display name on the associated participant.
  26. */
  27. _localParticipantID: React.PropTypes.string,
  28. /**
  29. * Invoked to update the local participant's display name.
  30. */
  31. dispatch: React.PropTypes.func,
  32. /**
  33. * Invoked to obtain translated strings.
  34. */
  35. t: React.PropTypes.func
  36. };
  37. /**
  38. * Initializes a new {@code DisplayNamePrompt} instance.
  39. *
  40. * @param {Object} props - The read-only properties with which the new
  41. * instance is to be initialized.
  42. */
  43. constructor(props) {
  44. super(props);
  45. this.state = {
  46. /**
  47. * The name to show in the display name text field.
  48. *
  49. * @type {string}
  50. */
  51. displayName: ''
  52. };
  53. // Bind event handlers so they are only bound once for every instance.
  54. this._onDisplayNameChange = this._onDisplayNameChange.bind(this);
  55. this._onSubmit = this._onSubmit.bind(this);
  56. }
  57. /**
  58. * Implements React's {@link Component#render()}.
  59. *
  60. * @inheritdoc
  61. * @returns {ReactElement}
  62. */
  63. render() {
  64. return (
  65. <Dialog
  66. isModal = { true }
  67. onSubmit = { this._onSubmit }
  68. titleKey = 'dialog.displayNameRequired'
  69. width = 'small'>
  70. <AKFieldText
  71. autoFocus = { true }
  72. compact = { true }
  73. label = { this.props.t('dialog.enterDisplayName') }
  74. name = 'displayName'
  75. onChange = { this._onDisplayNameChange }
  76. shouldFitContainer = { true }
  77. type = 'text'
  78. value = { this.state.displayName } />
  79. </Dialog>);
  80. }
  81. /**
  82. * Updates the entered display name.
  83. *
  84. * @param {Object} event - The DOM event triggered from the entered display
  85. * name value having changed.
  86. * @private
  87. * @returns {void}
  88. */
  89. _onDisplayNameChange(event) {
  90. this.setState({
  91. displayName: event.target.value
  92. });
  93. }
  94. /**
  95. * Dispatches an action to update the local participant's display name. A
  96. * name must be entered for the action to dispatch.
  97. *
  98. * @private
  99. * @returns {void}
  100. */
  101. _onSubmit() {
  102. const { displayName } = this.state;
  103. if (!displayName.trim()) {
  104. return false;
  105. }
  106. const { dispatch, _localParticipantID } = this.props;
  107. dispatch(
  108. participantDisplayNameChanged(_localParticipantID, displayName));
  109. return true;
  110. }
  111. }
  112. /**
  113. * Maps (parts of) the Redux state to the associated {@code DisplayNamePrompt}'s
  114. * props.
  115. *
  116. * @param {Object} state - The Redux state.
  117. * @private
  118. * @returns {{
  119. * _localParticipantID: string
  120. * }}
  121. */
  122. function _mapStateToProps(state) {
  123. const { id } = getLocalParticipant(state);
  124. return {
  125. /**
  126. * The current ID for the local participant.
  127. *
  128. * @type {string}
  129. */
  130. _localParticipantID: id
  131. };
  132. }
  133. export default translate(connect(_mapStateToProps)(DisplayNamePrompt));