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.

PasswordContainer.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. import AddPasswordForm from './AddPasswordForm';
  6. import LockStatePanel from './LockStatePanel';
  7. import RemovePasswordForm from './RemovePasswordForm';
  8. /**
  9. * React {@code Component} for displaying the current room lock state as well as
  10. * exposing features to modify the room lock.
  11. */
  12. class PasswordContainer extends Component {
  13. /**
  14. * {@code PasswordContainer}'s property types.
  15. *
  16. * @static
  17. */
  18. static propTypes = {
  19. /**
  20. * The JitsiConference for which to display a lock state and change the
  21. * password.
  22. *
  23. * @type {JitsiConference}
  24. */
  25. conference: PropTypes.object,
  26. /**
  27. * The value for how the conference is locked (or undefined if not
  28. * locked) as defined by room-lock constants.
  29. */
  30. locked: PropTypes.string,
  31. /**
  32. * The current known password for the JitsiConference.
  33. */
  34. password: PropTypes.string,
  35. /**
  36. * Whether or not the password editing components should be displayed.
  37. */
  38. showPasswordEdit: PropTypes.bool,
  39. /**
  40. * Invoked to obtain translated strings.
  41. */
  42. t: PropTypes.func
  43. };
  44. /**
  45. * Initializes a new {@code PasswordContainer} instance.
  46. *
  47. * @param {Object} props - The read-only properties with which the new
  48. * instance is to be initialized.
  49. */
  50. constructor(props) {
  51. super(props);
  52. this.state = {
  53. /**
  54. * Whether or not the form to edit the password should display. If
  55. * true, the form should display.
  56. *
  57. * @type {boolean}
  58. */
  59. isEditingPassword: false
  60. };
  61. // Bind event handlers so they are only bound once for every instance.
  62. this._onTogglePasswordEdit = this._onTogglePasswordEdit.bind(this);
  63. }
  64. /**
  65. * Implements React's {@link Component#render()}.
  66. *
  67. * @inheritdoc
  68. * @returns {ReactElement}
  69. */
  70. render() {
  71. return (
  72. <div className = 'password-overview'>
  73. <div className = 'password-overview-status'>
  74. <LockStatePanel locked = { Boolean(this.props.locked) } />
  75. { this._renderShowPasswordLink() }
  76. </div>
  77. { this._renderPasswordEdit() }
  78. </div>
  79. );
  80. }
  81. /**
  82. * Toggles the display of the ReactElements used to edit the password.
  83. *
  84. * @private
  85. * @returns {void}
  86. */
  87. _onTogglePasswordEdit() {
  88. this.setState({
  89. isEditingPassword: !this.state.isEditingPassword
  90. });
  91. }
  92. /**
  93. * Creates a ReactElement used for setting or removing a password.
  94. *
  95. * @private
  96. * @returns {ReactElement|null}
  97. */
  98. _renderPasswordEdit() {
  99. if (!this.state.isEditingPassword) {
  100. return null;
  101. }
  102. return (
  103. this.props.locked
  104. ? <RemovePasswordForm
  105. conference = { this.props.conference }
  106. lockedLocally = { this.props.locked === LOCKED_LOCALLY }
  107. password = { this.props.password } />
  108. : <AddPasswordForm conference = { this.props.conference } />
  109. );
  110. }
  111. /**
  112. * Creates a ReactElement that toggles displaying password edit components.
  113. *
  114. * @private
  115. * @returns {ReactElement|null}
  116. */
  117. _renderShowPasswordLink() {
  118. if (!this.props.showPasswordEdit) {
  119. return null;
  120. }
  121. let toggleStatusKey;
  122. if (this.state.isEditingPassword) {
  123. toggleStatusKey = 'invite.hidePassword';
  124. } else if (this.props.locked) {
  125. toggleStatusKey = 'invite.showPassword';
  126. } else {
  127. toggleStatusKey = 'invite.addPassword';
  128. }
  129. return (
  130. <a
  131. className = 'password-overview-toggle-edit'
  132. onClick = { this._onTogglePasswordEdit }>
  133. { this.props.t(toggleStatusKey) }
  134. </a>
  135. );
  136. }
  137. }
  138. export default translate(PasswordContainer);