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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. autoFocus = { true }
  70. compact = { true }
  71. label = { this.props.t('dialog.passwordLabel') }
  72. name = 'lockKey'
  73. onChange = { this._onPasswordChanged }
  74. shouldFitContainer = { true }
  75. type = 'text'
  76. value = { this.state.password } />
  77. </div>
  78. );
  79. }
  80. /**
  81. * Notifies this dialog that password has changed.
  82. *
  83. * @param {Object} event - The details of the notification/event.
  84. * @private
  85. * @returns {void}
  86. */
  87. _onPasswordChanged(event) {
  88. this.setState({
  89. password: event.target.value
  90. });
  91. }
  92. /**
  93. * Dispatches action to submit value from thus dialog.
  94. *
  95. * @private
  96. * @returns {void}
  97. */
  98. _onSubmit() {
  99. const { conference } = this.props;
  100. // We received that password is required, but user is trying anyway to
  101. // login without a password. Mark the room as not locked in case she
  102. // succeeds (maybe someone removed the password meanwhile). If it is
  103. // still locked, another password required will be received and the room
  104. // again will be marked as locked.
  105. if (!this.state.password || this.state.password === '') {
  106. // XXX Temporary solution while some components are not listening
  107. // for lock state updates in redux.
  108. APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK, false);
  109. }
  110. this.props.dispatch(
  111. setPassword(conference, conference.join, this.state.password));
  112. // We have used the password so let's clean it.
  113. this.setState({
  114. password: undefined
  115. });
  116. return true;
  117. }
  118. }
  119. export default translate(connect()(PasswordRequiredPrompt));