2018-04-17 00:44:57 +02:00
// @flow
2019-11-22 22:13:00 +01:00
import * as PAGES from 'constants/pages' ;
import React , { PureComponent } from 'react' ;
2018-03-26 23:32:43 +02:00
import BusyIndicator from 'component/common/busy-indicator' ;
2017-12-21 22:08:54 +01:00
import RewardListClaimed from 'component/rewardListClaimed' ;
import RewardTile from 'component/rewardTile' ;
2018-03-26 23:32:43 +02:00
import Button from 'component/button' ;
import Page from 'component/page' ;
import classnames from 'classnames' ;
2020-06-15 22:33:03 +02:00
import REWARD _TYPES from 'rewards' ;
2019-11-13 19:14:19 +01:00
import RewardAuthIntro from 'component/rewardAuthIntro' ;
2019-11-22 22:13:00 +01:00
import Card from 'component/common/card' ;
2019-12-19 18:33:33 +01:00
import I18nMessage from 'component/i18nMessage' ;
2017-05-26 10:53:32 +02:00
2018-04-17 00:44:57 +02:00
type Props = {
doAuth : ( ) => void ,
2019-09-19 20:45:48 +02:00
fetchRewards : ( ) => void ,
2019-10-14 22:18:16 +02:00
fetchUser : ( ) => void ,
2018-04-17 00:44:57 +02:00
fetching : boolean ,
2018-07-11 04:54:50 +02:00
rewards : Array < Reward > ,
claimed : Array < Reward > ,
2018-04-17 00:44:57 +02:00
user : ? {
is _identity _verified : boolean ,
2018-05-15 18:19:29 +02:00
is _reward _approved : boolean ,
primary _email : string ,
has _verified _email : boolean ,
2018-04-17 00:44:57 +02:00
} ,
daemonSettings : {
share _usage _data : boolean ,
} ,
} ;
2018-12-14 06:59:04 +01:00
class RewardsPage extends PureComponent < Props > {
2019-09-19 20:45:48 +02:00
componentDidMount ( ) {
2020-07-03 19:16:54 +02:00
const { user , fetchUser , fetchRewards } = this . props ;
const rewardsApproved = user && user . is _reward _approved ;
fetchRewards ( ) ;
if ( ! rewardsApproved ) {
fetchUser ( ) ;
}
2019-09-19 20:45:48 +02:00
}
2020-07-03 19:16:54 +02:00
2017-08-19 05:08:01 +02:00
renderPageHeader ( ) {
2019-10-14 22:18:16 +02:00
const { user , daemonSettings , fetchUser } = this . props ;
2019-10-23 20:59:33 +02:00
const rewardsEnabled = IS _WEB || ( daemonSettings && daemonSettings . share _usage _data ) ;
2017-06-23 07:29:40 +02:00
2019-10-23 20:59:33 +02:00
if ( user && ! user . is _reward _approved && rewardsEnabled ) {
2017-12-21 22:08:54 +01:00
if ( ! user . primary _email || ! user . has _verified _email || ! user . is _identity _verified ) {
2020-06-01 19:03:19 +02:00
return (
< div className = "section" >
< RewardAuthIntro / >
< / div >
) ;
2017-07-25 20:34:28 +02:00
}
2020-03-16 16:56:24 +01:00
2017-12-21 22:08:54 +01:00
return (
2020-03-16 16:56:24 +01:00
< Card
2020-06-01 19:03:19 +02:00
className = "section"
2020-08-26 22:28:33 +02:00
title = { _ _ ( 'Reward validation pending' ) }
2020-03-16 16:56:24 +01:00
body = {
< React.Fragment >
< p >
2020-05-22 03:19:01 +02:00
{ _ _ (
'This account must undergo review before you can participate in the rewards program. Not all users and regions may qualify.'
) } { ' ' }
{ _ _ ( 'This can take anywhere from a few hours to several days. Please be patient.' ) }
2020-03-16 16:56:24 +01:00
< / p >
2017-12-21 22:08:54 +01:00
2020-03-16 16:56:24 +01:00
< p >
2020-05-22 03:19:01 +02:00
{ _ _ (
2021-04-02 22:17:50 +02:00
'We apologize for this inconvenience, but have added this additional step to prevent abuse. Users on VPN or shared connections will continue to see this message and are not eligible for Rewards.'
2020-05-22 03:19:01 +02:00
) }
< / p >
< p >
< I18nMessage
tokens = { {
rewards _faq : < Button button = "link" label = { _ _ ( 'Rewards FAQ' ) } href = "https://lbry.com/faq/support" / > ,
} }
>
Please review the % rewards _faq % for eligibility , and send us an email to help @ lbry . com if you continue
to see this message . You can continue to use LBRY without this feature .
< / I18nMessage >
{ ` ${ _ _ ( 'Enjoy all the awesome free content in the meantime!' ) } ` }
2020-03-16 16:56:24 +01:00
< / p >
< / React.Fragment >
}
actions = {
< div className = "section__actions" >
< Button navigate = "/" button = "primary" label = "Return Home" / >
< Button onClick = { ( ) => fetchUser ( ) } button = "link" label = "Refresh" / >
< / div >
}
/ >
2017-12-21 22:08:54 +01:00
) ;
2017-08-19 05:08:01 +02:00
}
2018-04-17 00:44:57 +02:00
return null ;
2017-08-19 05:08:01 +02:00
}
2018-12-14 06:59:04 +01:00
renderCustomRewardCode ( ) {
return (
< RewardTile
key = { REWARD _TYPES . TYPE _GENERATED _CODE }
reward = { {
reward _type : REWARD _TYPES . TYPE _GENERATED _CODE ,
reward _title : _ _ ( 'Custom Code' ) ,
2019-05-07 23:38:29 +02:00
reward _description : _ _ ( 'Are you a supermodel or rockstar that received a custom reward code? Claim it here.' ) ,
2018-12-14 06:59:04 +01:00
} }
/ >
) ;
}
2017-08-19 05:08:01 +02:00
renderUnclaimedRewards ( ) {
2019-03-28 17:53:13 +01:00
const { fetching , rewards , user , daemonSettings , claimed } = this . props ;
2017-08-19 05:08:01 +02:00
2019-09-26 18:07:11 +02:00
if ( ! IS _WEB && daemonSettings && ! daemonSettings . share _usage _data ) {
2018-03-16 21:55:56 +01:00
return (
2018-12-19 06:44:53 +01:00
< section className = "card card--section" >
2019-12-19 18:33:33 +01:00
< h2 className = "card__title card__title--deprecated" > { _ _ ( 'Rewards Disabled' ) } < / h2 >
2020-04-13 21:16:07 +02:00
< p className = "error__text" >
2019-12-19 18:33:33 +01:00
< I18nMessage tokens = { { settings : < Button button = "link" navigate = "/$/settings" label = "Settings" / > } } >
Rewards are currently disabled for your account . Turn on diagnostic data sharing , in % settings % , to
re - enable them .
< / I18nMessage >
2019-07-21 23:31:22 +02:00
< / p >
2018-12-19 06:44:53 +01:00
< / section >
2018-03-16 21:55:56 +01:00
) ;
} else if ( fetching ) {
2019-07-21 23:31:22 +02:00
return < BusyIndicator message = { _ _ ( 'Fetching rewards' ) } / > ;
2017-08-03 00:55:58 +02:00
} else if ( user === null ) {
2017-08-19 05:08:01 +02:00
return (
2019-07-21 23:31:22 +02:00
< p className = "help" > { _ _ ( 'This application is unable to earn rewards due to an authentication failure.' ) } < / p >
2017-06-23 07:29:40 +02:00
) ;
2017-08-19 05:08:01 +02:00
} else if ( ! rewards || rewards . length <= 0 ) {
return (
2019-11-22 22:13:00 +01:00
< Card
2020-08-26 22:28:33 +02:00
title = { _ _ ( 'No rewards available' ) }
2019-11-22 22:13:00 +01:00
subtitle = {
claimed && claimed . length
? _ _ (
"You have claimed all available rewards! We're regularly adding more so be sure to check back later."
)
: _ _ ( 'There are no rewards available at this time, please check back later.' )
}
actions = { < Button button = "primary" navigate = { ` / $ / ${ PAGES . DISCOVER } ` } label = { _ _ ( 'Go Home' ) } / > }
/ >
2017-08-19 05:08:01 +02:00
) ;
2017-06-23 07:29:40 +02:00
}
2018-03-26 23:32:43 +02:00
2019-05-07 23:38:29 +02:00
const isNotEligible = ! user || ! user . primary _email || ! user . has _verified _email || ! user . is _reward _approved ;
2018-12-19 06:44:53 +01:00
2017-12-21 22:08:54 +01:00
return (
2018-03-26 23:32:43 +02:00
< div
2019-06-17 22:32:38 +02:00
className = { classnames ( 'card__list' , {
2018-03-26 23:32:43 +02:00
'card--disabled' : isNotEligible ,
} ) }
>
2021-04-02 22:17:50 +02:00
{ rewards . map ( ( reward ) => (
2019-03-05 05:46:57 +01:00
< RewardTile key = { reward . claim _code } reward = { reward } / >
) ) }
2018-12-14 06:59:04 +01:00
{ this . renderCustomRewardCode ( ) }
2017-12-21 22:08:54 +01:00
< / div >
) ;
2017-08-19 05:08:01 +02:00
}
2017-06-23 07:29:40 +02:00
2017-08-19 05:08:01 +02:00
render ( ) {
2017-06-23 07:29:40 +02:00
return (
2018-03-26 23:32:43 +02:00
< Page >
2017-08-19 05:08:01 +02:00
{ this . renderPageHeader ( ) }
2020-06-01 19:03:19 +02:00
< div className = "section" > { this . renderUnclaimedRewards ( ) } < / div >
2020-09-02 22:08:37 +02:00
< RewardListClaimed / >
2018-03-26 23:32:43 +02:00
< / Page >
2017-06-23 07:29:40 +02:00
) ;
}
}
2017-05-26 10:53:32 +02:00
export default RewardsPage ;