| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 | 
							- /* @flow */
 - 
 - import React, { Component } from 'react';
 - import { connect } from 'react-redux';
 - import { FieldTextStateless as TextField } from '@atlaskit/field-text';
 - 
 - import { Dialog } from '../../base/dialog';
 - import { translate } from '../../base/i18n';
 - import {
 -     getLocalParticipant,
 -     participantDisplayNameChanged
 - } from '../../base/participants';
 - 
 - /**
 -  * The type of the React {@code Component} props of {@link DisplayNamePrompt}.
 -  */
 - type Props = {
 - 
 -     /**
 -      * The current ID for the local participant. Used for setting the display
 -      * name on the associated participant.
 -      */
 -     _localParticipantID: string,
 - 
 -     /**
 -      * Invoked to update the local participant's display name.
 -      */
 -     dispatch: Dispatch<*>,
 - 
 -     /**
 -      * Invoked to obtain translated strings.
 -      */
 -     t: Function
 - };
 - 
 - /**
 -  * The type of the React {@code Component} props of {@link DisplayNamePrompt}.
 -  */
 - type State = {
 - 
 -     /**
 -      * 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.
 -  *
 -  * @extends Component
 -  */
 - class DisplayNamePrompt extends Component<Props, State> {
 -     /**
 -      * Initializes a new {@code DisplayNamePrompt} instance.
 -      *
 -      * @param {Object} props - The read-only properties with which the new
 -      * instance is to be initialized.
 -      */
 -     constructor(props: Props) {
 -         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
 -                 isModal = { true }
 -                 onSubmit = { this._onSubmit }
 -                 titleKey = 'dialog.displayNameRequired'
 -                 width = 'small'>
 -                 <TextField
 -                     autoFocus = { true }
 -                     compact = { true }
 -                     label = { this.props.t('dialog.enterDisplayName') }
 -                     name = 'displayName'
 -                     onChange = { this._onDisplayNameChange }
 -                     shouldFitContainer = { true }
 -                     type = 'text'
 -                     value = { this.state.displayName } />
 -             </Dialog>);
 -     }
 - 
 -     _onDisplayNameChange: (Object) => void;
 - 
 -     /**
 -      * 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
 -         });
 -     }
 - 
 -     _onSubmit: () => boolean;
 - 
 -     /**
 -      * Dispatches an action to update the local participant's display name. A
 -      * name must be entered for the action to dispatch.
 -      *
 -      * @private
 -      * @returns {boolean}
 -      */
 -     _onSubmit() {
 -         const { displayName } = this.state;
 - 
 -         if (!displayName.trim()) {
 -             return false;
 -         }
 - 
 -         const { dispatch, _localParticipantID } = this.props;
 - 
 -         dispatch(
 -             participantDisplayNameChanged(_localParticipantID, displayName));
 - 
 -         return true;
 -     }
 - }
 - 
 - /**
 -  * Maps (parts of) the Redux state to the associated {@code DisplayNamePrompt}'s
 -  * props.
 -  *
 -  * @param {Object} state - The Redux state.
 -  * @private
 -  * @returns {{
 -  *     _localParticipantID: string
 -  * }}
 -  */
 - function _mapStateToProps(state) {
 -     const { id } = getLocalParticipant(state);
 - 
 -     return {
 -         /**
 -          * The current ID for the local participant.
 -          *
 -          * @type {string}
 -          */
 -         _localParticipantID: id
 -     };
 - }
 - 
 - export default translate(connect(_mapStateToProps)(DisplayNamePrompt));
 
 
  |