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.

DisplayNameForm.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // @flow
  2. import { FieldTextStateless } from '@atlaskit/field-text';
  3. import React, { Component } from 'react';
  4. import { connect } from 'react-redux';
  5. import { translate } from '../../../base/i18n';
  6. import { updateSettings } from '../../../base/settings';
  7. /**
  8. * The type of the React {@code Component} props of {@DisplayNameForm}.
  9. */
  10. type Props = {
  11. /**
  12. * Invoked to set the local participant display name.
  13. */
  14. dispatch: Dispatch<*>,
  15. /**
  16. * Invoked to obtain translated strings.
  17. */
  18. t: Function
  19. };
  20. /**
  21. * The type of the React {@code Component} state of {@DisplayNameForm}.
  22. */
  23. type State = {
  24. /**
  25. * User provided display name when the input text is provided in the view.
  26. */
  27. displayName: string
  28. };
  29. /**
  30. * React Component for requesting the local participant to set a display name.
  31. *
  32. * @extends Component
  33. */
  34. class DisplayNameForm extends Component<Props, State> {
  35. state = {
  36. displayName: ''
  37. };
  38. /**
  39. * Initializes a new {@code DisplayNameForm} instance.
  40. *
  41. * @param {Object} props - The read-only properties with which the new
  42. * instance is to be initialized.
  43. */
  44. constructor(props: Props) {
  45. super(props);
  46. // Bind event handlers so they are only bound once for every instance.
  47. this._onDisplayNameChange = this._onDisplayNameChange.bind(this);
  48. this._onSubmit = this._onSubmit.bind(this);
  49. }
  50. /**
  51. * Implements React's {@link Component#render()}.
  52. *
  53. * @inheritdoc
  54. * @returns {ReactElement}
  55. */
  56. render() {
  57. const { t } = this.props;
  58. return (
  59. <div id = 'nickname'>
  60. <span>{ this.props.t('chat.nickname.title') }</span>
  61. <form onSubmit = { this._onSubmit }>
  62. <FieldTextStateless
  63. autoFocus = { true }
  64. id = 'nickinput'
  65. onChange = { this._onDisplayNameChange }
  66. placeholder = { t('chat.nickname.popover') }
  67. type = 'text'
  68. value = { this.state.displayName } />
  69. </form>
  70. </div>
  71. );
  72. }
  73. _onDisplayNameChange: (Object) => void;
  74. /**
  75. * Dispatches an action update the entered display name.
  76. *
  77. * @param {event} event - Keyboard event.
  78. * @private
  79. * @returns {void}
  80. */
  81. _onDisplayNameChange(event: Object) {
  82. this.setState({ displayName: event.target.value });
  83. }
  84. _onSubmit: (Object) => void;
  85. /**
  86. * Dispatches an action to hit enter to change your display name.
  87. *
  88. * @param {event} event - Keyboard event
  89. * that will check if user has pushed the enter key.
  90. * @private
  91. * @returns {void}
  92. */
  93. _onSubmit(event: Object) {
  94. event.preventDefault();
  95. // Store display name in settings
  96. this.props.dispatch(updateSettings({
  97. displayName: this.state.displayName
  98. }));
  99. }
  100. }
  101. export default translate(connect()(DisplayNameForm));