2018-03-30 02:43:47 +02:00
|
|
|
// @flow
|
2017-12-21 22:08:54 +01:00
|
|
|
import React from 'react';
|
2019-06-17 22:32:38 +02:00
|
|
|
import UserEmail from 'component/userEmail';
|
2017-12-21 22:08:54 +01:00
|
|
|
import UserVerify from 'component/userVerify';
|
2018-03-26 23:32:43 +02:00
|
|
|
import Page from 'component/page';
|
2017-07-19 01:00:13 +02:00
|
|
|
|
2018-03-30 02:43:47 +02:00
|
|
|
type Props = {
|
|
|
|
isPending: boolean,
|
|
|
|
email: string,
|
2019-03-29 15:23:32 +01:00
|
|
|
location: UrlLocation,
|
2019-04-04 23:05:23 +02:00
|
|
|
history: { push: string => void },
|
2018-03-30 02:43:47 +02:00
|
|
|
user: ?{
|
|
|
|
has_verified_email: boolean,
|
|
|
|
is_reward_approved: boolean,
|
|
|
|
is_identity_verified: boolean,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-09-24 05:44:42 +02:00
|
|
|
class AuthPage extends React.PureComponent<Props> {
|
2019-06-17 22:32:38 +02:00
|
|
|
componentDidMount() {
|
2017-07-19 01:00:13 +02:00
|
|
|
this.navigateIfAuthenticated(this.props);
|
|
|
|
}
|
|
|
|
|
2019-06-17 22:32:38 +02:00
|
|
|
componentDidUpdate() {
|
|
|
|
this.navigateIfAuthenticated(this.props);
|
2017-07-19 01:00:13 +02:00
|
|
|
}
|
|
|
|
|
2018-03-30 02:43:47 +02:00
|
|
|
navigateIfAuthenticated = (props: Props) => {
|
2019-04-04 23:05:23 +02:00
|
|
|
const { isPending, user, location, history } = props;
|
2019-05-07 23:38:29 +02:00
|
|
|
if (!isPending && user && user.has_verified_email && (user.is_reward_approved || user.is_identity_verified)) {
|
2019-03-29 15:23:32 +01:00
|
|
|
const { search } = location;
|
|
|
|
const urlParams = new URLSearchParams(search);
|
|
|
|
const redirectTo = urlParams.get('redirect');
|
|
|
|
const path = redirectTo ? `/$/${redirectTo}` : '/';
|
2019-04-04 23:05:23 +02:00
|
|
|
history.push(path);
|
2018-03-30 02:43:47 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-07-19 01:00:13 +02:00
|
|
|
render() {
|
2019-06-17 22:32:38 +02:00
|
|
|
const { user, email } = this.props;
|
2019-07-08 18:51:53 +02:00
|
|
|
return <Page>{user && email && user.has_verified_email ? <UserVerify /> : <UserEmail />}</Page>;
|
2017-07-19 01:00:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AuthPage;
|