Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

DisplayNamePrompt.tsx 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import React from 'react';
  2. import { translate } from '../../../base/i18n/functions';
  3. import { connect } from '../../../base/redux/functions';
  4. import Dialog from '../../../base/ui/components/web/Dialog';
  5. import Input from '../../../base/ui/components/web/Input';
  6. import AbstractDisplayNamePrompt, { Props } from '../AbstractDisplayNamePrompt';
  7. /**
  8. * The type of the React {@code Component} props of {@link DisplayNamePrompt}.
  9. */
  10. type State = {
  11. /**
  12. * The name to show in the display name text field.
  13. */
  14. displayName: string;
  15. };
  16. /**
  17. * Implements a React {@code Component} for displaying a dialog with an field
  18. * for setting the local participant's display name.
  19. *
  20. * @augments Component
  21. */
  22. class DisplayNamePrompt extends AbstractDisplayNamePrompt<State> {
  23. /**
  24. * Initializes a new {@code DisplayNamePrompt} instance.
  25. *
  26. * @param {Object} props - The read-only properties with which the new
  27. * instance is to be initialized.
  28. */
  29. constructor(props: Props) {
  30. super(props);
  31. this.state = {
  32. displayName: ''
  33. };
  34. // Bind event handlers so they are only bound once for every instance.
  35. this._onDisplayNameChange = this._onDisplayNameChange.bind(this);
  36. this._onSubmit = this._onSubmit.bind(this);
  37. }
  38. /**
  39. * Implements React's {@link Component#render()}.
  40. *
  41. * @inheritdoc
  42. * @returns {ReactElement}
  43. */
  44. render() {
  45. return (
  46. <Dialog
  47. cancel = {{ translationKey: 'dialog.Cancel' }}
  48. ok = {{ translationKey: 'dialog.Ok' }}
  49. onSubmit = { this._onSubmit }
  50. titleKey = 'dialog.displayNameRequired'>
  51. <Input
  52. autoFocus = { true }
  53. className = 'dialog-bottom-margin'
  54. label = { this.props.t('dialog.enterDisplayName') }
  55. name = 'displayName'
  56. onChange = { this._onDisplayNameChange }
  57. type = 'text'
  58. value = { this.state.displayName } />
  59. </Dialog>);
  60. }
  61. /**
  62. * Updates the entered display name.
  63. *
  64. * @param {string} value - The new value of the input.
  65. * @private
  66. * @returns {void}
  67. */
  68. _onDisplayNameChange(value: string) {
  69. this.setState({
  70. displayName: value
  71. });
  72. }
  73. /**
  74. * Dispatches an action to update the local participant's display name. A
  75. * name must be entered for the action to dispatch.
  76. *
  77. * @private
  78. * @returns {boolean}
  79. */
  80. _onSubmit() {
  81. return this._onSetDisplayName(this.state.displayName);
  82. }
  83. }
  84. export default translate(connect()(DisplayNamePrompt));