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

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