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

PasswordRequiredPrompt.web.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // @flow
  2. import { FieldTextStateless as TextField } from '@atlaskit/field-text';
  3. import React, { Component } from 'react';
  4. import type { Dispatch } from 'redux';
  5. import { setPassword } from '../../base/conference';
  6. import { Dialog } from '../../base/dialog';
  7. import { translate } from '../../base/i18n';
  8. import { connect } from '../../base/redux';
  9. import { _cancelPasswordRequiredPrompt } from '../actions';
  10. /**
  11. * The type of the React {@code Component} props of
  12. * {@link PasswordRequiredPrompt}.
  13. */
  14. type Props = {
  15. /**
  16. * The JitsiConference which requires a password.
  17. */
  18. conference: Object,
  19. /**
  20. * The redux store's {@code dispatch} function.
  21. */
  22. dispatch: Dispatch<any>,
  23. /**
  24. * The translate function.
  25. */
  26. t: Function
  27. };
  28. /**
  29. * The type of the React {@code Component} state of
  30. * {@link PasswordRequiredPrompt}.
  31. */
  32. type State = {
  33. /**
  34. * The password entered by the local participant.
  35. */
  36. password: string
  37. }
  38. /**
  39. * Implements a React Component which prompts the user when a password is
  40. * required to join a conference.
  41. */
  42. class PasswordRequiredPrompt extends Component<Props, State> {
  43. state = {
  44. password: ''
  45. };
  46. /**
  47. * Initializes a new PasswordRequiredPrompt instance.
  48. *
  49. * @param {Object} props - The read-only properties with which the new
  50. * instance is to be initialized.
  51. */
  52. constructor(props: Props) {
  53. super(props);
  54. // Bind event handlers so they are only bound once per instance.
  55. this._onPasswordChanged = this._onPasswordChanged.bind(this);
  56. this._onCancel = this._onCancel.bind(this);
  57. this._onSubmit = this._onSubmit.bind(this);
  58. }
  59. /**
  60. * Implements React's {@link Component#render()}.
  61. *
  62. * @inheritdoc
  63. * @returns {ReactElement}
  64. */
  65. render() {
  66. return (
  67. <Dialog
  68. disableBlanketClickDismiss = { true }
  69. isModal = { false }
  70. onCancel = { this._onCancel }
  71. onSubmit = { this._onSubmit }
  72. titleKey = 'dialog.passwordRequired'
  73. width = 'small'>
  74. { this._renderBody() }
  75. </Dialog>
  76. );
  77. }
  78. /**
  79. * Display component in dialog body.
  80. *
  81. * @returns {ReactElement}
  82. * @protected
  83. */
  84. _renderBody() {
  85. return (
  86. <div>
  87. <TextField
  88. autoFocus = { true }
  89. compact = { true }
  90. label = { this.props.t('dialog.passwordLabel') }
  91. name = 'lockKey'
  92. onChange = { this._onPasswordChanged }
  93. shouldFitContainer = { true }
  94. type = 'password'
  95. value = { this.state.password } />
  96. </div>
  97. );
  98. }
  99. _onPasswordChanged: ({ target: { value: * }}) => void;
  100. /**
  101. * Notifies this dialog that password has changed.
  102. *
  103. * @param {Object} event - The details of the notification/event.
  104. * @private
  105. * @returns {void}
  106. */
  107. _onPasswordChanged({ target: { value } }) {
  108. this.setState({
  109. password: value
  110. });
  111. }
  112. _onCancel: () => boolean;
  113. /**
  114. * Dispatches action to cancel and dismiss this dialog.
  115. *
  116. * @private
  117. * @returns {boolean}
  118. */
  119. _onCancel() {
  120. this.props.dispatch(
  121. _cancelPasswordRequiredPrompt(this.props.conference));
  122. return true;
  123. }
  124. _onSubmit: () => boolean;
  125. /**
  126. * Dispatches action to submit value from this dialog.
  127. *
  128. * @private
  129. * @returns {boolean}
  130. */
  131. _onSubmit() {
  132. const { conference } = this.props;
  133. // We received that password is required, but user is trying anyway to
  134. // login without a password. Mark the room as not locked in case she
  135. // succeeds (maybe someone removed the password meanwhile). If it is
  136. // still locked, another password required will be received and the room
  137. // again will be marked as locked.
  138. this.props.dispatch(
  139. setPassword(conference, conference.join, this.state.password));
  140. // We have used the password so let's clean it.
  141. this.setState({
  142. password: undefined
  143. });
  144. return true;
  145. }
  146. }
  147. export default translate(connect()(PasswordRequiredPrompt));