Files
jitsi-meet/react/features/invite/components/info-dialog/PasswordForm.web.js
Leonard Kim 486e8e35d9 ref: move all prop type declaration to flow
For the most part the changes are taking the "static propTypes" declaration off
of components and declaring them as Flow types. Sometimes to support flow some
method signatures had to be added. There are some exceptions in which more had
to be done to tame the beast:
- AbstractVideoTrack: put in additional truthy checks for videoTrack.
- Video: add truthy checks for the _videoElement ref.
- shouldRenderVideoTrack function: Some component could pass null for the
  videoTrack argument and Flow wanted that called out explicitly.
- DisplayName: Add a truthy check for the input ref before acting on it.
- NumbersList: Move array checks inline for Flow to comprehend array methods
  could be called. Add type checks in the Object.entries loop as the value is
  assumed to be a mixed type by Flow.
- AbstractToolbarButton: add additional truthy check for passed in type.
2018-11-07 17:38:10 +01:00

187 lines
4.9 KiB
JavaScript

/* @flow */
import React, { Component } from 'react';
import { translate } from '../../../base/i18n';
import { LOCKED_LOCALLY } from '../../../room-lock';
/**
* The type of the React {@code Component} props of {@link PasswordForm}.
*/
type Props = {
/**
* Whether or not to show the password editing field.
*/
editEnabled: boolean,
/**
* The value for how the conference is locked (or undefined if not locked)
* as defined by room-lock constants.
*/
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,
/**
* Invoked to obtain translated strings.
*/
t: Function
};
/**
* 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.
*
* @extends Component
*/
class PasswordForm extends Component<Props, State> {
state = {
enteredPassword: ''
};
/**
* Initializes a new {@code PasswordForm} instance.
*
* @param {Props} props - The React {@code Component} props to initialize
* the new {@code PasswordForm} instance with.
*/
constructor(props: Props) {
super(props);
// Bind event handlers so they are only bound once per instance.
this._onEnteredPasswordChange
= this._onEnteredPasswordChange.bind(this);
this._onPasswordSubmit = this._onPasswordSubmit.bind(this);
}
/**
* Implements React's {@link Component#componentWillReceiveProps()}. Invoked
* before this mounted component receives new props.
*
* @inheritdoc
* @param {Props} nextProps - New props component will receive.
*/
componentWillReceiveProps(nextProps: Props) {
if (this.props.editEnabled && !nextProps.editEnabled) {
this.setState({ enteredPassword: '' });
}
}
/**
* Implements React's {@link Component#render()}.
*
* @inheritdoc
* @returns {ReactElement}
*/
render() {
const { t } = this.props;
return (
<div className = 'info-password'>
<span className = 'info-label'>
{ t('info.password') }
</span>
<span className = 'spacer'>&nbsp;</span>
<span className = 'info-password-field info-value'>
{ this._renderPasswordField() }
</span>
</div>
);
}
/**
* 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) {
return (
<form
className = 'info-password-form'
onSubmit = { this._onPasswordSubmit }>
<input
autoFocus = { true }
className = 'info-password-input'
onChange = { this._onEnteredPasswordChange }
spellCheck = { 'false' }
type = 'text'
value = { this.state.enteredPassword } />
</form>
);
} else if (this.props.locked === LOCKED_LOCALLY) {
return (
<div className = 'info-password-local'>
{ this.props.password }
</div>
);
} else if (this.props.locked) {
return (
<div className = 'info-password-remote'>
{ this.props.t('passwordSetRemotely') }
</div>
);
}
return (
<div className = 'info-password-none'>
{ this.props.t('info.noPassword') }
</div>
);
}
_onEnteredPasswordChange: (Object) => void;
/**
* Updates the internal state of entered password.
*
* @param {Object} event - DOM Event for value change.
* @private
* @returns {void}
*/
_onEnteredPasswordChange(event) {
this.setState({ enteredPassword: event.target.value });
}
_onPasswordSubmit: (Object) => void;
/**
* Invokes the passed in onSubmit callback to notify the parent that a
* password submission has been attempted.
*
* @param {Object} event - DOM Event for form submission.
* @private
* @returns {void}
*/
_onPasswordSubmit(event) {
event.preventDefault();
this.props.onSubmit(this.state.enteredPassword);
}
}
export default translate(PasswordForm);