2017-08-15 19:30:57 +00:00
|
|
|
import Button from '@atlaskit/button';
|
2017-10-06 16:14:45 +00:00
|
|
|
import { FieldTextStateless as TextField } from '@atlaskit/field-text';
|
2017-09-27 21:23:31 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2017-04-13 00:23:43 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
|
|
|
import { translate } from '../../base/i18n';
|
|
|
|
|
|
|
|
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
|
|
|
|
|
|
|
/**
|
2017-04-18 21:49:52 +00:00
|
|
|
* A React {@code Component} for displaying a value with a copy button to copy
|
|
|
|
* the value into the clipboard.
|
2017-04-13 00:23:43 +00:00
|
|
|
*/
|
|
|
|
class ShareLinkForm extends Component {
|
|
|
|
/**
|
2017-04-18 21:49:52 +00:00
|
|
|
* {@code ShareLinkForm}'s property types.
|
2017-04-13 00:23:43 +00:00
|
|
|
*
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
static propTypes = {
|
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
2017-09-27 21:23:31 +00:00
|
|
|
t: PropTypes.func,
|
2017-04-13 00:23:43 +00:00
|
|
|
|
2017-04-18 21:49:52 +00:00
|
|
|
/**
|
|
|
|
* The value to be displayed and copied into the clipboard.
|
2017-04-13 00:23:43 +00:00
|
|
|
*/
|
2017-09-27 21:23:31 +00:00
|
|
|
toCopy: PropTypes.string
|
2017-06-02 02:01:50 +00:00
|
|
|
};
|
2017-04-13 00:23:43 +00:00
|
|
|
|
|
|
|
/**
|
2017-04-18 21:49:52 +00:00
|
|
|
* Initializes a new {@code ShareLinkForm} instance.
|
2017-04-13 00:23:43 +00:00
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only properties with which the new
|
|
|
|
* instance is to be initialized.
|
|
|
|
*/
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
2017-04-18 21:49:52 +00:00
|
|
|
/**
|
2017-08-15 19:30:57 +00:00
|
|
|
* The internal reference to the React {@code component} for display
|
|
|
|
* the meeting link in an input element.
|
2017-04-18 21:49:52 +00:00
|
|
|
*
|
|
|
|
* @private
|
2017-08-15 19:30:57 +00:00
|
|
|
* @type {ReactComponent}
|
2017-04-18 21:49:52 +00:00
|
|
|
*/
|
2017-08-15 19:30:57 +00:00
|
|
|
this._inputComponent = null;
|
2017-04-13 00:23:43 +00:00
|
|
|
|
2017-04-18 21:49:52 +00:00
|
|
|
// Bind event handlers so they are only bound once for every instance.
|
2017-04-13 00:23:43 +00:00
|
|
|
this._onClick = this._onClick.bind(this);
|
2017-08-15 19:30:57 +00:00
|
|
|
this._onDropdownTriggerInputChange
|
|
|
|
= this._onDropdownTriggerInputChange.bind(this);
|
2017-04-13 00:23:43 +00:00
|
|
|
this._setInput = this._setInput.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
2017-04-18 21:49:52 +00:00
|
|
|
const { t } = this.props;
|
|
|
|
const inputValue = this.props.toCopy || t('inviteUrlDefaultMsg');
|
2017-04-13 00:23:43 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className = 'form-control'>
|
|
|
|
<label className = 'form-control__label'>
|
2017-04-18 21:49:52 +00:00
|
|
|
{ t('dialog.shareLink') }
|
2017-04-13 00:23:43 +00:00
|
|
|
</label>
|
|
|
|
<div className = 'form-control__container'>
|
2017-08-15 19:30:57 +00:00
|
|
|
<div className = 'form-control__input-container'>
|
2017-10-06 16:14:45 +00:00
|
|
|
<TextField
|
2017-08-15 19:30:57 +00:00
|
|
|
id = 'inviteLinkRef'
|
|
|
|
isLabelHidden = { true }
|
|
|
|
isReadOnly = { true }
|
|
|
|
label = 'invite link'
|
|
|
|
onChange = { this._onDropdownTriggerInputChange }
|
|
|
|
ref = { this._setInput }
|
|
|
|
shouldFitContainer = { true }
|
|
|
|
type = 'text'
|
|
|
|
value = { inputValue } />
|
|
|
|
</div>
|
|
|
|
<Button
|
|
|
|
appearance = 'default'
|
2017-04-13 00:23:43 +00:00
|
|
|
onClick = { this._onClick }
|
|
|
|
type = 'button'>
|
2017-04-18 21:49:52 +00:00
|
|
|
{ t('dialog.copy') }
|
2017-08-15 19:30:57 +00:00
|
|
|
</Button>
|
2017-04-13 00:23:43 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies the passed in value to the clipboard.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onClick() {
|
|
|
|
try {
|
2017-08-15 19:30:57 +00:00
|
|
|
const { input } = this._inputComponent;
|
|
|
|
|
|
|
|
input.select();
|
2017-04-13 00:23:43 +00:00
|
|
|
document.execCommand('copy');
|
2017-08-15 19:30:57 +00:00
|
|
|
input.blur();
|
2017-04-13 00:23:43 +00:00
|
|
|
} catch (err) {
|
|
|
|
logger.error('error when copying the text', err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-06 16:14:45 +00:00
|
|
|
* This is a no-op function used to stub out TextField's onChange in order
|
|
|
|
* to prevent TextField from printing prop type validation errors. TextField
|
2017-08-15 19:30:57 +00:00
|
|
|
* is used as a trigger for the dropdown in {@code ShareLinkForm} to get the
|
|
|
|
* desired AtlasKit input look for the UI.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onDropdownTriggerInputChange() {
|
|
|
|
// Intentionally left empty.
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the internal reference to the React Component wrapping the input
|
|
|
|
* with id {@code inviteLinkRef}.
|
2017-04-13 00:23:43 +00:00
|
|
|
*
|
2017-08-15 19:30:57 +00:00
|
|
|
* @param {ReactComponent} inputComponent - React Component for displaying
|
|
|
|
* an input for displaying the meeting link.
|
2017-04-13 00:23:43 +00:00
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2017-08-15 19:30:57 +00:00
|
|
|
_setInput(inputComponent) {
|
|
|
|
this._inputComponent = inputComponent;
|
2017-04-13 00:23:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(ShareLinkForm);
|