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

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