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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 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. * PasswordContainer component'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 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. isEditingPassword: false
  53. };
  54. this._onTogglePasswordEdit = this._onTogglePasswordEdit.bind(this);
  55. }
  56. /**
  57. * Implements React's {@link Component#render()}.
  58. *
  59. * @inheritdoc
  60. * @returns {ReactElement}
  61. */
  62. render() {
  63. return (
  64. <div className = 'password-overview'>
  65. <div className = 'password-overview-status'>
  66. <LockStatePanel locked = { Boolean(this.props.locked) } />
  67. { this._renderShowPasswordLink() }
  68. </div>
  69. { this._renderPasswordEdit() }
  70. </div>
  71. );
  72. }
  73. /**
  74. * Toggles the display of the ReactElements used to edit the password.
  75. *
  76. * @private
  77. * @returns {void}
  78. */
  79. _onTogglePasswordEdit() {
  80. this.setState({
  81. isEditingPassword: !this.state.isEditingPassword
  82. });
  83. }
  84. /**
  85. * Creates a ReactElement used for setting or removing a password.
  86. *
  87. * @private
  88. * @returns {ReactElement|null}
  89. */
  90. _renderPasswordEdit() {
  91. if (!this.state.isEditingPassword) {
  92. return null;
  93. }
  94. return this.props.locked
  95. ? <RemovePasswordForm
  96. conference = { this.props.conference }
  97. lockedLocally = { this.props.locked === LOCKED_LOCALLY }
  98. password = { this.props.password } />
  99. : <AddPasswordForm conference = { this.props.conference } />;
  100. }
  101. /**
  102. * Creates a ReactElement that toggles displaying password edit components.
  103. *
  104. * @private
  105. * @returns {ReactElement|null}
  106. */
  107. _renderShowPasswordLink() {
  108. if (!this.props.showPasswordEdit) {
  109. return null;
  110. }
  111. let toggleStatusKey;
  112. if (this.state.isEditingPassword) {
  113. toggleStatusKey = 'invite.hidePassword';
  114. } else if (this.props.locked) {
  115. toggleStatusKey = 'invite.showPassword';
  116. } else {
  117. toggleStatusKey = 'invite.addPassword';
  118. }
  119. return (
  120. <a
  121. className = 'password-overview-toggle-edit'
  122. onClick = { this._onTogglePasswordEdit }>
  123. { this.props.t(toggleStatusKey) }
  124. </a>
  125. );
  126. }
  127. }
  128. export default translate(PasswordContainer);