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