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.

PasswordForm.web.js 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import PropTypes from 'prop-types';
  2. import React, { Component } from 'react';
  3. import { translate } from '../../../base/i18n';
  4. import { LOCKED_LOCALLY } from '../../../room-lock';
  5. /**
  6. * React {@code Component} for displaying and editing the conference password.
  7. *
  8. * @extends Component
  9. */
  10. class PasswordForm extends Component {
  11. /**
  12. * {@code PasswordForm} component's property types.
  13. *
  14. * @static
  15. */
  16. static propTypes = {
  17. /**
  18. * Whether or not to show the password editing field.
  19. */
  20. editEnabled: PropTypes.bool,
  21. /**
  22. * The value for how the conference is locked (or undefined if not
  23. * locked) as defined by room-lock constants.
  24. */
  25. locked: PropTypes.string,
  26. /**
  27. * Callback to invoke when the local participant is submitting a
  28. * password set request.
  29. */
  30. onSubmit: PropTypes.func,
  31. /**
  32. * The current known password for the JitsiConference.
  33. */
  34. password: PropTypes.string,
  35. /**
  36. * Invoked to obtain translated strings.
  37. */
  38. t: PropTypes.func
  39. };
  40. /**
  41. * {@code PasswordForm} component's local state.
  42. *
  43. * @type {Object}
  44. * @property {string} enteredPassword - The value of the password being
  45. * entered by the local participant.
  46. */
  47. state = {
  48. enteredPassword: ''
  49. };
  50. /**
  51. * Initializes a new {@code PasswordForm} instance.
  52. *
  53. * @param {Props} props - The React {@code Component} props to initialize
  54. * the new {@code PasswordForm} instance with.
  55. */
  56. constructor(props) {
  57. super(props);
  58. // Bind event handlers so they are only bound once per instance.
  59. this._onEnteredPasswordChange
  60. = this._onEnteredPasswordChange.bind(this);
  61. this._onPasswordSubmit = this._onPasswordSubmit.bind(this);
  62. }
  63. /**
  64. * Implements React's {@link Component#componentWillReceiveProps()}. Invoked
  65. * before this mounted component receives new props.
  66. *
  67. * @inheritdoc
  68. * @param {Props} nextProps - New props component will receive.
  69. */
  70. componentWillReceiveProps(nextProps) {
  71. if (this.props.editEnabled && !nextProps.editEnabled) {
  72. this.setState({ enteredPassword: '' });
  73. }
  74. }
  75. /**
  76. * Implements React's {@link Component#render()}.
  77. *
  78. * @inheritdoc
  79. * @returns {ReactElement}
  80. */
  81. render() {
  82. const { t } = this.props;
  83. return (
  84. <div className = 'info-password'>
  85. <div>{ t('info.password') }</div>
  86. <div className = 'info-password-field'>
  87. { this._renderPasswordField() }
  88. </div>
  89. </div>
  90. );
  91. }
  92. /**
  93. * Returns a ReactElement for showing the current state of the password or
  94. * for editing the current password.
  95. *
  96. * @private
  97. * @returns {ReactElement}
  98. */
  99. _renderPasswordField() {
  100. if (this.props.editEnabled) {
  101. return (
  102. <form
  103. className = 'info-password-form'
  104. onSubmit = { this._onPasswordSubmit }>
  105. <input
  106. autoFocus = { true }
  107. className = 'info-password-input'
  108. onChange = { this._onEnteredPasswordChange }
  109. spellCheck = { 'false' }
  110. type = 'text'
  111. value = { this.state.enteredPassword } />
  112. </form>
  113. );
  114. } else if (this.props.locked === LOCKED_LOCALLY) {
  115. return (
  116. <div className = 'info-password-local'>
  117. { this.props.password }
  118. </div>
  119. );
  120. } else if (this.props.locked) {
  121. return (
  122. <div className = 'info-password-remote'>
  123. { this.props.t('passwordSetRemotely') }
  124. </div>
  125. );
  126. }
  127. return (
  128. <div className = 'info-password-none'>
  129. { this.props.t('info.noPassword') }
  130. </div>
  131. );
  132. }
  133. /**
  134. * Updates the internal state of entered password.
  135. *
  136. * @param {Object} event - DOM Event for value change.
  137. * @private
  138. * @returns {void}
  139. */
  140. _onEnteredPasswordChange(event) {
  141. this.setState({ enteredPassword: event.target.value });
  142. }
  143. /**
  144. * Invokes the passed in onSubmit callback to notify the parent that a
  145. * password submission has been attempted.
  146. *
  147. * @param {Object} event - DOM Event for form submission.
  148. * @private
  149. * @returns {void}
  150. */
  151. _onPasswordSubmit(event) {
  152. event.preventDefault();
  153. this.props.onSubmit(this.state.enteredPassword);
  154. }
  155. }
  156. export default translate(PasswordForm);