2018-02-07 18:06:07 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2019-07-22 21:52:19 +00:00
|
|
|
import { reduxForm } from 'redux-form';
|
2017-03-16 22:25:12 +00:00
|
|
|
import { bindActionCreators } from 'redux';
|
2019-05-14 09:58:04 +00:00
|
|
|
import { Tab, Tabs, TabList, TabPanel } from 'react-tabs';
|
2018-02-23 16:31:41 +00:00
|
|
|
import { Helmet } from 'react-helmet';
|
2020-08-13 12:25:57 +00:00
|
|
|
import { withTranslation } from 'react-i18next';
|
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';
|
2020-06-08 10:29:24 +00:00
|
|
|
import apiClient from '../../../utils/apiClient';
|
2017-03-16 22:25:12 +00:00
|
|
|
import { validateSettings } from '../../../utils/reduxFormUtils';
|
2020-04-19 20:45:09 +00:00
|
|
|
import SocialAuthButton from '../components/SocialAuthButton';
|
2019-05-14 09:58:04 +00:00
|
|
|
import APIKeyForm from '../components/APIKeyForm';
|
2019-09-19 17:38:27 +00:00
|
|
|
import Nav from '../../../components/Nav';
|
2017-03-16 22:25:12 +00:00
|
|
|
|
2020-02-11 21:58:08 +00:00
|
|
|
function SocialLoginPanel(props) {
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<AccountForm {...props} />
|
2020-08-13 12:25:57 +00:00
|
|
|
{/* eslint-disable-next-line react/prop-types */}
|
|
|
|
<h2 className="form-container__divider">{props.t('AccountView.SocialLogin')}</h2>
|
2020-02-11 21:58:08 +00:00
|
|
|
<p className="account__social-text">
|
2020-08-13 12:25:57 +00:00
|
|
|
{/* eslint-disable-next-line react/prop-types */}
|
|
|
|
{props.t('AccountView.SocialLoginDescription')}
|
2020-02-11 21:58:08 +00:00
|
|
|
</p>
|
2020-04-26 09:40:00 +00:00
|
|
|
<div className="account__social-stack">
|
|
|
|
<SocialAuthButton service={SocialAuthButton.services.github} />
|
|
|
|
<SocialAuthButton service={SocialAuthButton.services.google} />
|
|
|
|
</div>
|
2020-02-11 21:58:08 +00:00
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-09-19 17:38:27 +00:00
|
|
|
class AccountView extends React.Component {
|
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
|
|
|
render() {
|
2019-08-30 20:15:13 +00:00
|
|
|
const accessTokensUIEnabled = window.process.env.UI_ACCESS_TOKEN_ENABLED;
|
|
|
|
|
2017-03-16 22:25:12 +00:00
|
|
|
return (
|
2019-09-19 17:38:27 +00:00
|
|
|
<div className="account-settings__container">
|
2018-02-23 16:31:41 +00:00
|
|
|
<Helmet>
|
2020-08-13 12:25:57 +00:00
|
|
|
<title>{this.props.t('AccountView.Title')}</title>
|
2018-02-23 16:31:41 +00:00
|
|
|
</Helmet>
|
2019-05-24 09:59:56 +00:00
|
|
|
|
2019-09-19 17:38:27 +00:00
|
|
|
<Nav layout="dashboard" />
|
2019-05-24 09:59:56 +00:00
|
|
|
|
2020-05-19 19:34:00 +00:00
|
|
|
<main className="account-settings">
|
2019-09-19 17:38:27 +00:00
|
|
|
<header className="account-settings__header">
|
2020-08-13 12:25:57 +00:00
|
|
|
<h1 className="account-settings__title">{this.props.t('AccountView.Settings')}</h1>
|
2019-09-19 17:38:27 +00:00
|
|
|
</header>
|
|
|
|
{accessTokensUIEnabled &&
|
2019-05-24 09:59:56 +00:00
|
|
|
<Tabs className="account__tabs">
|
|
|
|
<TabList>
|
|
|
|
<div className="tabs__titles">
|
2020-08-13 12:25:57 +00:00
|
|
|
<Tab><h4 className="tabs__title">{this.props.t('AccountView.AccountTab')}</h4></Tab>
|
|
|
|
{accessTokensUIEnabled && <Tab><h4 className="tabs__title">{this.props.t('AccountView.AccessTokensTab')}</h4></Tab>}
|
2019-05-24 09:59:56 +00:00
|
|
|
</div>
|
|
|
|
</TabList>
|
|
|
|
<TabPanel>
|
2020-09-07 11:59:15 +00:00
|
|
|
{/* <SocialLoginPanel {...this.props} /> */}
|
2019-05-24 09:59:56 +00:00
|
|
|
</TabPanel>
|
|
|
|
<TabPanel>
|
|
|
|
<APIKeyForm {...this.props} />
|
|
|
|
</TabPanel>
|
|
|
|
</Tabs>
|
2019-09-19 17:38:27 +00:00
|
|
|
}
|
2020-02-11 21:58:08 +00:00
|
|
|
{ !accessTokensUIEnabled && <SocialLoginPanel {...this.props} /> }
|
2020-05-19 19:34:00 +00:00
|
|
|
</main>
|
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;
|
2020-06-08 10:29:24 +00:00
|
|
|
return apiClient.get('/signup/duplicate_check', { params: queryParams })
|
2017-03-16 22:25:12 +00: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 14:40:09 +00:00
|
|
|
previousPath: PropTypes.string.isRequired,
|
2020-08-13 12:25:57 +00:00
|
|
|
theme: PropTypes.string.isRequired,
|
|
|
|
t: PropTypes.func.isRequired
|
2017-03-16 22:25:12 +00:00
|
|
|
};
|
|
|
|
|
2020-08-13 12:25:57 +00:00
|
|
|
export default withTranslation()(reduxForm({
|
2019-07-22 21:52:19 +00:00
|
|
|
form: 'updateAllSettings',
|
|
|
|
fields: ['username', 'email', 'currentPassword', 'newPassword'],
|
|
|
|
validate: validateSettings,
|
|
|
|
asyncValidate,
|
|
|
|
asyncBlurFields: ['username', 'email', 'currentPassword']
|
2020-08-13 12:25:57 +00:00
|
|
|
}, mapStateToProps, mapDispatchToProps)(AccountView));
|