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.js 3.8KB

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