Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

PasswordForm.js 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { translate } from '../../../../base/i18n';
  4. import { LOCKED_LOCALLY } from '../../../../room-lock';
  5. /**
  6. * The type of the React {@code Component} props of {@link PasswordForm}.
  7. */
  8. type Props = {
  9. /**
  10. * Whether or not to show the password editing field.
  11. */
  12. editEnabled: boolean,
  13. /**
  14. * The value for how the conference is locked (or undefined if not locked)
  15. * as defined by room-lock constants.
  16. */
  17. locked: string,
  18. /**
  19. * Callback to invoke when the local participant is submitting a password
  20. * set request.
  21. */
  22. onSubmit: Function,
  23. /**
  24. * The current known password for the JitsiConference.
  25. */
  26. password: string,
  27. /**
  28. * The number of digits to be used in the password.
  29. */
  30. passwordNumberOfDigits: boolean,
  31. /**
  32. * Invoked to obtain translated strings.
  33. */
  34. t: Function
  35. };
  36. /**
  37. * The type of the React {@code Component} state of {@link PasswordForm}.
  38. */
  39. type State = {
  40. /**
  41. * The value of the password being entered by the local participant.
  42. */
  43. enteredPassword: string
  44. };
  45. /**
  46. * React {@code Component} for displaying and editing the conference password.
  47. *
  48. * @augments Component
  49. */
  50. class PasswordForm extends Component<Props, State> {
  51. /**
  52. * Implements React's {@link Component#getDerivedStateFromProps()}.
  53. *
  54. * @inheritdoc
  55. */
  56. static getDerivedStateFromProps(props, state) {
  57. return {
  58. enteredPassword: props.editEnabled ? state.enteredPassword : ''
  59. };
  60. }
  61. state = {
  62. enteredPassword: ''
  63. };
  64. /**
  65. * Initializes a new {@code PasswordForm} instance.
  66. *
  67. * @param {Props} props - The React {@code Component} props to initialize
  68. * the new {@code PasswordForm} instance with.
  69. */
  70. constructor(props: Props) {
  71. super(props);
  72. // Bind event handlers so they are only bound once per instance.
  73. this._onEnteredPasswordChange = this._onEnteredPasswordChange.bind(this);
  74. this._onKeyPress = this._onKeyPress.bind(this);
  75. }
  76. /**
  77. * Implements React's {@link Component#render()}.
  78. *
  79. * @inheritdoc
  80. * @returns {ReactElement}
  81. */
  82. render() {
  83. const { t } = this.props;
  84. return (
  85. <div className = 'info-password'>
  86. <span className = 'info-label'>
  87. { t('info.password') }
  88. </span>
  89. <span className = 'spacer'>&nbsp;</span>
  90. <span className = 'info-password-field info-value'>
  91. { this._renderPasswordField() }
  92. </span>
  93. </div>
  94. );
  95. }
  96. /**
  97. * Returns a ReactElement for showing the current state of the password or
  98. * for editing the current password.
  99. *
  100. * @private
  101. * @returns {ReactElement}
  102. */
  103. _renderPasswordField() {
  104. if (this.props.editEnabled) {
  105. let placeHolderText;
  106. if (this.props.passwordNumberOfDigits) {
  107. placeHolderText = this.props.t('passwordDigitsOnly', {
  108. number: this.props.passwordNumberOfDigits });
  109. }
  110. return (
  111. <div
  112. className = 'info-password-form'>
  113. <input
  114. aria-label = { this.props.t('info.addPassword') }
  115. autoFocus = { true }
  116. className = 'info-password-input'
  117. maxLength = { this.props.passwordNumberOfDigits }
  118. onChange = { this._onEnteredPasswordChange }
  119. onKeyPress = { this._onKeyPress }
  120. placeholder = { placeHolderText }
  121. spellCheck = { 'false' }
  122. type = 'text'
  123. value = { this.state.enteredPassword } />
  124. </div>
  125. );
  126. } else if (this.props.locked === LOCKED_LOCALLY) {
  127. return (
  128. <div className = 'info-password-local'>
  129. { this.props.password }
  130. </div>
  131. );
  132. } else if (this.props.locked) {
  133. return (
  134. <div className = 'info-password-remote'>
  135. { this.props.t('passwordSetRemotely') }
  136. </div>
  137. );
  138. }
  139. return (
  140. <div className = 'info-password-none'>
  141. { this.props.t('info.noPassword') }
  142. </div>
  143. );
  144. }
  145. _onEnteredPasswordChange: (Object) => void;
  146. /**
  147. * Updates the internal state of entered password.
  148. *
  149. * @param {Object} event - DOM Event for value change.
  150. * @private
  151. * @returns {void}
  152. */
  153. _onEnteredPasswordChange(event) {
  154. this.setState({ enteredPassword: event.target.value });
  155. }
  156. _onKeyPress: (Object) => void;
  157. /**
  158. * Stops the the EnterKey for propagation in order to prevent the dialog
  159. * to close.
  160. *
  161. * @param {Object} event - The key event.
  162. * @private
  163. * @returns {void}
  164. */
  165. _onKeyPress(event) {
  166. if (event.key === 'Enter') {
  167. event.preventDefault();
  168. event.stopPropagation();
  169. this.props.onSubmit(this.state.enteredPassword);
  170. }
  171. }
  172. }
  173. export default translate(PasswordForm);