lbry-desktop/src/renderer/page/auth/view.jsx

107 lines
3.2 KiB
React
Raw Normal View History

2018-03-30 02:43:47 +02:00
// @flow
import React from 'react';
2018-03-26 23:32:43 +02:00
import BusyIndicator from 'component/common/busy-indicator';
import Button from 'component/button';
import UserEmailNew from 'component/userEmailNew';
import UserEmailVerify from 'component/userEmailVerify';
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,
// Not sure why it isn't recognizing that we are using this prop type
// Something to do with how we are passing all the props through probably
pathAfterAuth: string, // eslint-disable-line react/no-unused-prop-types
user: ?{
has_verified_email: boolean,
is_reward_approved: boolean,
is_identity_verified: boolean,
},
navigate: (string, ?{}) => void,
};
export class AuthPage extends React.PureComponent<Props> {
2017-07-19 01:00:13 +02:00
componentWillMount() {
this.navigateIfAuthenticated(this.props);
}
2018-03-30 02:43:47 +02:00
componentWillReceiveProps(nextProps: Props) {
2017-07-19 01:00:13 +02:00
this.navigateIfAuthenticated(nextProps);
}
getTitle() {
2018-03-30 02:43:47 +02:00
const { email, isPending, user } = this.props;
2017-07-19 01:00:13 +02:00
if (isPending || (user && !user.has_verified_email && !email)) {
return __('Human Proofing');
2017-07-19 01:00:13 +02:00
} else if (user && !user.has_verified_email) {
return __('Confirm Email');
} else if (user && !user.is_identity_verified && !user.is_reward_approved) {
return __('Final Verification');
2017-07-19 01:00:13 +02:00
}
return __('Welcome to LBRY');
2017-07-19 01:00:13 +02:00
}
2018-03-30 02:43:47 +02:00
navigateIfAuthenticated = (props: Props) => {
const { isPending, user, pathAfterAuth, navigate } = props;
if (
!isPending &&
user &&
user.has_verified_email &&
(user.is_reward_approved || user.is_identity_verified)
) {
navigate(pathAfterAuth);
}
};
2017-07-19 01:00:13 +02:00
renderMain() {
2018-03-30 02:43:47 +02:00
const { email, isPending, user } = this.props;
2017-07-19 01:00:13 +02:00
if (isPending) {
2018-03-26 23:32:43 +02:00
return [<BusyIndicator message={__('Authenticating')} />, true];
2017-07-19 01:00:13 +02:00
} else if (user && !user.has_verified_email && !email) {
2017-08-26 05:21:26 +02:00
return [<UserEmailNew />, true];
2017-07-19 01:00:13 +02:00
} else if (user && !user.has_verified_email) {
2017-08-26 05:21:26 +02:00
return [<UserEmailVerify />, true];
2017-07-19 01:00:13 +02:00
} else if (user && !user.is_identity_verified) {
2017-08-26 05:21:26 +02:00
return [<UserVerify />, false];
2017-07-19 01:00:13 +02:00
}
return [<span className="empty">{__('No further steps.')}</span>, true];
2017-07-19 01:00:13 +02:00
}
render() {
2018-03-30 02:43:47 +02:00
const { navigate } = this.props;
2017-08-26 05:21:26 +02:00
const [innerContent, useTemplate] = this.renderMain();
2017-07-19 01:00:13 +02:00
2018-03-26 23:32:43 +02:00
return (
<Page>
{useTemplate ? (
<section className="card card--section">
<div className="card__title">
<h1>{this.getTitle()}</h1>
2017-08-26 05:21:26 +02:00
</div>
2018-03-26 23:32:43 +02:00
<div className="card__content">{innerContent}</div>
<div className="card__content">
<div className="help">
{`${__(
'This information is disclosed only to LBRY, Inc. and not to the LBRY network. It is only required to earn LBRY rewards and may be used to sync usage data across devices.'
)} `}
2018-03-30 02:43:47 +02:00
<Button
button="link"
onClick={() => navigate('/discover')}
label={__('Return home.')}
/>
2018-03-26 23:32:43 +02:00
</div>
</div>
</section>
) : (
innerContent
)}
</Page>
2017-11-24 15:31:05 +01:00
);
2017-07-19 01:00:13 +02:00
}
}
export default AuthPage;