2018-02-07 19:06:07 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2019-07-22 23:52:19 +02:00
|
|
|
import { reduxForm } from 'redux-form';
|
2017-03-16 23:25:12 +01:00
|
|
|
import { bindActionCreators } from 'redux';
|
2019-05-14 11:58:04 +02:00
|
|
|
import { Tab, Tabs, TabList, TabPanel } from 'react-tabs';
|
2019-07-22 23:52:19 +02:00
|
|
|
import axios from 'axios';
|
2018-02-23 17:31:41 +01:00
|
|
|
import { Helmet } from 'react-helmet';
|
2019-05-15 16:25:58 +02:00
|
|
|
import { updateSettings, initiateVerification, createApiKey, removeApiKey } from '../actions';
|
2017-03-16 23:25:12 +01:00
|
|
|
import AccountForm from '../components/AccountForm';
|
|
|
|
import { validateSettings } from '../../../utils/reduxFormUtils';
|
2017-04-13 18:04:10 +02:00
|
|
|
import GithubButton from '../components/GithubButton';
|
2020-02-11 22:58:08 +01:00
|
|
|
import GoogleButton from '../components/GoogleButton';
|
2019-05-14 11:58:04 +02:00
|
|
|
import APIKeyForm from '../components/APIKeyForm';
|
2019-09-19 19:38:27 +02:00
|
|
|
import Nav from '../../../components/Nav';
|
2017-03-16 23:25:12 +01:00
|
|
|
|
2019-09-19 19:38:27 +02:00
|
|
|
const __process = (typeof global !== 'undefined' ? global : window).process;
|
|
|
|
const ROOT_URL = __process.env.API_URL;
|
2017-03-16 23:25:12 +01:00
|
|
|
|
2020-02-11 22:58:08 +01:00
|
|
|
function SocialLoginPanel(props) {
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<AccountForm {...props} />
|
|
|
|
<h2 className="form-container__divider">Social Login</h2>
|
|
|
|
<p className="account__social-text">
|
|
|
|
Use your GitHub or Google account to log into the p5.js Web Editor.
|
|
|
|
</p>
|
|
|
|
<GithubButton buttonText="Login with GitHub" />
|
|
|
|
<GoogleButton buttonText="Login with Google" />
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-09-19 19:38:27 +02:00
|
|
|
class AccountView extends React.Component {
|
2018-10-13 22:14:46 +02:00
|
|
|
componentDidMount() {
|
2019-05-24 11:59:56 +02:00
|
|
|
document.body.className = this.props.theme;
|
2018-10-13 22:14:46 +02:00
|
|
|
}
|
|
|
|
|
2017-03-16 23:25:12 +01:00
|
|
|
render() {
|
2019-08-30 22:15:13 +02:00
|
|
|
const accessTokensUIEnabled = window.process.env.UI_ACCESS_TOKEN_ENABLED;
|
|
|
|
|
2017-03-16 23:25:12 +01:00
|
|
|
return (
|
2019-09-19 19:38:27 +02:00
|
|
|
<div className="account-settings__container">
|
2018-02-23 17:31:41 +01:00
|
|
|
<Helmet>
|
2019-09-19 19:38:27 +02:00
|
|
|
<title>p5.js Web Editor | Account Settings</title>
|
2018-02-23 17:31:41 +01:00
|
|
|
</Helmet>
|
2019-05-24 11:59:56 +02:00
|
|
|
|
2019-09-19 19:38:27 +02:00
|
|
|
<Nav layout="dashboard" />
|
2019-05-24 11:59:56 +02:00
|
|
|
|
2019-09-19 19:38:27 +02:00
|
|
|
<section className="account-settings">
|
|
|
|
<header className="account-settings__header">
|
|
|
|
<h1 className="account-settings__title">Account Settings</h1>
|
|
|
|
</header>
|
|
|
|
{accessTokensUIEnabled &&
|
2019-05-24 11:59:56 +02:00
|
|
|
<Tabs className="account__tabs">
|
|
|
|
<TabList>
|
|
|
|
<div className="tabs__titles">
|
|
|
|
<Tab><h4 className="tabs__title">Account</h4></Tab>
|
2019-08-30 22:15:13 +02:00
|
|
|
{accessTokensUIEnabled && <Tab><h4 className="tabs__title">Access Tokens</h4></Tab>}
|
2019-05-24 11:59:56 +02:00
|
|
|
</div>
|
|
|
|
</TabList>
|
|
|
|
<TabPanel>
|
2020-02-11 22:58:08 +01:00
|
|
|
<SocialLoginPanel {...this.props} />
|
2019-05-24 11:59:56 +02:00
|
|
|
</TabPanel>
|
|
|
|
<TabPanel>
|
|
|
|
<APIKeyForm {...this.props} />
|
|
|
|
</TabPanel>
|
|
|
|
</Tabs>
|
2019-09-19 19:38:27 +02:00
|
|
|
}
|
2020-02-11 22:58:08 +01:00
|
|
|
{ !accessTokensUIEnabled && <SocialLoginPanel {...this.props} /> }
|
2019-05-24 11:59:56 +02:00
|
|
|
</section>
|
2019-06-04 14:30:10 +02:00
|
|
|
</div>
|
2017-03-16 23:25:12 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
initialValues: state.user, // <- initialValues for reduxForm
|
2019-05-15 16:40:09 +02:00
|
|
|
previousPath: state.ide.previousPath,
|
2017-03-16 23:25:12 +01:00
|
|
|
user: state.user,
|
2019-05-14 11:58:04 +02:00
|
|
|
apiKeys: state.user.apiKeys,
|
2018-10-13 22:14:46 +02:00
|
|
|
theme: state.preferences.theme
|
2017-03-16 23:25:12 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps(dispatch) {
|
2019-05-14 11:58:04 +02:00
|
|
|
return bindActionCreators({
|
|
|
|
updateSettings, initiateVerification, createApiKey, removeApiKey
|
|
|
|
}, dispatch);
|
2017-03-16 23:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function asyncValidate(formProps, dispatch, props) {
|
|
|
|
const fieldToValidate = props.form._active;
|
|
|
|
if (fieldToValidate) {
|
|
|
|
const queryParams = {};
|
|
|
|
queryParams[fieldToValidate] = formProps[fieldToValidate];
|
|
|
|
queryParams.check_type = fieldToValidate;
|
2019-09-19 19:38:27 +02:00
|
|
|
return axios.get(`${ROOT_URL}/signup/duplicate_check`, { params: queryParams })
|
2017-03-16 23:25:12 +01:00
|
|
|
.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 16:40:09 +02:00
|
|
|
previousPath: PropTypes.string.isRequired,
|
2018-10-13 22:14:46 +02:00
|
|
|
theme: PropTypes.string.isRequired
|
2017-03-16 23:25:12 +01:00
|
|
|
};
|
|
|
|
|
2019-07-22 23:52:19 +02:00
|
|
|
export default reduxForm({
|
|
|
|
form: 'updateAllSettings',
|
|
|
|
fields: ['username', 'email', 'currentPassword', 'newPassword'],
|
|
|
|
validate: validateSettings,
|
|
|
|
asyncValidate,
|
|
|
|
asyncBlurFields: ['username', 'email', 'currentPassword']
|
|
|
|
}, mapStateToProps, mapDispatchToProps)(AccountView);
|