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.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { translate } from '../../../base/i18n/functions';
  4. import Dialog from '../../../base/ui/components/web/Dialog';
  5. import Input from '../../../base/ui/components/web/Input';
  6. import AbstractDisplayNamePrompt, { IProps } from '../AbstractDisplayNamePrompt';
  7. /**
  8. * The type of the React {@code Component} props of {@link DisplayNamePrompt}.
  9. */
  10. interface IState {
  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<IState> {
  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: IProps) {
  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. id = 'dialog-displayName'
  55. label = { this.props.t('dialog.enterDisplayName') }
  56. name = 'displayName'
  57. onChange = { this._onDisplayNameChange }
  58. type = 'text'
  59. value = { this.state.displayName } />
  60. </Dialog>
  61. );
  62. }
  63. /**
  64. * Updates the entered display name.
  65. *
  66. * @param {string} value - The new value of the input.
  67. * @private
  68. * @returns {void}
  69. */
  70. _onDisplayNameChange(value: string) {
  71. this.setState({
  72. displayName: value
  73. });
  74. }
  75. /**
  76. * Dispatches an action to update the local participant's display name. A
  77. * name must be entered for the action to dispatch.
  78. *
  79. * @private
  80. * @returns {boolean}
  81. */
  82. _onSubmit() {
  83. return this._onSetDisplayName(this.state.displayName);
  84. }
  85. }
  86. export default translate(connect()(DisplayNamePrompt));