2016-11-22 21:19:08 +01:00
|
|
|
import React from 'react';
|
|
|
|
import lbry from '../lbry.js';
|
|
|
|
import {Link} from '../component/link.js';
|
|
|
|
import Modal from '../component/modal.js';
|
|
|
|
|
2016-09-08 10:17:08 +02:00
|
|
|
var referralCodeContentStyle = {
|
|
|
|
display: 'inline-block',
|
|
|
|
textAlign: 'left',
|
|
|
|
width: '600px',
|
|
|
|
}, referralCodeLabelStyle = {
|
|
|
|
display: 'inline-block',
|
|
|
|
cursor: 'default',
|
|
|
|
width: '130px',
|
|
|
|
textAlign: 'right',
|
|
|
|
marginRight: '6px',
|
|
|
|
};
|
|
|
|
|
|
|
|
var ReferralPage = React.createClass({
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
submitting: false,
|
2016-10-21 09:49:04 +02:00
|
|
|
modal: null,
|
|
|
|
referralCredits: null,
|
|
|
|
failureReason: null,
|
2016-09-08 10:17:08 +02:00
|
|
|
}
|
|
|
|
},
|
2016-10-19 09:13:39 +02:00
|
|
|
handleSubmit: function(event) {
|
|
|
|
if (typeof event !== 'undefined') {
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
|
2016-09-08 10:17:08 +02:00
|
|
|
if (!this.refs.code.value) {
|
2016-10-21 09:49:04 +02:00
|
|
|
this.setState({
|
|
|
|
modal: 'missingCode',
|
|
|
|
});
|
2016-09-08 10:17:08 +02:00
|
|
|
} else if (!this.refs.email.value) {
|
2016-10-21 09:49:04 +02:00
|
|
|
this.setState({
|
|
|
|
modal: 'missingEmail',
|
|
|
|
});
|
2016-09-08 10:17:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({
|
2016-10-21 09:49:04 +02:00
|
|
|
submitting: true,
|
2016-09-08 10:17:08 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
lbry.getNewAddress((address) => {
|
|
|
|
var code = this.refs.code.value;
|
|
|
|
var email = this.refs.email.value;
|
|
|
|
|
|
|
|
var xhr = new XMLHttpRequest;
|
|
|
|
xhr.addEventListener('load', () => {
|
|
|
|
var response = JSON.parse(xhr.responseText);
|
|
|
|
|
|
|
|
if (response.success) {
|
2016-10-21 09:49:04 +02:00
|
|
|
this.setState({
|
|
|
|
modal: 'referralInfo',
|
|
|
|
referralCredits: response.referralCredits,
|
|
|
|
});
|
2016-09-08 10:17:08 +02:00
|
|
|
} else {
|
|
|
|
this.setState({
|
2016-10-21 09:49:04 +02:00
|
|
|
submitting: false,
|
|
|
|
modal: 'lookupFailed',
|
|
|
|
failureReason: response.reason,
|
2016-09-08 10:17:08 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
xhr.addEventListener('error', () => {
|
|
|
|
this.setState({
|
2016-10-21 09:49:04 +02:00
|
|
|
submitting: false,
|
|
|
|
modal: 'couldNotConnect',
|
2016-09-08 10:17:08 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
xhr.open('POST', 'https://invites.lbry.io/check', true);
|
|
|
|
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
|
|
|
xhr.send('code=' + encodeURIComponent(code) + '&address=' + encodeURIComponent(address) +
|
|
|
|
'&email=' + encodeURIComponent(email));
|
|
|
|
});
|
|
|
|
},
|
2016-10-21 09:49:04 +02:00
|
|
|
closeModal: function() {
|
|
|
|
this.setState({
|
|
|
|
modal: null,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
handleFinished: function() {
|
|
|
|
localStorage.setItem('claimCodeDone', true);
|
|
|
|
window.location = '?home';
|
|
|
|
},
|
2016-09-08 10:17:08 +02:00
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<main>
|
2016-10-19 09:13:39 +02:00
|
|
|
<form onSubmit={this.handleSubmit}>
|
|
|
|
<div className="card">
|
|
|
|
<h2>Check your referral credits</h2>
|
|
|
|
<section style={referralCodeContentStyle}>
|
|
|
|
<p>Have you referred others to LBRY? Enter your referral code and email address below to check how many credits you've earned!</p>
|
|
|
|
<p>As a reminder, your referral code is the same as your LBRY invitation code.</p>
|
|
|
|
</section>
|
|
|
|
<section>
|
2016-09-08 10:17:08 +02:00
|
|
|
<section><label style={referralCodeLabelStyle} htmlFor="code">Referral code</label><input name="code" ref="code" /></section>
|
|
|
|
<section><label style={referralCodeLabelStyle} htmlFor="email">Email</label><input name="email" ref="email" /></section>
|
2016-10-19 09:13:39 +02:00
|
|
|
</section>
|
|
|
|
<section>
|
|
|
|
<Link button="primary" label={this.state.submitting ? "Submitting..." : "Submit"}
|
|
|
|
disabled={this.state.submitting} onClick={this.handleSubmit} />
|
|
|
|
<input type='submit' className='hidden' />
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
</form>
|
2017-01-13 23:05:09 +01:00
|
|
|
<Modal isOpen={this.state.modal == 'referralInfo'} contentLabel="Credit earnings"
|
|
|
|
onConfirmed={this.handleFinished}>
|
2016-10-21 09:49:04 +02:00
|
|
|
{this.state.referralCredits > 0
|
2016-11-29 00:24:38 +01:00
|
|
|
? `You have earned ${response.referralCredits} credits from referrals. We will credit your account shortly. Thanks!`
|
2016-10-21 09:49:04 +02:00
|
|
|
: 'You have not earned any new referral credits since the last time you checked. Please check back in a week or two.'}
|
|
|
|
</Modal>
|
2017-01-13 23:05:09 +01:00
|
|
|
<Modal isOpen={this.state.modal == 'lookupFailed'} contentLabel={failureReason}
|
|
|
|
onConfirmed={this.closeModal}>
|
2016-10-21 09:49:04 +02:00
|
|
|
{this.state.failureReason}
|
|
|
|
</Modal>
|
2017-01-13 23:05:09 +01:00
|
|
|
<Modal isOpen={this.state.modal == 'couldNotConnect'} contentLabel="Couldn't confirm referral code"
|
|
|
|
onConfirmed={this.closeModal}>
|
2016-10-21 09:49:04 +02:00
|
|
|
LBRY couldn't connect to our servers to confirm your referral code. Please check your internet connection.
|
|
|
|
</Modal>
|
2016-09-08 10:17:08 +02:00
|
|
|
</main>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2016-11-22 21:19:08 +01:00
|
|
|
|
|
|
|
export default ReferralPage;
|