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.tsx 4.2KB

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