2018-02-07 18:06:07 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2018-10-15 22:22:56 +00:00
|
|
|
import { connect } from 'react-redux';
|
2017-03-16 22:25:12 +00:00
|
|
|
import { bindActionCreators } from 'redux';
|
2019-05-15 14:25:58 +00:00
|
|
|
import { browserHistory } from 'react-router';
|
2019-05-14 09:58:04 +00:00
|
|
|
import { Tab, Tabs, TabList, TabPanel } from 'react-tabs';
|
2017-03-16 22:25:12 +00:00
|
|
|
import InlineSVG from 'react-inlinesvg';
|
2018-02-23 16:31:41 +00:00
|
|
|
import { Helmet } from 'react-helmet';
|
2019-05-15 14:25:58 +00:00
|
|
|
import { updateSettings, initiateVerification, createApiKey, removeApiKey } from '../actions';
|
2017-03-16 22:25:12 +00:00
|
|
|
import AccountForm from '../components/AccountForm';
|
|
|
|
import { validateSettings } from '../../../utils/reduxFormUtils';
|
2017-04-13 16:04:10 +00:00
|
|
|
import GithubButton from '../components/GithubButton';
|
2019-05-14 09:58:04 +00:00
|
|
|
import APIKeyForm from '../components/APIKeyForm';
|
2019-05-24 09:59:56 +00:00
|
|
|
import NavBasic from '../../../components/NavBasic';
|
2017-03-16 22:25:12 +00:00
|
|
|
|
|
|
|
const exitUrl = require('../../../images/exit.svg');
|
|
|
|
|
|
|
|
class AccountView extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.closeAccountPage = this.closeAccountPage.bind(this);
|
|
|
|
this.gotoHomePage = this.gotoHomePage.bind(this);
|
|
|
|
}
|
|
|
|
|
2018-10-13 20:14:46 +00:00
|
|
|
componentDidMount() {
|
2019-05-24 09:59:56 +00:00
|
|
|
document.body.className = this.props.theme;
|
2018-10-13 20:14:46 +00:00
|
|
|
}
|
|
|
|
|
2017-03-16 22:25:12 +00:00
|
|
|
closeAccountPage() {
|
2019-05-15 14:40:09 +00:00
|
|
|
browserHistory.push(this.props.previousPath);
|
2017-03-16 22:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gotoHomePage() {
|
|
|
|
browserHistory.push('/');
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2019-06-04 12:30:10 +00:00
|
|
|
<div className="user">
|
2018-02-23 16:31:41 +00:00
|
|
|
<Helmet>
|
|
|
|
<title>p5.js Web Editor | Account</title>
|
|
|
|
</Helmet>
|
2019-05-24 09:59:56 +00:00
|
|
|
|
2019-06-04 12:58:13 +00:00
|
|
|
<NavBasic onBack={this.closeAccountPage} />
|
2019-05-24 09:59:56 +00:00
|
|
|
|
2019-06-04 12:30:10 +00:00
|
|
|
<section className="modal">
|
2019-05-24 09:59:56 +00:00
|
|
|
<div className="modal-content">
|
|
|
|
<div className="modal__header">
|
|
|
|
<h2 className="modal__title">My Account</h2>
|
|
|
|
</div>
|
|
|
|
<Tabs className="account__tabs">
|
|
|
|
<TabList>
|
|
|
|
<div className="tabs__titles">
|
|
|
|
<Tab><h4 className="tabs__title">Account</h4></Tab>
|
|
|
|
<Tab><h4 className="tabs__title">Access Tokens</h4></Tab>
|
|
|
|
</div>
|
|
|
|
</TabList>
|
|
|
|
<TabPanel>
|
|
|
|
<AccountForm {...this.props} />
|
2019-05-22 14:30:46 +00:00
|
|
|
<h2 className="form-container__divider">Social Login</h2>
|
2019-05-24 09:59:56 +00:00
|
|
|
<p className="account__social-text">
|
2019-05-22 14:30:46 +00:00
|
|
|
Link this account with your GitHub account to allow login from both.
|
|
|
|
</p>
|
|
|
|
<GithubButton buttonText="Login with GitHub" />
|
2019-05-24 09:59:56 +00:00
|
|
|
</TabPanel>
|
|
|
|
<TabPanel>
|
|
|
|
<APIKeyForm {...this.props} />
|
|
|
|
</TabPanel>
|
|
|
|
</Tabs>
|
|
|
|
</div>
|
|
|
|
</section>
|
2019-06-04 12:30:10 +00:00
|
|
|
</div>
|
2017-03-16 22:25:12 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
initialValues: state.user, // <- initialValues for reduxForm
|
2019-05-15 14:40:09 +00:00
|
|
|
previousPath: state.ide.previousPath,
|
2017-03-16 22:25:12 +00:00
|
|
|
user: state.user,
|
2019-05-14 09:58:04 +00:00
|
|
|
apiKeys: state.user.apiKeys,
|
2018-10-13 20:14:46 +00:00
|
|
|
theme: state.preferences.theme
|
2017-03-16 22:25:12 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps(dispatch) {
|
2019-05-14 09:58:04 +00:00
|
|
|
return bindActionCreators({
|
|
|
|
updateSettings, initiateVerification, createApiKey, removeApiKey
|
|
|
|
}, dispatch);
|
2017-03-16 22:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function asyncValidate(formProps, dispatch, props) {
|
|
|
|
const fieldToValidate = props.form._active;
|
|
|
|
if (fieldToValidate) {
|
|
|
|
const queryParams = {};
|
|
|
|
queryParams[fieldToValidate] = formProps[fieldToValidate];
|
|
|
|
queryParams.check_type = fieldToValidate;
|
|
|
|
return axios.get('/api/signup/duplicate_check', { params: queryParams })
|
|
|
|
.then((response) => {
|
|
|
|
if (response.data.exists) {
|
|
|
|
const error = {};
|
|
|
|
error[fieldToValidate] = response.data.message;
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return Promise.resolve(true).then(() => {});
|
|
|
|
}
|
|
|
|
|
|
|
|
AccountView.propTypes = {
|
2019-05-15 14:40:09 +00:00
|
|
|
previousPath: PropTypes.string.isRequired,
|
2018-10-13 20:14:46 +00:00
|
|
|
theme: PropTypes.string.isRequired
|
2017-03-16 22:25:12 +00:00
|
|
|
};
|
|
|
|
|
2018-10-15 22:22:56 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(AdvancedSettingsView);
|