diff --git a/src/components/auth/Finish.jsx b/src/components/auth/Finish.jsx index 61e2b5f..4cf2c1d 100644 --- a/src/components/auth/Finish.jsx +++ b/src/components/auth/Finish.jsx @@ -1,58 +1,55 @@ import React, { Component, PropTypes } from 'react'; +import { connect } from 'react-redux'; import { FormattedMessage as Message } from 'react-intl'; -import Helmet from 'react-helmet'; import classNames from 'classnames'; import buttons from 'components/ui/buttons.scss'; -import { Input } from 'components/ui/Form'; -import BaseAuthBody from './BaseAuthBody'; import messages from './Finish.messages'; - import styles from './finish.scss'; -export default class Finish extends Component { - static propTypes = { +class Finish extends Component { + static displayName = 'Finish'; + static propTypes = { + appName: PropTypes.string.isRequired, + code: PropTypes.string.isRequired, + displayCode: PropTypes.bool, + success: PropTypes.bool }; state = { - isSidebarHidden: false + isCopySupported: document.queryCommandSupported && document.queryCommandSupported('copy') }; - handleCopyClick(selector) { + handleCopyClick = (event) => { + event.preventDefault(); // http://stackoverflow.com/a/987376/5184751 - var text = document.querySelector(selector); - var range, selection; - if (document.body.createTextRange) { - range = document.body.createTextRange(); - range.moveToElementText(text); - range.select(); - } else if (window.getSelection) { - selection = window.getSelection(); - range = document.createRange(); - range.selectNodeContents(text); - selection.removeAllRanges(); - selection.addRange(range); - } try { - var successful = document.execCommand('copy'); + const selection = window.getSelection(); + const range = document.createRange(); + range.selectNodeContents(this.code); + selection.removeAllRanges(); + selection.addRange(range); + + const successful = document.execCommand('copy'); + selection.removeAllRanges(); + // TODO: было бы ещё неплохо сделать какую-то анимацию, вроде "Скопировано", // ибо сейчас после клика как-то неубедительно, скопировалось оно или нет console.log('Copying text command was ' + (successful ? 'successful' : 'unsuccessful')); - } catch (err) { - console.error('Oops, unable to copy'); - } - } + } catch (err) {} + }; + + setCode = (el) => { + this.code = el; + }; render() { - const withCode = true; - const success = true; - const appName = 'TLauncher'; - const code = 'HW9vkZA6Y4vRN3ciSm1IIDk98PHLkPPlv3jvo1MX'; - const copySupported = document.queryCommandSupported('copy'); + const {appName, code, displayCode, success} = this.props; + const {isCopySupported} = this.state; return (
@@ -64,19 +61,21 @@ export default class Finish extends Component { appName: ({appName}) }} />
- {withCode ? ( + {displayCode ? (
-
{code}
- {copySupported ? ( -
+
{code}
+
+ {isCopySupported ? ( +
+ ) : ( '' )} @@ -104,3 +103,10 @@ export default class Finish extends Component { ); } } + +export default connect((state) => ({ + appName: state.auth.client ? state.auth.client.name : 'Undefined', + code: 'HW9vkZA6Y4vRN3ciSm1IIDk98PHLkPPlv3jvo1MX', + displayCode: true, + success: true +}))(Finish); diff --git a/src/components/auth/PanelTransition.jsx b/src/components/auth/PanelTransition.jsx index 54a3b67..ab15178 100644 --- a/src/components/auth/PanelTransition.jsx +++ b/src/components/auth/PanelTransition.jsx @@ -38,10 +38,11 @@ class PanelTransition extends Component { // local props path: PropTypes.string.isRequired, - Title: PropTypes.element.isRequired, - Body: PropTypes.element.isRequired, - Footer: PropTypes.element.isRequired, - Links: PropTypes.element.isRequired + Title: PropTypes.element, + Body: PropTypes.element, + Footer: PropTypes.element, + Links: PropTypes.element, + children: PropTypes.element }; static childContextTypes = { @@ -101,6 +102,12 @@ class PanelTransition extends Component { const {path, Title, Body, Footer, Links} = this.props; + if (this.props.children) { + return this.props.children; + } else if (!Title || !Body || !Footer || !Links) { + throw new Error('Title, Body, Footer and Links are required'); + } + return (
- +
); diff --git a/src/routes.js b/src/routes.js index 8e976c9..78a5347 100644 --- a/src/routes.js +++ b/src/routes.js @@ -46,9 +46,9 @@ export default function routesFactory(store) { + - );