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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. * Invoked to obtain translated strings.
  29. */
  30. t: Function
  31. };
  32. /**
  33. * The type of the React {@code Component} state of {@link PasswordForm}.
  34. */
  35. type State = {
  36. /**
  37. * The value of the password being entered by the local participant.
  38. */
  39. enteredPassword: string
  40. };
  41. /**
  42. * React {@code Component} for displaying and editing the conference password.
  43. *
  44. * @extends Component
  45. */
  46. class PasswordForm extends Component<Props, State> {
  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: 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: Props) {
  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. _onEnteredPasswordChange: (Object) => void;
  137. /**
  138. * Updates the internal state of entered password.
  139. *
  140. * @param {Object} event - DOM Event for value change.
  141. * @private
  142. * @returns {void}
  143. */
  144. _onEnteredPasswordChange(event) {
  145. this.setState({ enteredPassword: event.target.value });
  146. }
  147. _onPasswordSubmit: (Object) => void;
  148. /**
  149. * Invokes the passed in onSubmit callback to notify the parent that a
  150. * password submission has been attempted.
  151. *
  152. * @param {Object} event - DOM Event for form submission.
  153. * @private
  154. * @returns {void}
  155. */
  156. _onPasswordSubmit(event) {
  157. event.preventDefault();
  158. this.props.onSubmit(this.state.enteredPassword);
  159. }
  160. }
  161. export default translate(PasswordForm);