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.5KB

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