Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

PasswordRequiredPrompt.native.tsx 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. import { IReduxState, IStore } from '../../app/types';
  4. import { setPassword } from '../../base/conference/actions';
  5. import { IJitsiConference } from '../../base/conference/reducer';
  6. import InputDialog from '../../base/dialog/components/native/InputDialog';
  7. import { _cancelPasswordRequiredPrompt } from '../actions';
  8. /**
  9. * {@code PasswordRequiredPrompt}'s React {@code Component} prop types.
  10. */
  11. interface IProps {
  12. /**
  13. * The previously entered password, if any.
  14. */
  15. _password?: string;
  16. /**
  17. * The {@code JitsiConference} which requires a password.
  18. *
  19. * @type {JitsiConference}
  20. */
  21. conference: IJitsiConference;
  22. /**
  23. * The redux dispatch function.
  24. */
  25. dispatch: IStore['dispatch'];
  26. }
  27. interface IState {
  28. /**
  29. * The previously entered password, if any.
  30. */
  31. password?: string;
  32. }
  33. /**
  34. * Implements a React {@code Component} which prompts the user when a password
  35. * is required to join a conference.
  36. */
  37. class PasswordRequiredPrompt extends Component<IProps, IState> {
  38. /**
  39. * Initializes a new {@code PasswordRequiredPrompt} instance.
  40. *
  41. * @param {IProps} props - The read-only React {@code Component} props with
  42. * which the new instance is to be initialized.
  43. */
  44. constructor(props: IProps) {
  45. super(props);
  46. this.state = {
  47. password: props._password
  48. };
  49. // Bind event handlers so they are only bound once per instance.
  50. this._onCancel = this._onCancel.bind(this);
  51. this._onSubmit = this._onSubmit.bind(this);
  52. }
  53. /**
  54. * Implements {@code Component#componentDidUpdate}.
  55. *
  56. * @inheritdoc
  57. */
  58. componentDidUpdate() {
  59. const { _password } = this.props;
  60. // The previous password in Redux gets cleared after the dialog appears and it ends up breaking the dialog
  61. // logic. We move the prop into state and only update it if it has an actual value, avoiding losing the
  62. // previously received value when Redux updates.
  63. if (_password && _password !== this.state.password) {
  64. // eslint-disable-next-line react/no-did-update-set-state
  65. this.setState({
  66. password: _password
  67. });
  68. }
  69. }
  70. /**
  71. * Implements React's {@link Component#render()}.
  72. *
  73. * @inheritdoc
  74. * @returns {ReactElement}
  75. */
  76. render() {
  77. const { password } = this.state;
  78. return (
  79. <InputDialog
  80. descriptionKey = 'dialog.passwordLabel'
  81. initialValue = { password }
  82. messageKey = { password ? 'dialog.incorrectRoomLockPassword' : undefined }
  83. onCancel = { this._onCancel }
  84. onSubmit = { this._onSubmit }
  85. textInputProps = {{
  86. secureTextEntry: true
  87. }}
  88. titleKey = 'dialog.password' />
  89. );
  90. }
  91. /**
  92. * Notifies this prompt that it has been dismissed by cancel.
  93. *
  94. * @private
  95. * @returns {boolean} If this prompt is to be closed/hidden, {@code true};
  96. * otherwise, {@code false}.
  97. */
  98. _onCancel() {
  99. this.props.dispatch(
  100. _cancelPasswordRequiredPrompt(this.props.conference));
  101. return true;
  102. }
  103. /**
  104. * Notifies this prompt that it has been dismissed by submitting a specific
  105. * value.
  106. *
  107. * @param {string|undefined} value - The submitted value.
  108. * @private
  109. * @returns {boolean} If this prompt is to be closed/hidden, {@code true};
  110. * otherwise, {@code false}.
  111. */
  112. _onSubmit(value?: string) {
  113. const { conference } = this.props;
  114. this.props.dispatch(setPassword(conference, conference.join, value));
  115. return true;
  116. }
  117. }
  118. /**
  119. * Maps part of the Redux state to the props of this component.
  120. *
  121. * @param {Object} state - The Redux state.
  122. * @returns {IProps}
  123. */
  124. function _mapStateToProps(state: IReduxState) {
  125. return {
  126. _password: state['features/base/conference'].password
  127. };
  128. }
  129. export default connect(_mapStateToProps)(PasswordRequiredPrompt);