2016-03-04 02:57:33 +05:30
|
|
|
import React, { Component, PropTypes } from 'react';
|
|
|
|
|
2016-03-15 11:10:18 +05:30
|
|
|
import { connect } from 'react-redux';
|
2016-03-04 02:57:33 +05:30
|
|
|
import { FormattedMessage as Message } from 'react-intl';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
|
|
|
import buttons from 'components/ui/buttons.scss';
|
|
|
|
|
|
|
|
import messages from './Finish.messages';
|
|
|
|
import styles from './finish.scss';
|
|
|
|
|
2016-03-15 11:10:18 +05:30
|
|
|
class Finish extends Component {
|
|
|
|
static displayName = 'Finish';
|
2016-03-04 02:57:33 +05:30
|
|
|
|
2016-03-15 11:10:18 +05:30
|
|
|
static propTypes = {
|
|
|
|
appName: PropTypes.string.isRequired,
|
|
|
|
code: PropTypes.string.isRequired,
|
|
|
|
displayCode: PropTypes.bool,
|
|
|
|
success: PropTypes.bool
|
2016-03-04 02:57:33 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
2016-03-15 11:10:18 +05:30
|
|
|
isCopySupported: document.queryCommandSupported && document.queryCommandSupported('copy')
|
2016-03-04 02:57:33 +05:30
|
|
|
};
|
|
|
|
|
2016-03-15 11:10:18 +05:30
|
|
|
handleCopyClick = (event) => {
|
|
|
|
event.preventDefault();
|
2016-03-04 02:57:33 +05:30
|
|
|
// http://stackoverflow.com/a/987376/5184751
|
2016-03-15 11:10:18 +05:30
|
|
|
|
|
|
|
try {
|
|
|
|
const selection = window.getSelection();
|
|
|
|
const range = document.createRange();
|
|
|
|
range.selectNodeContents(this.code);
|
2016-03-04 02:57:33 +05:30
|
|
|
selection.removeAllRanges();
|
|
|
|
selection.addRange(range);
|
|
|
|
|
2016-03-15 11:10:18 +05:30
|
|
|
const successful = document.execCommand('copy');
|
|
|
|
selection.removeAllRanges();
|
|
|
|
|
2016-03-04 02:57:33 +05:30
|
|
|
// TODO: было бы ещё неплохо сделать какую-то анимацию, вроде "Скопировано",
|
|
|
|
// ибо сейчас после клика как-то неубедительно, скопировалось оно или нет
|
|
|
|
console.log('Copying text command was ' + (successful ? 'successful' : 'unsuccessful'));
|
2016-03-15 11:10:18 +05:30
|
|
|
} catch (err) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
setCode = (el) => {
|
|
|
|
this.code = el;
|
|
|
|
};
|
2016-03-04 02:57:33 +05:30
|
|
|
|
|
|
|
render() {
|
2016-03-15 11:10:18 +05:30
|
|
|
const {appName, code, displayCode, success} = this.props;
|
|
|
|
const {isCopySupported} = this.state;
|
2016-03-04 02:57:33 +05:30
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.finishPage}>
|
|
|
|
{success ? (
|
|
|
|
<div>
|
|
|
|
<div className={styles.successBackground}></div>
|
|
|
|
<div className={styles.greenTitle}>
|
|
|
|
<Message {...messages.authForAppSuccessful} values={{
|
|
|
|
appName: (<span className={styles.appName}>{appName}</span>)
|
|
|
|
}} />
|
|
|
|
</div>
|
2016-03-15 11:10:18 +05:30
|
|
|
{displayCode ? (
|
2016-03-04 02:57:33 +05:30
|
|
|
<div>
|
|
|
|
<div className={styles.description}>
|
|
|
|
<Message {...messages.passCodeToApp} values={{appName}} />
|
|
|
|
</div>
|
2016-03-15 11:10:18 +05:30
|
|
|
<div className={styles.codeContainer}>
|
|
|
|
<div className={styles.code} ref={this.setCode}>{code}</div>
|
|
|
|
</div>
|
|
|
|
{isCopySupported ? (
|
|
|
|
<button
|
2016-03-04 02:57:33 +05:30
|
|
|
className={classNames(buttons.smallButton, buttons.green)}
|
2016-03-15 11:10:18 +05:30
|
|
|
onClick={this.handleCopyClick}
|
2016-03-04 02:57:33 +05:30
|
|
|
>
|
|
|
|
<Message {...messages.copy} />
|
2016-03-15 11:10:18 +05:30
|
|
|
</button>
|
2016-03-04 02:57:33 +05:30
|
|
|
) : (
|
|
|
|
''
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className={styles.description}>
|
|
|
|
<Message {...messages.waitAppReaction} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div>
|
|
|
|
<div className={styles.failBackground}></div>
|
|
|
|
<div className={styles.redTitle}>
|
|
|
|
<Message {...messages.authForAppFailed} values={{
|
|
|
|
appName: (<span className={styles.appName}>{appName}</span>)
|
|
|
|
}} />
|
|
|
|
</div>
|
|
|
|
<div className={styles.description}>
|
|
|
|
<Message {...messages.waitAppReaction} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-03-15 11:10:18 +05:30
|
|
|
|
2016-03-15 12:06:13 +05:30
|
|
|
export default connect(({auth}) => ({
|
|
|
|
appName: auth.client.name,
|
|
|
|
code: auth.oauth.code,
|
|
|
|
displayCode: auth.oauth.displayCode,
|
|
|
|
success: auth.oauth.success
|
2016-03-15 11:10:18 +05:30
|
|
|
}))(Finish);
|