lbry-desktop/ui/js/component/welcome.js

157 lines
4.2 KiB
JavaScript
Raw Normal View History

2017-04-01 02:51:15 -04:00
import React from 'react';
2017-04-02 06:00:40 -04:00
import lbryio from '../lbryio.js';
2017-04-01 02:51:15 -04:00
import ModalPage from './modal-page.js';
import {Link} from '../component/link.js';
2017-04-02 06:00:40 -04:00
import FormField from '../component/form.js';
import Notice from '../component/notice.js'
const SubmitEmailStage = React.createClass({
getInitialState: function() {
return {
rewardType: null,
email: '',
submitting: false,
errorMessage: null,
2017-04-02 06:00:40 -04:00
};
},
handleEmailChanged: function(event) {
this.setState({
email: event.target.value,
});
},
handleSubmit: function(event) {
event.preventDefault();
this.setState({
submitting: true,
});
lbryio.call('user_email', 'new', {email: this.state.email}, 'post').then(() => {
this.props.onDone();
2017-04-02 06:00:40 -04:00
}, (error) => {
this.setState({
submitting: false,
errorMessage: error.message,
2017-04-02 06:00:40 -04:00
});
});
},
render: function() {
return (
<section>
<h1>Welcome to LBRY</h1>
{this.state.errorMessage
? <Notice isError>
{this.state.errorMessage}
2017-04-02 06:00:40 -04:00
</Notice>
: null}
<p>Copy here explaining what we do with your email, and the reward.</p>
<form onSubmit={this.handleSubmit}>
<section>Email <label><FormField ref={(field) => { this._emailField = field }} type="text" name="email" value={this.state.email} onChange={this.handleEmailChanged} /></label></section>
<section><Link button="primary" label="Submit and Continue" disabled={this.state.submitting} onClick={this.handleSubmit} /></section>
2017-04-02 06:00:40 -04:00
</form>
</section>
);
}
});
const ConfirmEmailStage = React.createClass({
2017-04-02 06:00:40 -04:00
getInitialState: function() {
return {
rewardType: null,
code: '',
2017-04-02 06:00:40 -04:00
submitting: false,
errorMessage: null,
2017-04-02 06:00:40 -04:00
};
},
handleCodeChanged: function(event) {
2017-04-02 06:00:40 -04:00
this.setState({
code: event.target.value,
2017-04-02 06:00:40 -04:00
});
},
handleSubmit: function(event) {
event.preventDefault();
this.setState({
submitting: true,
});
lbryio.call('user_email', 'confirm', {verification_token: this.state.code}, 'post').then(() => {
rewards.claimReward('confirm_email').then(() => {
console.log('succeeded');
this.props.onDone();
}, (err) => {
console.log('failed');
this.props.onDone();
});
}, (error) => {
this.setState({
submitting: false,
errorMessage: error.message,
});
});
2017-04-02 06:00:40 -04:00
},
render: function() {
return (
<section>
<h1>Confirm Your Email Address</h1>
{this.state.errorMessage
? <Notice isError>
{this.state.errorMessage}
2017-04-02 06:00:40 -04:00
</Notice>
: null}
<p>Please enter your verification code to confirm your email address.</p>
2017-04-02 06:00:40 -04:00
<form onSubmit={this.handleSubmit}>
<section><label>Verification Code: <FormField ref={(field) => { this._codeField = field }} type="text" name="code" value={this.state.code} onChange={this.handleCodeChanged} /></label></section>
<section><Link button="primary" label="Verify" disabled={this.state.submitting} onClick={this.handleSubmit} /></section>
2017-04-02 06:00:40 -04:00
</form>
</section>
);
}
});
2017-04-02 06:00:40 -04:00
const FinalMessageStage = React.createClass({
render: function() {
return (
<section>
<h1>Email verified</h1>
<p>Text here about what happens next</p>
<section><Link button="primary" label="OK" onClick={this.props.onDone} /></section>
2017-04-02 06:00:40 -04:00
</section>
);
}
});
2017-04-01 02:51:15 -04:00
export const Welcome = React.createClass({
2017-04-02 06:00:40 -04:00
_stages: [
SubmitEmailStage,
ConfirmEmailStage,
2017-04-02 06:00:40 -04:00
FinalMessageStage,
],
2017-04-01 02:51:15 -04:00
propTypes: {
onDone: React.PropTypes.func.isRequired,
},
2017-04-02 06:00:40 -04:00
getInitialState: function() {
return {
stageNum: 0,
};
},
handleStageDone: function() {
2017-04-02 06:00:40 -04:00
if (this.state.stageNum >= this._stages.length - 1) {
this.props.onDone();
} else {
this.setState({
stageNum: this.state.stageNum + 1,
});
2017-04-02 06:00:40 -04:00
}
},
2017-04-01 02:51:15 -04:00
render: function() {
2017-04-02 06:00:40 -04:00
const Content = this._stages[this.state.stageNum];
2017-04-01 02:51:15 -04:00
return (
<ModalPage contentLabel="Welcome to LBRY" {...this.props}>
<Content onDone={this.handleStageDone} />
2017-04-01 02:51:15 -04:00
</ModalPage>
);
}
});