2017-10-04 22:36:09 +00:00
|
|
|
// @flow
|
2018-10-30 05:02:23 +00:00
|
|
|
|
2019-03-19 15:42:25 +00:00
|
|
|
import { FieldTextStateless as TextField } from '@atlaskit/field-text';
|
2017-03-07 03:43:41 +00:00
|
|
|
import React, { Component } from 'react';
|
2019-03-19 15:42:25 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
2017-03-07 03:43:41 +00:00
|
|
|
|
|
|
|
import { setPassword } from '../../base/conference';
|
|
|
|
import { Dialog } from '../../base/dialog';
|
|
|
|
import { translate } from '../../base/i18n';
|
2019-03-21 16:38:29 +00:00
|
|
|
import { connect } from '../../base/redux';
|
2017-03-07 03:43:41 +00:00
|
|
|
|
2019-07-01 12:02:25 +00:00
|
|
|
import { _cancelPasswordRequiredPrompt } from '../actions';
|
|
|
|
|
2017-03-07 03:43:41 +00:00
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* The type of the React {@code Component} props of
|
|
|
|
* {@link PasswordRequiredPrompt}.
|
2017-03-07 03:43:41 +00:00
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
type Props = {
|
|
|
|
|
2017-03-07 03:43:41 +00:00
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* The JitsiConference which requires a password.
|
2017-03-07 03:43:41 +00:00
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
conference: Object,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The redux store's {@code dispatch} function.
|
|
|
|
*/
|
2019-03-19 15:42:25 +00:00
|
|
|
dispatch: Dispatch<any>,
|
2018-10-30 05:02:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The translate function.
|
|
|
|
*/
|
|
|
|
t: Function
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} state of
|
|
|
|
* {@link PasswordRequiredPrompt}.
|
|
|
|
*/
|
|
|
|
type State = {
|
2017-03-07 03:43:41 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* The password entered by the local participant.
|
|
|
|
*/
|
|
|
|
password: string
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements a React Component which prompts the user when a password is
|
|
|
|
* required to join a conference.
|
|
|
|
*/
|
|
|
|
class PasswordRequiredPrompt extends Component<Props, State> {
|
2017-10-04 22:36:09 +00:00
|
|
|
state = {
|
|
|
|
password: ''
|
|
|
|
};
|
|
|
|
|
2017-03-07 03:43:41 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new PasswordRequiredPrompt instance.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only properties with which the new
|
|
|
|
* instance is to be initialized.
|
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
constructor(props: Props) {
|
2017-03-07 03:43:41 +00:00
|
|
|
super(props);
|
|
|
|
|
2017-10-04 22:36:09 +00:00
|
|
|
// Bind event handlers so they are only bound once per instance.
|
2017-03-07 03:43:41 +00:00
|
|
|
this._onPasswordChanged = this._onPasswordChanged.bind(this);
|
2019-07-01 12:02:25 +00:00
|
|
|
this._onCancel = this._onCancel.bind(this);
|
2017-03-07 03:43:41 +00:00
|
|
|
this._onSubmit = this._onSubmit.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Dialog
|
2019-07-01 12:02:25 +00:00
|
|
|
disableBlanketClickDismiss = { true }
|
|
|
|
isModal = { false }
|
|
|
|
onCancel = { this._onCancel }
|
2017-03-07 03:43:41 +00:00
|
|
|
onSubmit = { this._onSubmit }
|
|
|
|
titleKey = 'dialog.passwordRequired'
|
|
|
|
width = 'small'>
|
|
|
|
{ this._renderBody() }
|
2017-10-04 22:36:09 +00:00
|
|
|
</Dialog>
|
|
|
|
);
|
2017-03-07 03:43:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display component in dialog body.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
_renderBody() {
|
|
|
|
return (
|
|
|
|
<div>
|
2017-10-06 16:14:45 +00:00
|
|
|
<TextField
|
2017-06-06 20:34:21 +00:00
|
|
|
autoFocus = { true }
|
2017-03-07 03:43:41 +00:00
|
|
|
compact = { true }
|
2017-04-18 21:49:52 +00:00
|
|
|
label = { this.props.t('dialog.passwordLabel') }
|
2017-03-07 03:43:41 +00:00
|
|
|
name = 'lockKey'
|
|
|
|
onChange = { this._onPasswordChanged }
|
|
|
|
shouldFitContainer = { true }
|
|
|
|
type = 'text'
|
|
|
|
value = { this.state.password } />
|
2017-04-18 21:49:52 +00:00
|
|
|
</div>
|
|
|
|
);
|
2017-03-07 03:43:41 +00:00
|
|
|
}
|
|
|
|
|
2017-10-04 22:36:09 +00:00
|
|
|
_onPasswordChanged: ({ target: { value: * }}) => void;
|
|
|
|
|
2017-03-07 03:43:41 +00:00
|
|
|
/**
|
|
|
|
* Notifies this dialog that password has changed.
|
|
|
|
*
|
|
|
|
* @param {Object} event - The details of the notification/event.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2017-10-04 22:36:09 +00:00
|
|
|
_onPasswordChanged({ target: { value } }) {
|
2017-04-18 21:49:52 +00:00
|
|
|
this.setState({
|
2017-10-04 22:36:09 +00:00
|
|
|
password: value
|
2017-04-18 21:49:52 +00:00
|
|
|
});
|
2017-03-07 03:43:41 +00:00
|
|
|
}
|
|
|
|
|
2019-07-01 12:02:25 +00:00
|
|
|
_onCancel: () => boolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatches action to cancel and dismiss this dialog.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
_onCancel() {
|
|
|
|
|
|
|
|
this.props.dispatch(
|
|
|
|
_cancelPasswordRequiredPrompt(this.props.conference));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-10-04 22:36:09 +00:00
|
|
|
_onSubmit: () => boolean;
|
|
|
|
|
2017-03-07 03:43:41 +00:00
|
|
|
/**
|
2017-10-04 22:36:09 +00:00
|
|
|
* Dispatches action to submit value from this dialog.
|
2017-03-07 03:43:41 +00:00
|
|
|
*
|
|
|
|
* @private
|
2017-10-04 22:36:09 +00:00
|
|
|
* @returns {boolean}
|
2017-03-07 03:43:41 +00:00
|
|
|
*/
|
|
|
|
_onSubmit() {
|
2017-04-18 21:49:52 +00:00
|
|
|
const { conference } = this.props;
|
|
|
|
|
|
|
|
// We received that password is required, but user is trying anyway to
|
|
|
|
// login without a password. Mark the room as not locked in case she
|
|
|
|
// succeeds (maybe someone removed the password meanwhile). If it is
|
|
|
|
// still locked, another password required will be received and the room
|
|
|
|
// again will be marked as locked.
|
|
|
|
this.props.dispatch(
|
|
|
|
setPassword(conference, conference.join, this.state.password));
|
2017-03-07 03:43:41 +00:00
|
|
|
|
2017-04-18 21:49:52 +00:00
|
|
|
// We have used the password so let's clean it.
|
|
|
|
this.setState({
|
|
|
|
password: undefined
|
|
|
|
});
|
2017-03-07 03:43:41 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect()(PasswordRequiredPrompt));
|