jiti-meet/react/features/room-lock/components/PasswordRequiredPrompt.nati...

117 lines
3.1 KiB
JavaScript
Raw Normal View History

2017-10-04 22:36:09 +00:00
// @flow
import PropTypes from 'prop-types';
2016-12-12 01:02:50 +00:00
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { setPassword } from '../../base/conference';
import { Dialog } from '../../base/dialog';
2016-12-12 01:02:50 +00:00
/**
2017-10-04 22:36:09 +00:00
* {@code PasswordRequiredPrompt}'s React {@code Component} prop types.
*/
type Props = {
/**
* The {@code JitsiConference} which requires a password.
*
* @type {JitsiConference}
*/
conference: { join: Function },
dispatch: Dispatch<*>
};
/**
* The style of the {@link TextInput} rendered by
* {@code PasswordRequiredPrompt}. As it requests the entry of a password, the
* entry should better be secure.
*/
const _TEXT_INPUT_PROPS = {
secureTextEntry: true
};
2017-10-04 22:36:09 +00:00
/**
* Implements a React {@code Component} which prompts the user when a password
* is required to join a conference.
2016-12-12 01:02:50 +00:00
*/
class PasswordRequiredPrompt extends Component {
/**
2017-10-04 22:36:09 +00:00
* {@code PasswordRequiredPrompt}'s React {@code Component} prop types.
2016-12-12 01:02:50 +00:00
*
* @static
*/
static propTypes = {
conference: PropTypes.object,
dispatch: PropTypes.func
};
2016-12-12 01:02:50 +00:00
/**
2017-10-04 22:36:09 +00:00
* Initializes a new {@code PasswordRequiredPrompt} instance.
2016-12-12 01:02:50 +00:00
*
2017-10-04 22:36:09 +00:00
* @param {Props} props - The read-only React {@code Component} props with
* which the new instance is to be initialized.
2016-12-12 01:02:50 +00:00
*/
2017-10-04 22:36:09 +00:00
constructor(props: Props) {
2016-12-12 01:02:50 +00:00
super(props);
2017-10-04 22:36:09 +00:00
// Bind event handlers so they are only bound once per instance.
2016-12-12 01:02:50 +00:00
this._onCancel = this._onCancel.bind(this);
this._onSubmit = this._onSubmit.bind(this);
}
/**
* Implements React's {@link Component#render()}.
*
* @inheritdoc
* @returns {ReactElement}
*/
render() {
return (
<Dialog
bodyKey = 'dialog.passwordLabel'
2016-12-12 01:02:50 +00:00
onCancel = { this._onCancel }
onSubmit = { this._onSubmit }
textInputProps = { _TEXT_INPUT_PROPS }
titleKey = 'dialog.passwordRequired' />
2016-12-12 01:02:50 +00:00
);
}
2017-10-04 22:36:09 +00:00
_onCancel: () => boolean;
2016-12-12 01:02:50 +00:00
/**
* Notifies this prompt that it has been dismissed by cancel.
*
* @private
2017-10-04 22:36:09 +00:00
* @returns {boolean} If this prompt is to be closed/hidden, {@code true};
* otherwise, {@code false}.
2016-12-12 01:02:50 +00:00
*/
_onCancel() {
// XXX The user has canceled this prompt for a password so we are to
// attempt joining the conference without a password. If the conference
// still requires a password to join, the user will be prompted again
// later.
return this._onSubmit(undefined);
2016-12-12 01:02:50 +00:00
}
2017-10-04 22:36:09 +00:00
_onSubmit: (?string) => boolean;
2016-12-12 01:02:50 +00:00
/**
* Notifies this prompt that it has been dismissed by submitting a specific
* value.
*
2017-10-04 22:36:09 +00:00
* @param {string|undefined} value - The submitted value.
2016-12-12 01:02:50 +00:00
* @private
2017-10-04 22:36:09 +00:00
* @returns {boolean} If this prompt is to be closed/hidden, {@code true};
* otherwise, {@code false}.
2016-12-12 01:02:50 +00:00
*/
2017-10-04 22:36:09 +00:00
_onSubmit(value: ?string) {
const { conference }: { conference: { join: Function } } = this.props;
2016-12-12 01:02:50 +00:00
this.props.dispatch(setPassword(conference, conference.join, value));
return true;
2016-12-12 01:02:50 +00:00
}
}
export default connect()(PasswordRequiredPrompt);