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.

DisplayNamePrompt.tsx 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import React from 'react';
  2. // @ts-ignore
  3. import { Dialog } from '../../../base/dialog';
  4. import { translate } from '../../../base/i18n/functions';
  5. import { connect } from '../../../base/redux/functions';
  6. import Input from '../../../base/ui/components/web/Input';
  7. import AbstractDisplayNamePrompt, { Props } from '../AbstractDisplayNamePrompt';
  8. /**
  9. * The type of the React {@code Component} props of {@link DisplayNamePrompt}.
  10. */
  11. type State = {
  12. /**
  13. * The name to show in the display name text field.
  14. */
  15. displayName: string
  16. };
  17. /**
  18. * Implements a React {@code Component} for displaying a dialog with an field
  19. * for setting the local participant's display name.
  20. *
  21. * @augments Component
  22. */
  23. class DisplayNamePrompt extends AbstractDisplayNamePrompt<State> {
  24. /**
  25. * Initializes a new {@code DisplayNamePrompt} instance.
  26. *
  27. * @param {Object} props - The read-only properties with which the new
  28. * instance is to be initialized.
  29. */
  30. constructor(props: Props) {
  31. super(props);
  32. this.state = {
  33. displayName: ''
  34. };
  35. // Bind event handlers so they are only bound once for every instance.
  36. this._onDisplayNameChange = this._onDisplayNameChange.bind(this);
  37. this._onSubmit = this._onSubmit.bind(this);
  38. }
  39. /**
  40. * Implements React's {@link Component#render()}.
  41. *
  42. * @inheritdoc
  43. * @returns {ReactElement}
  44. */
  45. render() {
  46. return (
  47. <Dialog
  48. isModal = { false }
  49. onSubmit = { this._onSubmit }
  50. titleKey = 'dialog.displayNameRequired'
  51. width = 'small'>
  52. <Input
  53. autoFocus = { true }
  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));