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

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