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

PasswordRequiredPrompt.web.js 3.4KB

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