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.native.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // @flow
  2. import React, { Component } from 'react';
  3. import type { Dispatch } from 'redux';
  4. import { setPassword } from '../../base/conference';
  5. import { InputDialog } from '../../base/dialog';
  6. import { connect } from '../../base/redux';
  7. import { _cancelPasswordRequiredPrompt } from '../actions';
  8. /**
  9. * {@code PasswordRequiredPrompt}'s React {@code Component} prop types.
  10. */
  11. type Props = {
  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: { join: Function },
  22. /**
  23. * The redux dispatch function.
  24. */
  25. dispatch: Dispatch<any>
  26. };
  27. type State = {
  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<Props, State> {
  38. /**
  39. * Initializes a new {@code PasswordRequiredPrompt} instance.
  40. *
  41. * @param {Props} props - The read-only React {@code Component} props with
  42. * which the new instance is to be initialized.
  43. */
  44. constructor(props: Props) {
  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. contentKey = '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. );
  89. }
  90. _onCancel: () => boolean;
  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. _onSubmit: (?string) => boolean;
  104. /**
  105. * Notifies this prompt that it has been dismissed by submitting a specific
  106. * value.
  107. *
  108. * @param {string|undefined} value - The submitted value.
  109. * @private
  110. * @returns {boolean} If this prompt is to be closed/hidden, {@code true};
  111. * otherwise, {@code false}.
  112. */
  113. _onSubmit(value: ?string) {
  114. const { conference }: { conference: { join: Function } } = this.props;
  115. this.props.dispatch(setPassword(conference, conference.join, value));
  116. return true;
  117. }
  118. }
  119. /**
  120. * Maps part of the Redux state to the props of this component.
  121. *
  122. * @param {Object} state - The Redux state.
  123. * @returns {Props}
  124. */
  125. function _mapStateToProps(state) {
  126. return {
  127. _password: state['features/base/conference'].password
  128. };
  129. }
  130. export default connect(_mapStateToProps)(PasswordRequiredPrompt);