您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

PasswordRequiredPrompt.web.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import AKFieldText from '@atlaskit/field-text';
  2. import PropTypes from 'prop-types';
  3. import React, { Component } from 'react';
  4. import { connect } from 'react-redux';
  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: PropTypes.object,
  25. dispatch: PropTypes.func,
  26. t: 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 = {
  37. password: ''
  38. };
  39. this._onPasswordChanged = this._onPasswordChanged.bind(this);
  40. this._onSubmit = this._onSubmit.bind(this);
  41. }
  42. /**
  43. * Implements React's {@link Component#render()}.
  44. *
  45. * @inheritdoc
  46. * @returns {ReactElement}
  47. */
  48. render() {
  49. return (
  50. <Dialog
  51. isModal = { true }
  52. onSubmit = { this._onSubmit }
  53. titleKey = 'dialog.passwordRequired'
  54. width = 'small'>
  55. { this._renderBody() }
  56. </Dialog>);
  57. }
  58. /**
  59. * Display component in dialog body.
  60. *
  61. * @returns {ReactElement}
  62. * @protected
  63. */
  64. _renderBody() {
  65. return (
  66. <div>
  67. <AKFieldText
  68. autoFocus = { true }
  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. this.props.dispatch(
  105. setPassword(conference, conference.join, this.state.password));
  106. // We have used the password so let's clean it.
  107. this.setState({
  108. password: undefined
  109. });
  110. return true;
  111. }
  112. }
  113. export default translate(connect()(PasswordRequiredPrompt));