Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

DisplayNamePrompt.tsx 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import React, { Component } 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 { onSetDisplayName } from '../../functions';
  7. import { IProps } from '../../types';
  8. /**
  9. * The type of the React {@code Component} props of {@link DisplayNamePrompt}.
  10. */
  11. interface IState {
  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 Component<IProps, IState> {
  24. _onSetDisplayName: (displayName: string) => boolean;
  25. /**
  26. * Initializes a new {@code DisplayNamePrompt} instance.
  27. *
  28. * @param {Object} props - The read-only properties with which the new
  29. * instance is to be initialized.
  30. */
  31. constructor(props: IProps) {
  32. super(props);
  33. this.state = {
  34. displayName: ''
  35. };
  36. // Bind event handlers so they are only bound once for every instance.
  37. this._onDisplayNameChange = this._onDisplayNameChange.bind(this);
  38. this._onSubmit = this._onSubmit.bind(this);
  39. this._onSetDisplayName = onSetDisplayName(props.dispatch, props.onPostSubmit);
  40. }
  41. /**
  42. * Implements React's {@link Component#render()}.
  43. *
  44. * @inheritdoc
  45. * @returns {ReactElement}
  46. */
  47. render() {
  48. return (
  49. <Dialog
  50. cancel = {{ translationKey: 'dialog.Cancel' }}
  51. ok = {{ translationKey: 'dialog.Ok' }}
  52. onSubmit = { this._onSubmit }
  53. titleKey = 'dialog.displayNameRequired'>
  54. <Input
  55. autoFocus = { true }
  56. className = 'dialog-bottom-margin'
  57. id = 'dialog-displayName'
  58. label = { this.props.t('dialog.enterDisplayName') }
  59. name = 'displayName'
  60. onChange = { this._onDisplayNameChange }
  61. type = 'text'
  62. value = { this.state.displayName } />
  63. </Dialog>
  64. );
  65. }
  66. /**
  67. * Updates the entered display name.
  68. *
  69. * @param {string} value - The new value of the input.
  70. * @private
  71. * @returns {void}
  72. */
  73. _onDisplayNameChange(value: string) {
  74. this.setState({
  75. displayName: value
  76. });
  77. }
  78. /**
  79. * Dispatches an action to update the local participant's display name. A
  80. * name must be entered for the action to dispatch.
  81. *
  82. * @private
  83. * @returns {boolean}
  84. */
  85. _onSubmit() {
  86. return this._onSetDisplayName(this.state.displayName);
  87. }
  88. }
  89. export default translate(connect()(DisplayNamePrompt));