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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. /**
  48. * Implements React's {@link Component#getDerivedStateFromProps()}.
  49. *
  50. * @inheritdoc
  51. */
  52. static getDerivedStateFromProps(props, state) {
  53. return {
  54. enteredPassword: props.editEnabled ? state.enteredPassword : ''
  55. };
  56. }
  57. state = {
  58. enteredPassword: ''
  59. };
  60. /**
  61. * Initializes a new {@code PasswordForm} instance.
  62. *
  63. * @param {Props} props - The React {@code Component} props to initialize
  64. * the new {@code PasswordForm} instance with.
  65. */
  66. constructor(props: Props) {
  67. super(props);
  68. // Bind event handlers so they are only bound once per instance.
  69. this._onEnteredPasswordChange
  70. = this._onEnteredPasswordChange.bind(this);
  71. this._onPasswordSubmit = this._onPasswordSubmit.bind(this);
  72. }
  73. /**
  74. * Implements React's {@link Component#render()}.
  75. *
  76. * @inheritdoc
  77. * @returns {ReactElement}
  78. */
  79. render() {
  80. const { t } = this.props;
  81. return (
  82. <div className = 'info-password'>
  83. <span className = 'info-label'>
  84. { t('info.password') }
  85. </span>
  86. <span className = 'spacer'>&nbsp;</span>
  87. <span className = 'info-password-field info-value'>
  88. { this._renderPasswordField() }
  89. </span>
  90. </div>
  91. );
  92. }
  93. /**
  94. * Returns a ReactElement for showing the current state of the password or
  95. * for editing the current password.
  96. *
  97. * @private
  98. * @returns {ReactElement}
  99. */
  100. _renderPasswordField() {
  101. if (this.props.editEnabled) {
  102. return (
  103. <form
  104. className = 'info-password-form'
  105. onSubmit = { this._onPasswordSubmit }>
  106. <input
  107. autoFocus = { true }
  108. className = 'info-password-input'
  109. onChange = { this._onEnteredPasswordChange }
  110. spellCheck = { 'false' }
  111. type = 'text'
  112. value = { this.state.enteredPassword } />
  113. </form>
  114. );
  115. } else if (this.props.locked === LOCKED_LOCALLY) {
  116. return (
  117. <div className = 'info-password-local'>
  118. { this.props.password }
  119. </div>
  120. );
  121. } else if (this.props.locked) {
  122. return (
  123. <div className = 'info-password-remote'>
  124. { this.props.t('passwordSetRemotely') }
  125. </div>
  126. );
  127. }
  128. return (
  129. <div className = 'info-password-none'>
  130. { this.props.t('info.noPassword') }
  131. </div>
  132. );
  133. }
  134. _onEnteredPasswordChange: (Object) => void;
  135. /**
  136. * Updates the internal state of entered password.
  137. *
  138. * @param {Object} event - DOM Event for value change.
  139. * @private
  140. * @returns {void}
  141. */
  142. _onEnteredPasswordChange(event) {
  143. this.setState({ enteredPassword: event.target.value });
  144. }
  145. _onPasswordSubmit: (Object) => void;
  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);