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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. <span className = 'info-label'>
  86. { t('info.password') }
  87. </span>
  88. <span className = 'spacer'>&nbsp;</span>
  89. <span className = 'info-password-field info-value'>
  90. { this._renderPasswordField() }
  91. </span>
  92. </div>
  93. );
  94. }
  95. /**
  96. * Returns a ReactElement for showing the current state of the password or
  97. * for editing the current password.
  98. *
  99. * @private
  100. * @returns {ReactElement}
  101. */
  102. _renderPasswordField() {
  103. if (this.props.editEnabled) {
  104. return (
  105. <form
  106. className = 'info-password-form'
  107. onSubmit = { this._onPasswordSubmit }>
  108. <input
  109. autoFocus = { true }
  110. className = 'info-password-input'
  111. onChange = { this._onEnteredPasswordChange }
  112. spellCheck = { 'false' }
  113. type = 'text'
  114. value = { this.state.enteredPassword } />
  115. </form>
  116. );
  117. } else if (this.props.locked === LOCKED_LOCALLY) {
  118. return (
  119. <div className = 'info-password-local'>
  120. { this.props.password }
  121. </div>
  122. );
  123. } else if (this.props.locked) {
  124. return (
  125. <div className = 'info-password-remote'>
  126. { this.props.t('passwordSetRemotely') }
  127. </div>
  128. );
  129. }
  130. return (
  131. <div className = 'info-password-none'>
  132. { this.props.t('info.noPassword') }
  133. </div>
  134. );
  135. }
  136. /**
  137. * Updates the internal state of entered password.
  138. *
  139. * @param {Object} event - DOM Event for value change.
  140. * @private
  141. * @returns {void}
  142. */
  143. _onEnteredPasswordChange(event) {
  144. this.setState({ enteredPassword: event.target.value });
  145. }
  146. /**
  147. * Invokes the passed in onSubmit callback to notify the parent that a
  148. * password submission has been attempted.
  149. *
  150. * @param {Object} event - DOM Event for form submission.
  151. * @private
  152. * @returns {void}
  153. */
  154. _onPasswordSubmit(event) {
  155. event.preventDefault();
  156. this.props.onSubmit(this.state.enteredPassword);
  157. }
  158. }
  159. export default translate(PasswordForm);