2018-10-30 05:02:23 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2017-10-06 16:14:45 +00:00
|
|
|
import { FieldTextStateless as TextField } from '@atlaskit/field-text';
|
2020-05-20 10:57:03 +00:00
|
|
|
import React from 'react';
|
2017-07-28 17:58:04 +00:00
|
|
|
|
2019-04-11 08:28:51 +00:00
|
|
|
import { Dialog } from '../../../base/dialog';
|
|
|
|
import { translate } from '../../../base/i18n';
|
|
|
|
import { connect } from '../../../base/redux';
|
2019-01-13 19:33:28 +00:00
|
|
|
import AbstractDisplayNamePrompt, {
|
|
|
|
type Props
|
2019-04-11 08:28:51 +00:00
|
|
|
} from '../AbstractDisplayNamePrompt';
|
2018-10-30 05:02:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of {@link DisplayNamePrompt}.
|
|
|
|
*/
|
|
|
|
type State = {
|
2017-07-28 17:58:04 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* The name to show in the display name text field.
|
|
|
|
*/
|
|
|
|
displayName: string
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements a React {@code Component} for displaying a dialog with an field
|
|
|
|
* for setting the local participant's display name.
|
|
|
|
*
|
2021-11-04 21:10:43 +00:00
|
|
|
* @augments Component
|
2018-10-30 05:02:23 +00:00
|
|
|
*/
|
2019-01-13 19:33:28 +00:00
|
|
|
class DisplayNamePrompt extends AbstractDisplayNamePrompt<State> {
|
2017-07-28 17:58:04 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new {@code DisplayNamePrompt} 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-07-28 17:58:04 +00:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
displayName: ''
|
|
|
|
};
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once for every instance.
|
|
|
|
this._onDisplayNameChange = this._onDisplayNameChange.bind(this);
|
|
|
|
this._onSubmit = this._onSubmit.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Dialog
|
2019-06-24 08:37:00 +00:00
|
|
|
isModal = { false }
|
2017-07-28 17:58:04 +00:00
|
|
|
onSubmit = { this._onSubmit }
|
|
|
|
titleKey = 'dialog.displayNameRequired'
|
|
|
|
width = 'small'>
|
2017-10-06 16:14:45 +00:00
|
|
|
<TextField
|
2017-07-28 17:58:04 +00:00
|
|
|
autoFocus = { true }
|
|
|
|
compact = { true }
|
|
|
|
label = { this.props.t('dialog.enterDisplayName') }
|
|
|
|
name = 'displayName'
|
|
|
|
onChange = { this._onDisplayNameChange }
|
|
|
|
shouldFitContainer = { true }
|
|
|
|
type = 'text'
|
|
|
|
value = { this.state.displayName } />
|
|
|
|
</Dialog>);
|
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_onDisplayNameChange: (Object) => void;
|
|
|
|
|
2017-07-28 17:58:04 +00:00
|
|
|
/**
|
|
|
|
* Updates the entered display name.
|
|
|
|
*
|
|
|
|
* @param {Object} event - The DOM event triggered from the entered display
|
|
|
|
* name value having changed.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onDisplayNameChange(event) {
|
|
|
|
this.setState({
|
|
|
|
displayName: event.target.value
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-13 19:33:28 +00:00
|
|
|
_onSetDisplayName: string => boolean;
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_onSubmit: () => boolean;
|
|
|
|
|
2017-07-28 17:58:04 +00:00
|
|
|
/**
|
|
|
|
* Dispatches an action to update the local participant's display name. A
|
|
|
|
* name must be entered for the action to dispatch.
|
|
|
|
*
|
|
|
|
* @private
|
2018-10-30 05:02:23 +00:00
|
|
|
* @returns {boolean}
|
2017-07-28 17:58:04 +00:00
|
|
|
*/
|
|
|
|
_onSubmit() {
|
2019-01-13 19:33:28 +00:00
|
|
|
return this._onSetDisplayName(this.state.displayName);
|
2017-07-28 17:58:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-13 19:33:28 +00:00
|
|
|
export default translate(connect()(DisplayNamePrompt));
|