2020-01-17 23:37:52 +03:00
|
|
|
import React, { MouseEventHandler } from 'react';
|
2016-03-15 07:40:18 +02:00
|
|
|
import { connect } from 'react-redux';
|
2016-03-04 00:27:33 +03:00
|
|
|
import { FormattedMessage as Message } from 'react-intl';
|
2019-12-30 09:29:39 +02:00
|
|
|
import { Helmet } from 'react-helmet-async';
|
2019-12-07 21:02:00 +02:00
|
|
|
import { Button } from 'app/components/ui/form';
|
|
|
|
import copy from 'app/services/copy';
|
|
|
|
import { RootState } from 'app/reducers';
|
2016-03-04 00:27:33 +03:00
|
|
|
|
2016-05-14 14:26:17 +03:00
|
|
|
import messages from './Finish.intl.json';
|
2016-03-04 00:27:33 +03:00
|
|
|
import styles from './finish.scss';
|
|
|
|
|
2019-12-07 13:28:52 +02:00
|
|
|
interface Props {
|
|
|
|
appName: string;
|
|
|
|
code?: string;
|
|
|
|
state: string;
|
2020-01-17 23:37:52 +03:00
|
|
|
displayCode?: boolean;
|
2019-12-07 13:28:52 +02:00
|
|
|
success?: boolean;
|
|
|
|
}
|
2016-03-04 00:27:33 +03:00
|
|
|
|
2019-12-07 13:28:52 +02:00
|
|
|
class Finish extends React.Component<Props> {
|
2019-11-27 11:03:32 +02:00
|
|
|
render() {
|
|
|
|
const { appName, code, state, displayCode, success } = this.props;
|
|
|
|
const authData = JSON.stringify({
|
2019-12-07 13:28:52 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/camelcase
|
|
|
|
auth_code: code,
|
2019-11-27 11:03:32 +02:00
|
|
|
state,
|
|
|
|
});
|
2016-03-16 06:46:44 +02:00
|
|
|
|
2019-12-07 13:28:52 +02:00
|
|
|
history.pushState(null, document.title, `#${authData}`);
|
2016-03-04 00:27:33 +03:00
|
|
|
|
2019-11-27 11:03:32 +02:00
|
|
|
return (
|
|
|
|
<div className={styles.finishPage}>
|
|
|
|
<Helmet title={authData} />
|
2016-03-16 06:46:44 +02:00
|
|
|
|
2019-11-27 11:03:32 +02:00
|
|
|
{success ? (
|
|
|
|
<div>
|
|
|
|
<div className={styles.successBackground} />
|
|
|
|
<div className={styles.greenTitle}>
|
|
|
|
<Message
|
|
|
|
{...messages.authForAppSuccessful}
|
|
|
|
values={{
|
|
|
|
appName: <span className={styles.appName}>{appName}</span>,
|
|
|
|
}}
|
|
|
|
/>
|
2016-03-04 00:27:33 +03:00
|
|
|
</div>
|
2019-11-27 11:03:32 +02:00
|
|
|
{displayCode ? (
|
2019-12-26 14:18:58 +02:00
|
|
|
<div data-testid="oauth-code-container">
|
2019-11-27 11:03:32 +02:00
|
|
|
<div className={styles.description}>
|
|
|
|
<Message {...messages.passCodeToApp} values={{ appName }} />
|
|
|
|
</div>
|
|
|
|
<div className={styles.codeContainer}>
|
|
|
|
<div className={styles.code}>{code}</div>
|
|
|
|
</div>
|
|
|
|
<Button
|
|
|
|
color="green"
|
|
|
|
small
|
|
|
|
label={messages.copy}
|
|
|
|
onClick={this.onCopyClick}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className={styles.description}>
|
|
|
|
<Message {...messages.waitAppReaction} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div>
|
|
|
|
<div className={styles.failBackground} />
|
|
|
|
<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-16 06:46:44 +02:00
|
|
|
|
2020-05-20 19:35:52 +03:00
|
|
|
onCopyClick: MouseEventHandler = (event) => {
|
2019-11-27 11:03:32 +02:00
|
|
|
event.preventDefault();
|
2019-12-07 13:28:52 +02:00
|
|
|
|
|
|
|
const { code } = this.props;
|
|
|
|
|
|
|
|
if (code) {
|
|
|
|
copy(code);
|
|
|
|
}
|
2019-11-27 11:03:32 +02:00
|
|
|
};
|
2016-03-04 00:27:33 +03:00
|
|
|
}
|
2016-03-15 07:40:18 +02:00
|
|
|
|
2019-12-07 13:28:52 +02:00
|
|
|
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);
|