import Button from '@atlaskit/button'; import { StatelessDropdownMenu } from '@atlaskit/dropdown-menu'; import { FieldText } from '@atlaskit/field-text'; import ExpandIcon from '@atlaskit/icon/glyph/expand'; import React, { Component } from 'react'; import { connect } from 'react-redux'; import { translate } from '../../base/i18n'; import { getLocalParticipant } from '../../base/participants'; import { updateDialInNumbers } from '../actions'; const logger = require('jitsi-meet-logger').getLogger(__filename); /** * React {@code Component} responsible for fetching and displaying telephone * numbers for dialing into a conference. Also supports copying a selected * dial-in number to the clipboard. * * @extends Component */ class DialInNumbersForm extends Component { /** * {@code DialInNumbersForm}'s property types. * * @static */ static propTypes = { /** * The redux state representing the dial-in numbers feature. */ _dialIn: React.PropTypes.object, /** * The display name of the local user. */ _localUserDisplayName: React.PropTypes.string, /** * Invoked to send an ajax request for dial-in numbers. */ dispatch: React.PropTypes.func, /** * The URL of the conference into which this {@code DialInNumbersForm} * is inviting the local participant. */ inviteURL: React.PropTypes.string, /** * Invoked to obtain translated strings. */ t: React.PropTypes.func }; /** * Initializes a new {@code DialInNumbersForm} instance. * * @param {Object} props - The read-only properties with which the new * instance is to be initialized. */ constructor(props) { super(props); this.state = { /** * Whether or not the dropdown should be open. * * @type {boolean} */ isDropdownOpen: false, /** * The dial-in number to display as currently selected in the * dropdown. The value should be an object which has two key/value * pairs, content and number. The value of "content" will display in * the dropdown while the value of "number" is a substring of * "content" which will be copied to clipboard. * * @type {object} */ selectedNumber: null }; /** * The internal reference to the DOM/HTML element backing the React * {@code Component} text area. It is necessary for the implementation * of copying to the clipboard. * * @private * @type {HTMLTextAreaElement} */ this._copyElement = null; // Bind event handlers so they are only bound once for every instance. this._onCopyClick = this._onCopyClick.bind(this); this._onDropdownTriggerInputChange = this._onDropdownTriggerInputChange.bind(this); this._onOpenChange = this._onOpenChange.bind(this); this._onSelect = this._onSelect.bind(this); this._setCopyElement = this._setCopyElement.bind(this); } /** * Sets a default number to display in the dropdown trigger. * * @inheritdoc * returns {void} */ componentWillMount() { const { numbers } = this.props._dialIn; if (numbers) { this._setDefaultNumber(numbers); } else { this.props.dispatch(updateDialInNumbers()); } } /** * Monitors for number updates and sets a default number to display in the * dropdown trigger if not already set. * * @inheritdoc * returns {void} */ componentWillReceiveProps(nextProps) { if (!this.state.selectedNumber && nextProps._dialIn.numbers) { this._setDefaultNumber(nextProps._dialIn.numbers); } } /** * Implements React's {@link Component#render()}. Returns null if the * component is not ready for display. * * @inheritdoc * @returns {ReactElement|null} */ render() { const { _dialIn, t } = this.props; const { conferenceID, numbers, numbersEnabled } = _dialIn; const { selectedNumber } = this.state; if (!conferenceID || !numbers || !numbersEnabled || !selectedNumber) { return null; } const items = this._formatNumbers(numbers); return (
{ this._createDropdownMenu(items, selectedNumber.content) }