import React, { MouseEventHandler } from 'react'; import { connect } from 'react-redux'; import { defineMessages, FormattedMessage as Message } from 'react-intl'; import { Helmet } from 'react-helmet-async'; import { Button } from 'app/components/ui/form'; import copy from 'app/services/copy'; import { RootState } from 'app/reducers'; import styles from './finish.scss'; const messages = defineMessages({ copy: 'Copy', }); interface Props { appName: string; code?: string; state: string; displayCode?: boolean; success?: boolean; } class Finish extends React.Component { render() { const { appName, code, state, displayCode, success } = this.props; const authData = JSON.stringify({ auth_code: code, state, }); history.pushState(null, document.title, `#${authData}`); return (
{success ? (
{appName}, }} />
{displayCode ? (
{code}
) : (
)}
) : (
{appName}, }} />
)}
); } onCopyClick: MouseEventHandler = (event) => { event.preventDefault(); const { code } = this.props; if (code) { copy(code); } }; } export default connect(({ auth }: RootState) => { if (!auth || !auth.client || !auth.oauth) { throw new Error('Can not connect Finish component. No auth data in state'); } return { appName: auth.client.name, code: auth.oauth.code, displayCode: auth.oauth.displayCode, state: auth.oauth.state, success: auth.oauth.success, }; })(Finish);