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.

PasswordRequiredPrompt.web.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* global APP */
  2. import AKFieldText from '@atlaskit/field-text';
  3. import React, { Component } from 'react';
  4. import { connect } from 'react-redux';
  5. import UIEvents from '../../../../service/UI/UIEvents';
  6. import { setPassword } from '../../base/conference';
  7. import { Dialog } from '../../base/dialog';
  8. import { translate } from '../../base/i18n';
  9. /**
  10. * Implements a React Component which prompts the user when a password is
  11. * required to join a conference.
  12. */
  13. class PasswordRequiredPrompt extends Component {
  14. /**
  15. * PasswordRequiredPrompt component's property types.
  16. *
  17. * @static
  18. */
  19. static propTypes = {
  20. /**
  21. * The JitsiConference which requires a password.
  22. *
  23. * @type {JitsiConference}
  24. */
  25. conference: React.PropTypes.object,
  26. dispatch: React.PropTypes.func,
  27. t: React.PropTypes.func
  28. };
  29. /**
  30. * Initializes a new PasswordRequiredPrompt instance.
  31. *
  32. * @param {Object} props - The read-only properties with which the new
  33. * instance is to be initialized.
  34. */
  35. constructor(props) {
  36. super(props);
  37. this.state = {
  38. password: ''
  39. };
  40. this._onPasswordChanged = this._onPasswordChanged.bind(this);
  41. this._onSubmit = this._onSubmit.bind(this);
  42. }
  43. /**
  44. * Implements React's {@link Component#render()}.
  45. *
  46. * @inheritdoc
  47. * @returns {ReactElement}
  48. */
  49. render() {
  50. return (
  51. <Dialog
  52. isModal = { true }
  53. onSubmit = { this._onSubmit }
  54. titleKey = 'dialog.passwordRequired'
  55. width = 'small'>
  56. { this._renderBody() }
  57. </Dialog>);
  58. }
  59. /**
  60. * Display component in dialog body.
  61. *
  62. * @returns {ReactElement}
  63. * @protected
  64. */
  65. _renderBody() {
  66. return (
  67. <div>
  68. <AKFieldText
  69. compact = { true }
  70. label = { this.props.t('dialog.passwordLabel') }
  71. name = 'lockKey'
  72. onChange = { this._onPasswordChanged }
  73. shouldFitContainer = { true }
  74. type = 'text'
  75. value = { this.state.password } />
  76. </div>
  77. );
  78. }
  79. /**
  80. * Notifies this dialog that password has changed.
  81. *
  82. * @param {Object} event - The details of the notification/event.
  83. * @private
  84. * @returns {void}
  85. */
  86. _onPasswordChanged(event) {
  87. this.setState({
  88. password: event.target.value
  89. });
  90. }
  91. /**
  92. * Dispatches action to submit value from thus dialog.
  93. *
  94. * @private
  95. * @returns {void}
  96. */
  97. _onSubmit() {
  98. const { conference } = this.props;
  99. // We received that password is required, but user is trying anyway to
  100. // login without a password. Mark the room as not locked in case she
  101. // succeeds (maybe someone removed the password meanwhile). If it is
  102. // still locked, another password required will be received and the room
  103. // again will be marked as locked.
  104. if (!this.state.password || this.state.password === '') {
  105. // XXX Temporary solution while some components are not listening
  106. // for lock state updates in redux.
  107. APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK, false);
  108. }
  109. this.props.dispatch(
  110. setPassword(conference, conference.join, this.state.password));
  111. // We have used the password so let's clean it.
  112. this.setState({
  113. password: undefined
  114. });
  115. return true;
  116. }
  117. }
  118. export default translate(connect()(PasswordRequiredPrompt));