2018-02-13 19:46:47 +00:00
|
|
|
import React, { Component } from 'react';
|
2022-08-04 08:26:13 +00:00
|
|
|
import { WithTranslation } from 'react-i18next';
|
2018-02-13 19:46:47 +00:00
|
|
|
|
2022-08-04 08:26:13 +00:00
|
|
|
import { translate } from '../../../../base/i18n/functions';
|
|
|
|
import Input from '../../../../base/ui/components/web/Input';
|
|
|
|
// eslint-disable-next-line lines-around-comment
|
|
|
|
// @ts-ignore
|
2021-04-09 12:30:25 +00:00
|
|
|
import { LOCKED_LOCALLY } from '../../../../room-lock';
|
2018-02-13 19:46:47 +00:00
|
|
|
|
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* The type of the React {@code Component} props of {@link PasswordForm}.
|
2018-02-13 19:46:47 +00:00
|
|
|
*/
|
2022-08-04 08:26:13 +00:00
|
|
|
interface Props extends WithTranslation {
|
2018-10-30 05:02:23 +00:00
|
|
|
|
2018-02-13 19:46:47 +00:00
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* Whether or not to show the password editing field.
|
2018-02-13 19:46:47 +00:00
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
editEnabled: boolean,
|
2018-02-13 19:46:47 +00:00
|
|
|
|
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* The value for how the conference is locked (or undefined if not locked)
|
|
|
|
* as defined by room-lock constants.
|
2018-02-13 19:46:47 +00:00
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
locked: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to invoke when the local participant is submitting a password
|
|
|
|
* set request.
|
|
|
|
*/
|
|
|
|
onSubmit: Function,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current known password for the JitsiConference.
|
|
|
|
*/
|
|
|
|
password: string,
|
|
|
|
|
2019-05-22 07:43:17 +00:00
|
|
|
/**
|
|
|
|
* The number of digits to be used in the password.
|
|
|
|
*/
|
2022-08-04 08:26:13 +00:00
|
|
|
passwordNumberOfDigits?: number
|
|
|
|
}
|
2018-10-30 05:02:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} state of {@link PasswordForm}.
|
|
|
|
*/
|
|
|
|
type State = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The value of the password being entered by the local participant.
|
|
|
|
*/
|
|
|
|
enteredPassword: string
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* React {@code Component} for displaying and editing the conference password.
|
|
|
|
*
|
2021-11-04 21:10:43 +00:00
|
|
|
* @augments Component
|
2018-10-30 05:02:23 +00:00
|
|
|
*/
|
|
|
|
class PasswordForm extends Component<Props, State> {
|
2018-10-29 02:11:03 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#getDerivedStateFromProps()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2022-08-04 08:26:13 +00:00
|
|
|
static getDerivedStateFromProps(props: Props, state: State) {
|
2018-10-29 02:11:03 +00:00
|
|
|
return {
|
|
|
|
enteredPassword: props.editEnabled ? state.enteredPassword : ''
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-02-13 19:46:47 +00:00
|
|
|
state = {
|
|
|
|
enteredPassword: ''
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a new {@code PasswordForm} instance.
|
|
|
|
*
|
|
|
|
* @param {Props} props - The React {@code Component} props to initialize
|
|
|
|
* the new {@code PasswordForm} instance with.
|
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
constructor(props: Props) {
|
2018-02-13 19:46:47 +00:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once per instance.
|
2022-01-21 12:58:54 +00:00
|
|
|
this._onEnteredPasswordChange = this._onEnteredPasswordChange.bind(this);
|
2021-06-10 12:48:44 +00:00
|
|
|
this._onKeyPress = this._onKeyPress.bind(this);
|
2018-02-13 19:46:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div className = 'info-password'>
|
2022-08-04 08:26:13 +00:00
|
|
|
{this._renderPassword()}
|
|
|
|
{this._renderPasswordField()}
|
2018-02-13 19:46:47 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-08-04 08:26:13 +00:00
|
|
|
/** .........
|
|
|
|
* Renders the password if there is any.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
_renderPassword() {
|
|
|
|
const { locked, t } = this.props;
|
|
|
|
|
|
|
|
return locked && <>
|
|
|
|
<span className = 'info-label'>
|
|
|
|
{t('info.password')}
|
|
|
|
</span>
|
|
|
|
<span className = 'spacer'> </span>
|
|
|
|
<span className = 'info-password-field info-value'>
|
|
|
|
{locked === LOCKED_LOCALLY ? (
|
|
|
|
<div className = 'info-password-local'>
|
|
|
|
{this.props.password}
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className = 'info-password-remote'>
|
|
|
|
{this.props.t('passwordSetRemotely')}
|
|
|
|
</div>
|
|
|
|
) }
|
|
|
|
{this._renderPasswordField()}
|
|
|
|
</span>
|
|
|
|
</>;
|
|
|
|
}
|
|
|
|
|
2018-02-13 19:46:47 +00:00
|
|
|
/**
|
|
|
|
* Returns a ReactElement for showing the current state of the password or
|
|
|
|
* for editing the current password.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
_renderPasswordField() {
|
|
|
|
if (this.props.editEnabled) {
|
2022-08-04 08:26:13 +00:00
|
|
|
let placeHolderText = this.props.t('dialog.password');
|
2019-05-22 07:43:17 +00:00
|
|
|
|
|
|
|
if (this.props.passwordNumberOfDigits) {
|
|
|
|
placeHolderText = this.props.t('passwordDigitsOnly', {
|
|
|
|
number: this.props.passwordNumberOfDigits });
|
|
|
|
}
|
|
|
|
|
2018-02-13 19:46:47 +00:00
|
|
|
return (
|
2022-01-21 12:58:54 +00:00
|
|
|
<div
|
|
|
|
className = 'info-password-form'>
|
2022-08-04 08:26:13 +00:00
|
|
|
<Input
|
|
|
|
accessibilityLabel = { this.props.t('info.addPassword') }
|
2018-02-13 19:46:47 +00:00
|
|
|
autoFocus = { true }
|
2022-08-04 08:26:13 +00:00
|
|
|
id = 'info-password-input'
|
2019-05-22 07:43:17 +00:00
|
|
|
maxLength = { this.props.passwordNumberOfDigits }
|
2018-02-13 19:46:47 +00:00
|
|
|
onChange = { this._onEnteredPasswordChange }
|
2022-01-21 12:58:54 +00:00
|
|
|
onKeyPress = { this._onKeyPress }
|
2019-05-22 07:43:17 +00:00
|
|
|
placeholder = { placeHolderText }
|
2018-02-13 19:46:47 +00:00
|
|
|
value = { this.state.enteredPassword } />
|
2022-01-21 12:58:54 +00:00
|
|
|
</div>
|
2018-02-13 19:46:47 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the internal state of entered password.
|
|
|
|
*
|
2022-08-04 08:26:13 +00:00
|
|
|
* @param {string} value - DOM Event for value change.
|
2018-02-13 19:46:47 +00:00
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-08-04 08:26:13 +00:00
|
|
|
_onEnteredPasswordChange(value: string) {
|
|
|
|
this.setState({ enteredPassword: value });
|
2018-02-13 19:46:47 +00:00
|
|
|
}
|
|
|
|
|
2019-03-05 14:26:45 +00:00
|
|
|
/**
|
|
|
|
* Stops the the EnterKey for propagation in order to prevent the dialog
|
|
|
|
* to close.
|
|
|
|
*
|
|
|
|
* @param {Object} event - The key event.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-08-04 08:26:13 +00:00
|
|
|
_onKeyPress(event: React.KeyboardEvent) {
|
2019-03-05 14:26:45 +00:00
|
|
|
if (event.key === 'Enter') {
|
2022-01-21 12:58:54 +00:00
|
|
|
event.preventDefault();
|
2019-03-05 14:26:45 +00:00
|
|
|
event.stopPropagation();
|
2022-01-21 12:58:54 +00:00
|
|
|
|
|
|
|
this.props.onSubmit(this.state.enteredPassword);
|
2019-03-05 14:26:45 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-13 19:46:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(PasswordForm);
|