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.

AddPasswordForm.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. import { setPassword } from '../../base/conference';
  4. import { translate } from '../../base/i18n';
  5. /**
  6. * A React Component for locking a JitsiConference with a password.
  7. */
  8. class AddPasswordForm extends Component {
  9. /**
  10. * AddPasswordForm component's property types.
  11. *
  12. * @static
  13. */
  14. static propTypes = {
  15. /**
  16. * The JitsiConference on which to lock and set a password.
  17. *
  18. * @type {JitsiConference}
  19. */
  20. conference: React.PropTypes.object,
  21. /**
  22. * Invoked to set a password on the conference.
  23. */
  24. dispatch: React.PropTypes.func,
  25. /**
  26. * Invoked to obtain translated strings.
  27. */
  28. t: React.PropTypes.func
  29. }
  30. /**
  31. * Initializes a new AddPasswordForm instance.
  32. *
  33. * @param {Object} props - The read-only properties with which the new
  34. * instance is to be initialized.
  35. */
  36. constructor(props) {
  37. super(props);
  38. this.state = {
  39. password: ''
  40. };
  41. this._onKeyDown = this._onKeyDown.bind(this);
  42. this._onPasswordChange = this._onPasswordChange.bind(this);
  43. this._onSubmit = this._onSubmit.bind(this);
  44. }
  45. /**
  46. * Implements React's {@link Component#render()}.
  47. *
  48. * @inheritdoc
  49. * @returns {ReactElement}
  50. */
  51. render() {
  52. return (
  53. <div
  54. className = 'form-control'
  55. onSubmit = { this._onSubmit } >
  56. <div className = 'form-control__container'>
  57. <input
  58. autoFocus = { true }
  59. className = 'input-control'
  60. id = 'newPasswordInput'
  61. onChange = { this._onPasswordChange }
  62. onKeyDown = { this._onKeyDown }
  63. placeholder
  64. = { this.props.t('dialog.createPassword') }
  65. type = 'text' />
  66. <button
  67. className = 'button-control button-control_light'
  68. disabled = { !this.state.password }
  69. id = 'addPasswordBtn'
  70. onClick = { this._onSubmit }
  71. type = 'button'>
  72. { this.props.t('dialog.add') }
  73. </button>
  74. </div>
  75. </div>
  76. );
  77. }
  78. /**
  79. * Mimics form behavior by listening for enter key press and submitting the
  80. * entered password.
  81. *
  82. * @param {Object} event - DOM Event for keydown.
  83. * @private
  84. * @returns {void}
  85. */
  86. _onKeyDown(event) {
  87. event.stopPropagation();
  88. if (event.keyCode === /* Enter */ 13) {
  89. this._onSubmit();
  90. }
  91. }
  92. /**
  93. * Updates the internal state of the entered password.
  94. *
  95. * @param {Object} event - DOM Event for value change.
  96. * @private
  97. * @returns {void}
  98. */
  99. _onPasswordChange(event) {
  100. this.setState({ password: event.target.value });
  101. }
  102. /**
  103. * Dispatches a request to lock the conference with a password.
  104. *
  105. * @private
  106. * @returns {void}
  107. */
  108. _onSubmit() {
  109. if (!this.state.password) {
  110. return;
  111. }
  112. const conference = this.props.conference;
  113. this.props.dispatch(setPassword(
  114. conference,
  115. conference.lock,
  116. this.state.password
  117. ));
  118. this.setState({ password: '' });
  119. }
  120. }
  121. export default translate(connect()(AddPasswordForm));