lbry-desktop/src/ui/page/rewards/view.jsx

168 lines
5.5 KiB
React
Raw Normal View History

// @flow
import React, { PureComponent, Fragment } from 'react';
2018-03-26 23:32:43 +02:00
import BusyIndicator from 'component/common/busy-indicator';
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';
2018-09-26 02:12:07 +02:00
import { rewards as REWARD_TYPES } from 'lbryinc';
import UnsupportedOnWeb from 'component/common/unsupported-on-web';
2017-05-26 10:53:32 +02:00
type Props = {
doAuth: () => void,
fetching: boolean,
2018-07-11 04:54:50 +02:00
rewards: Array<Reward>,
claimed: Array<Reward>,
user: ?{
is_identity_verified: boolean,
is_reward_approved: boolean,
primary_email: string,
has_verified_email: boolean,
},
daemonSettings: {
share_usage_data: boolean,
},
};
class RewardsPage extends PureComponent<Props> {
renderPageHeader() {
2019-04-04 23:05:23 +02:00
const { user, daemonSettings } = this.props;
2017-06-23 07:29:40 +02:00
2018-06-05 17:22:15 +02:00
if (user && !user.is_reward_approved && daemonSettings && daemonSettings.share_usage_data) {
if (!user.primary_email || !user.has_verified_email || !user.is_identity_verified) {
return (
!IS_WEB && (
<section className="card card--section">
<header className="card__header">
<h2 className="card__title">{__('Rewards Approval to Earn Credits (LBC)')}</h2>
<p className="card__subtitle">
{__(
2019-07-17 20:04:50 +02:00
'This step is optional. You can continue to use this app without rewards, but LBC may be needed for some tasks.'
)}{' '}
2019-07-17 20:04:50 +02:00
<Button button="link" label={__('Learn more')} href="https://lbry.com/faq/rewards" />
</p>
</header>
<div className="card__content">
2019-05-07 23:38:29 +02:00
<Button navigate="/$/auth?redirect=rewards" button="primary" label="Prove Humanity" />
</div>
</section>
)
);
}
return (
2019-01-08 20:16:07 +01:00
<section className="card card--section">
2019-04-19 21:28:43 +02:00
<div className="card__content">
<p>
2019-05-07 23:38:29 +02:00
{__('This account must undergo review before you can participate in the rewards program.')}{' '}
2019-04-19 21:28:43 +02:00
{__('This can take anywhere from several minutes to several days.')}
</p>
2019-05-07 23:38:29 +02:00
<p>{__('We apologize for this inconvenience, but have added this additional step to prevent fraud.')}</p>
2019-04-19 21:28:43 +02:00
<p>
2019-05-07 23:38:29 +02:00
{`${__('If you continue to see this message, send us an email to help@lbry.com.')} ${__(
'Please enjoy free content in the meantime!'
)}`}
2019-04-19 21:28:43 +02:00
</p>
</div>
<div className="card__actions">
2019-03-28 17:53:13 +01:00
<Button navigate="/" button="primary" label="Return Home" />
2019-04-19 21:28:43 +02:00
</div>
2019-01-08 20:16:07 +01:00
</section>
);
}
return null;
}
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.'),
}}
/>
);
}
renderUnclaimedRewards() {
2019-03-28 17:53:13 +01:00
const { fetching, rewards, user, daemonSettings, claimed } = this.props;
2018-06-05 17:22:15 +02:00
if (daemonSettings && !daemonSettings.share_usage_data) {
return (
<section className="card card--section">
<header className="card__header">
<h2 className="card__title">{__('Disabled')}</h2>
2019-01-08 20:16:07 +01:00
<p className="card__subtitle">
2019-05-07 23:38:29 +02:00
{__('Rewards are currently disabled for your account. Turn on diagnostic data sharing, in')}{' '}
2019-03-28 17:53:13 +01:00
<Button button="link" navigate="/$/settings" label="Settings" />
{__(', in order to re-enable them.')}
</p>
2019-01-08 20:16:07 +01:00
</header>
</section>
);
} else if (fetching) {
return (
<div className="card__content">
2018-03-26 23:32:43 +02:00
<BusyIndicator message={__('Fetching rewards')} />
</div>
);
2017-08-03 00:55:58 +02:00
} else if (user === null) {
return (
2019-01-08 20:16:07 +01:00
<section className="card card--section">
2019-05-07 23:38:29 +02:00
<p>{__('This application is unable to earn rewards due to an authentication failure.')}</p>
2019-01-08 20:16:07 +01:00
</section>
2017-06-23 07:29:40 +02:00
);
} else if (!rewards || rewards.length <= 0) {
return (
<Fragment>
2019-01-08 20:16:07 +01:00
<section className="card card--section">
<h2 className="card__title">{__('No Rewards Available')}</h2>
<p className="card__content">
{claimed && claimed.length
? __(
2019-05-07 23:38:29 +02:00
"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.')}
</p>
2019-01-08 20:16:07 +01:00
</section>
2019-06-17 22:32:38 +02:00
<div className="card__list">{this.renderCustomRewardCode()}</div>
</Fragment>
);
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;
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,
})}
>
2019-03-05 05:46:57 +01:00
{rewards.map(reward => (
<RewardTile key={reward.claim_code} reward={reward} />
))}
{this.renderCustomRewardCode()}
</div>
);
}
2017-06-23 07:29:40 +02:00
render() {
2017-06-23 07:29:40 +02:00
return (
2018-03-26 23:32:43 +02:00
<Page>
{IS_WEB && <UnsupportedOnWeb />}
{this.renderPageHeader()}
{this.renderUnclaimedRewards()}
{<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;