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

PasswordRequiredPrompt.web.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // @flow
  2. import AKFieldText from '@atlaskit/field-text';
  3. import PropTypes from 'prop-types';
  4. import React, { Component } from 'react';
  5. import { connect } from 'react-redux';
  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: PropTypes.object,
  26. dispatch: PropTypes.func,
  27. t: PropTypes.func
  28. };
  29. state = {
  30. password: ''
  31. };
  32. /**
  33. * Initializes a new PasswordRequiredPrompt instance.
  34. *
  35. * @param {Object} props - The read-only properties with which the new
  36. * instance is to be initialized.
  37. */
  38. constructor(props) {
  39. super(props);
  40. // Bind event handlers so they are only bound once per instance.
  41. this._onPasswordChanged = this._onPasswordChanged.bind(this);
  42. this._onSubmit = this._onSubmit.bind(this);
  43. }
  44. /**
  45. * Implements React's {@link Component#render()}.
  46. *
  47. * @inheritdoc
  48. * @returns {ReactElement}
  49. */
  50. render() {
  51. return (
  52. <Dialog
  53. isModal = { true }
  54. onSubmit = { this._onSubmit }
  55. titleKey = 'dialog.passwordRequired'
  56. width = 'small'>
  57. { this._renderBody() }
  58. </Dialog>
  59. );
  60. }
  61. /**
  62. * Display component in dialog body.
  63. *
  64. * @returns {ReactElement}
  65. * @protected
  66. */
  67. _renderBody() {
  68. return (
  69. <div>
  70. <AKFieldText
  71. autoFocus = { true }
  72. compact = { true }
  73. label = { this.props.t('dialog.passwordLabel') }
  74. name = 'lockKey'
  75. onChange = { this._onPasswordChanged }
  76. shouldFitContainer = { true }
  77. type = 'text'
  78. value = { this.state.password } />
  79. </div>
  80. );
  81. }
  82. _onPasswordChanged: ({ target: { value: * }}) => void;
  83. /**
  84. * Notifies this dialog that password has changed.
  85. *
  86. * @param {Object} event - The details of the notification/event.
  87. * @private
  88. * @returns {void}
  89. */
  90. _onPasswordChanged({ target: { value } }) {
  91. this.setState({
  92. password: value
  93. });
  94. }
  95. _onSubmit: () => boolean;
  96. /**
  97. * Dispatches action to submit value from this dialog.
  98. *
  99. * @private
  100. * @returns {boolean}
  101. */
  102. _onSubmit() {
  103. const { conference } = this.props;
  104. // We received that password is required, but user is trying anyway to
  105. // login without a password. Mark the room as not locked in case she
  106. // succeeds (maybe someone removed the password meanwhile). If it is
  107. // still locked, another password required will be received and the room
  108. // again will be marked as locked.
  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));