2016-07-04 17:29:58 +02:00
|
|
|
var claimCodePageStyle = {
|
|
|
|
textAlign: 'center',
|
|
|
|
}, claimCodeContentStyle = {
|
|
|
|
display: 'inline-block',
|
|
|
|
textAlign: 'left',
|
|
|
|
width: '600px',
|
|
|
|
}, claimCodeLabelStyle = {
|
|
|
|
display: 'inline-block',
|
|
|
|
cursor: 'default',
|
|
|
|
width: '130px',
|
2016-07-05 07:39:53 +02:00
|
|
|
textAlign: 'right',
|
|
|
|
marginRight: '6px',
|
2016-07-04 17:29:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var ClaimCodePage = React.createClass({
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
2016-07-04 20:58:31 +02:00
|
|
|
submitting: false,
|
2016-07-04 17:29:58 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
handleSubmit: function() {
|
|
|
|
if (!this.refs.code.value) {
|
2016-07-04 20:55:18 +02:00
|
|
|
alert('Please enter an invitation code or choose "Skip."');
|
2016-07-04 20:58:00 +02:00
|
|
|
return;
|
2016-07-04 20:55:18 +02:00
|
|
|
} else if (!this.refs.email.value) {
|
|
|
|
alert('Please enter an email address or choose "Skip."');
|
2016-07-04 20:58:00 +02:00
|
|
|
return;
|
2016-07-04 17:29:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
submitting: true
|
|
|
|
});
|
|
|
|
|
|
|
|
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) {
|
|
|
|
alert('Your invite code has been redeemed! 200 LBRY credits will be added to your balance shortly.');
|
|
|
|
// Send them to "landing" instead of "home" (home will just trigger the message all over again until the credits arrive)
|
|
|
|
window.location = '?landing';
|
|
|
|
} else {
|
|
|
|
alert("You've entered an invalid code, or one that's already been claimed. Please check your code and try again.");
|
|
|
|
this.setState({
|
|
|
|
submitting: false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
xhr.addEventListener('error', () => {
|
|
|
|
this.setState({
|
|
|
|
submitting: false
|
|
|
|
});
|
|
|
|
alert('LBRY couldn\'t connect to our servers to confirm your invitation code. Please check your ' +
|
|
|
|
'internet connection. If you continue to have problems, you can still browse LBRY and ' +
|
|
|
|
'visit the Settings page to redeem your code later.');
|
|
|
|
});
|
|
|
|
|
|
|
|
xhr.open('POST', 'https://invites.lbry.io', true);
|
|
|
|
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
2016-07-05 04:07:24 +02:00
|
|
|
xhr.send('code=' + encodeURIComponent(code) + '&address=' + encodeURIComponent(address) +
|
|
|
|
'&email=' + encodeURIComponent(email));
|
2016-07-04 17:29:58 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
handleSkip: function() {
|
|
|
|
alert('Welcome to LBRY! You can visit the Settings page to redeem an invite code at any time.');
|
|
|
|
window.location = '?landing';
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<main className="page" style={claimCodePageStyle}>
|
|
|
|
<h1>Claim your beta invitation code</h1>
|
|
|
|
<section style={claimCodeContentStyle}>
|
2016-07-04 20:55:18 +02:00
|
|
|
<p>Thanks for beta testing LBRY! Enter your invitation code and email address below to receive your 200 free
|
|
|
|
LBRY credits.</p>
|
|
|
|
<p>You will be added to our mailing list (if you're not already on it) and will be eligible for future rewards for beta testers.</p>
|
2016-07-04 17:29:58 +02:00
|
|
|
</section>
|
|
|
|
<section>
|
2016-07-05 07:39:53 +02:00
|
|
|
<form onSubmit={this.handleSubmit}>
|
2016-07-04 17:29:58 +02:00
|
|
|
<section><label style={claimCodeLabelStyle} htmlFor="code">Invitation code</label><input name="code" ref="code" /></section>
|
2016-07-05 03:55:58 +02:00
|
|
|
<section><label style={claimCodeLabelStyle} htmlFor="email">Email</label><input name="email" ref="email" /></section>
|
2016-07-04 17:29:58 +02:00
|
|
|
</form>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
|
|
<Link button="primary" label={this.state.submitting ? "Submitting..." : "Submit"}
|
|
|
|
disabled={this.state.submitting} onClick={this.handleSubmit} />
|
2016-07-04 21:05:26 +02:00
|
|
|
<Link button="alt" label="Skip" disabled={this.state.submitting} onClick={this.handleSkip} />
|
2016-07-04 17:29:58 +02:00
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
);
|
|
|
|
}
|
2016-07-04 20:55:18 +02:00
|
|
|
});
|