2017-06-08 02:56:52 +02:00
|
|
|
import React from "react";
|
2017-08-19 05:08:01 +02:00
|
|
|
import { BusyMessage } from "component/common";
|
|
|
|
import RewardListClaimed from "component/rewardListClaimed";
|
|
|
|
import RewardTile from "component/rewardTile";
|
2017-06-08 02:56:52 +02:00
|
|
|
import SubHeader from "component/subHeader";
|
|
|
|
import Link from "component/link";
|
2017-05-26 10:53:32 +02:00
|
|
|
|
2017-06-23 07:29:40 +02:00
|
|
|
class RewardsPage extends React.PureComponent {
|
|
|
|
componentDidMount() {
|
|
|
|
this.fetchRewards(this.props);
|
|
|
|
}
|
2017-06-08 02:56:52 +02:00
|
|
|
|
2017-06-23 07:29:40 +02:00
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
this.fetchRewards(nextProps);
|
|
|
|
}
|
2017-05-26 10:53:32 +02:00
|
|
|
|
2017-06-23 07:29:40 +02:00
|
|
|
fetchRewards(props) {
|
|
|
|
const { fetching, rewards, fetchRewards } = props;
|
|
|
|
|
2017-07-16 18:29:46 +02:00
|
|
|
if (!fetching && (!rewards || !rewards.length)) {
|
|
|
|
fetchRewards();
|
|
|
|
}
|
2017-05-26 10:53:32 +02:00
|
|
|
}
|
|
|
|
|
2017-08-19 05:08:01 +02:00
|
|
|
renderPageHeader() {
|
|
|
|
const { doAuth, navigate, user } = this.props;
|
2017-06-23 07:29:40 +02:00
|
|
|
|
2017-07-25 20:34:28 +02:00
|
|
|
if (user && !user.is_reward_approved) {
|
|
|
|
if (
|
|
|
|
!user.primary_email ||
|
2017-07-20 03:07:17 +02:00
|
|
|
!user.has_verified_email ||
|
2017-07-25 20:34:28 +02:00
|
|
|
!user.is_identity_verified
|
|
|
|
) {
|
2017-08-19 05:08:01 +02:00
|
|
|
return (
|
2017-07-25 20:34:28 +02:00
|
|
|
<div>
|
|
|
|
<div className="card__content empty">
|
|
|
|
<p>
|
|
|
|
{__("Only verified accounts are eligible to earn rewards.")}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div className="card__content">
|
|
|
|
<Link onClick={doAuth} button="primary" label="Become Verified" />
|
|
|
|
</div>
|
2017-07-20 03:07:17 +02:00
|
|
|
</div>
|
2017-07-25 20:34:28 +02:00
|
|
|
);
|
|
|
|
} else {
|
2017-08-19 05:08:01 +02:00
|
|
|
return (
|
2017-07-20 03:07:17 +02:00
|
|
|
<div className="card__content">
|
2017-07-25 20:34:28 +02:00
|
|
|
<p>
|
|
|
|
{__(
|
|
|
|
"This account must undergo review before you can participate in the rewards program."
|
|
|
|
)}
|
|
|
|
{" "}
|
|
|
|
{__(
|
|
|
|
"This can take anywhere from several minutes to several days."
|
|
|
|
)}
|
|
|
|
</p>
|
2017-07-25 00:59:26 +02:00
|
|
|
|
2017-07-25 20:34:28 +02:00
|
|
|
<p>
|
|
|
|
{__(
|
|
|
|
"We apologize for this inconvenience, but have added this additional step to prevent fraud."
|
|
|
|
)}
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
{__("You will receive an email when this process is complete.") +
|
|
|
|
" " +
|
|
|
|
__("Please enjoy free content in the meantime!")}
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<Link
|
|
|
|
onClick={() => navigate("/discover")}
|
|
|
|
button="primary"
|
|
|
|
label="Return Home"
|
|
|
|
/>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2017-08-19 05:08:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderUnclaimedRewards() {
|
|
|
|
const { fetching, rewards, user } = this.props;
|
|
|
|
|
|
|
|
if (fetching) {
|
|
|
|
return (
|
|
|
|
<div className="card__content">
|
|
|
|
<BusyMessage message={__("Fetching rewards")} />
|
|
|
|
</div>
|
|
|
|
);
|
2017-08-03 00:55:58 +02:00
|
|
|
} else if (user === null) {
|
2017-08-19 05:08:01 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="card__content empty">
|
|
|
|
<p>
|
|
|
|
{__(
|
2017-08-08 11:36:14 +02:00
|
|
|
"This application is unable to earn rewards due to an authentication failure."
|
2017-08-19 05:08:01 +02:00
|
|
|
)}
|
|
|
|
</p>
|
2017-08-03 00:55:58 +02:00
|
|
|
</div>
|
2017-06-23 07:29:40 +02:00
|
|
|
);
|
2017-08-19 05:08:01 +02:00
|
|
|
} else if (!rewards || rewards.length <= 0) {
|
|
|
|
return (
|
|
|
|
<div className="card__content empty">
|
|
|
|
{__("Failed to load rewards.")}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return rewards.map(reward =>
|
|
|
|
<RewardTile key={reward.reward_type} reward={reward} />
|
|
|
|
);
|
2017-06-23 07:29:40 +02:00
|
|
|
}
|
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 (
|
|
|
|
<main className="main--single-column">
|
|
|
|
<SubHeader />
|
2017-08-19 05:08:01 +02:00
|
|
|
{this.renderPageHeader()}
|
|
|
|
{this.renderUnclaimedRewards()}
|
|
|
|
{<RewardListClaimed />}
|
2017-06-23 07:29:40 +02:00
|
|
|
</main>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2017-05-26 10:53:32 +02:00
|
|
|
|
|
|
|
export default RewardsPage;
|