2018-03-30 02:43:47 +02:00
// @flow
2017-12-21 22:08:54 +01:00
import React from 'react' ;
2018-03-26 23:32:43 +02:00
import BusyIndicator from 'component/common/busy-indicator' ;
import Button from 'component/button' ;
2017-12-21 22:08:54 +01:00
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' ;
2019-03-28 17:53:13 +01:00
import { navigate } from '@reach/router' ;
2017-07-19 01:00:13 +02:00
2018-03-30 02:43:47 +02:00
type Props = {
isPending : boolean ,
email : string ,
2019-03-18 06:09:50 +01:00
pathAfterAuth : string ,
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 > {
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 ) ;
}
2018-03-30 02:43:47 +02:00
navigateIfAuthenticated = ( props : Props ) => {
2019-03-28 17:53:13 +01:00
const { isPending , user } = props ;
2018-03-30 02:43:47 +02:00
if (
! isPending &&
user &&
user . has _verified _email &&
( user . is _reward _approved || user . is _identity _verified )
) {
2019-03-28 17:53:13 +01:00
navigate ( '/' ) ;
2018-03-30 02:43:47 +02:00
}
} ;
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
}
2019-03-25 07:18:22 +01:00
return [ < span className = "empty" > { _ _ ( 'No further steps.' ) } < / span > , true ] ;
2017-07-19 01:00:13 +02:00
}
render ( ) {
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 ? (
2019-03-25 07:18:22 +01:00
< section className = "card card--section" >
2019-01-22 19:29:45 +01:00
{ innerContent }
2018-12-19 06:44:53 +01:00
2019-03-25 07:18:22 +01:00
< p className = "help" >
2019-01-22 19:29:45 +01:00
{ ` ${ _ _ (
'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.'
) } ` }
2019-03-28 17:53:13 +01:00
< Button button = "link" navigate = "/" label = { _ _ ( 'Return home.' ) } / >
2019-01-22 19:29:45 +01:00
< / p >
2018-03-26 23:32:43 +02:00
< / section >
) : (
innerContent
) }
< / Page >
2017-11-24 15:31:05 +01:00
) ;
2017-07-19 01:00:13 +02:00
}
}
export default AuthPage ;