summaryrefslogtreecommitdiffstats
path: root/webapp/components
diff options
context:
space:
mode:
authorn1aba <n1aba.github@gmail.com>2017-08-18 08:42:10 -0500
committerHarrison Healey <harrisonmhealey@gmail.com>2017-08-18 09:42:10 -0400
commitf40f41ed536edb76c9873c0cdd5dc8685b0f950f (patch)
treeb53f73c702c4e40cb9a5140b8cd3e5f2da9aaf46 /webapp/components
parent9097289c2ce2b719a5aa0f9d567594f2b6a7e30b (diff)
downloadchat-f40f41ed536edb76c9873c0cdd5dc8685b0f950f.tar.gz
chat-f40f41ed536edb76c9873c0cdd5dc8685b0f950f.tar.bz2
chat-f40f41ed536edb76c9873c0cdd5dc8685b0f950f.zip
PLT-6443 Migrate add_oauth_app.jsx to be pure and use Redux (#7232)
* Migrate add_oauth_app.jsx to be pure and use Redux, add tests * Remove unused flux code for OAuthApps
Diffstat (limited to 'webapp/components')
-rw-r--r--webapp/components/integrations/components/add_oauth_app/add_oauth_app.jsx (renamed from webapp/components/integrations/components/add_oauth_app.jsx)80
-rw-r--r--webapp/components/integrations/components/add_oauth_app/index.js25
2 files changed, 67 insertions, 38 deletions
diff --git a/webapp/components/integrations/components/add_oauth_app.jsx b/webapp/components/integrations/components/add_oauth_app/add_oauth_app.jsx
index a74d577c3..cad3244e3 100644
--- a/webapp/components/integrations/components/add_oauth_app.jsx
+++ b/webapp/components/integrations/components/add_oauth_app/add_oauth_app.jsx
@@ -1,11 +1,8 @@
-import PropTypes from 'prop-types';
-
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React from 'react';
-
-import * as OAuthActions from 'actions/oauth_actions.jsx';
+import PropTypes from 'prop-types';
import BackstageHeader from 'components/backstage/components/backstage_header.jsx';
import {FormattedMessage} from 'react-intl';
@@ -13,26 +10,31 @@ import FormError from 'components/form_error.jsx';
import {browserHistory, Link} from 'react-router/es6';
import SpinnerButton from 'components/spinner_button.jsx';
-export default class AddOAuthApp extends React.Component {
- static get propTypes() {
- return {
- team: PropTypes.object
- };
+export default class AddOAuthApp extends React.PureComponent {
+ static propTypes = {
+
+ /**
+ * The team data
+ */
+ team: PropTypes.object,
+
+ /**
+ * The request state for addOAuthApp action. Contains status and error
+ */
+ addOAuthAppRequest: PropTypes.object.isRequired,
+
+ actions: PropTypes.shape({
+
+ /**
+ * The function to call to add new OAuthApp
+ */
+ addOAuthApp: PropTypes.func.isRequired
+ }).isRequired
}
constructor(props) {
super(props);
- this.handleSubmit = this.handleSubmit.bind(this);
-
- this.updateName = this.updateName.bind(this);
- this.updateTrusted = this.updateTrusted.bind(this);
- this.updateDescription = this.updateDescription.bind(this);
- this.updateHomepage = this.updateHomepage.bind(this);
- this.updateIconUrl = this.updateIconUrl.bind(this);
- this.updateCallbackUrls = this.updateCallbackUrls.bind(this);
-
- this.imageLoaded = this.imageLoaded.bind(this);
this.image = new Image();
this.image.onload = this.imageLoaded;
@@ -50,14 +52,14 @@ export default class AddOAuthApp extends React.Component {
};
}
- imageLoaded() {
+ imageLoaded = () => {
this.setState({
has_icon: true,
icon_url: this.refs.icon_url.value
});
}
- handleSubmit(e) {
+ handleSubmit = (e) => {
e.preventDefault();
if (this.state.saving) {
@@ -144,45 +146,47 @@ export default class AddOAuthApp extends React.Component {
icon_url: this.state.icon_url
};
- OAuthActions.registerOAuthApp(
- app,
+ this.props.actions.addOAuthApp(app).then(
(data) => {
- browserHistory.push('/' + this.props.team.name + '/integrations/confirm?type=oauth2-apps&id=' + data.id);
- },
- (err) => {
- this.setState({
- saving: false,
- serverError: err.message
- });
+ const {error} = this.props.addOAuthAppRequest;
+ if (error) {
+ this.setState({
+ saving: false,
+ serverError: error.message
+ });
+ } else {
+ browserHistory.
+ push(`/${this.props.team.name}/integrations/confirm?type=oauth2-apps&id=${data.id}`);
+ }
}
);
}
- updateName(e) {
+ updateName = (e) => {
this.setState({
name: e.target.value
});
}
- updateTrusted(e) {
+ updateTrusted = (e) => {
this.setState({
is_trusted: e.target.value === 'true'
});
}
- updateDescription(e) {
+ updateDescription = (e) => {
this.setState({
description: e.target.value
});
}
- updateHomepage(e) {
+ updateHomepage = (e) => {
this.setState({
homepage: e.target.value
});
}
- updateIconUrl(e) {
+ updateIconUrl = (e) => {
this.setState({
has_icon: false,
icon_url: ''
@@ -190,7 +194,7 @@ export default class AddOAuthApp extends React.Component {
this.image.src = e.target.value;
}
- updateCallbackUrls(e) {
+ updateCallbackUrls = (e) => {
this.setState({
callbackUrls: e.target.value
});
@@ -209,7 +213,7 @@ export default class AddOAuthApp extends React.Component {
return (
<div className='backstage-content'>
<BackstageHeader>
- <Link to={'/' + this.props.team.name + '/integrations/oauth2-apps'}>
+ <Link to={`/${this.props.team.name}/integrations/oauth2-apps`}>
<FormattedMessage
id='installed_oauth_apps.header'
defaultMessage='Installed OAuth2 Apps'
@@ -410,7 +414,7 @@ export default class AddOAuthApp extends React.Component {
/>
<Link
className='btn btn-sm'
- to={'/' + this.props.team.name + '/integrations/oauth2-apps'}
+ to={`/${this.props.team.name}/integrations/oauth2-apps`}
>
<FormattedMessage
id='installed_oauth_apps.cancel'
diff --git a/webapp/components/integrations/components/add_oauth_app/index.js b/webapp/components/integrations/components/add_oauth_app/index.js
new file mode 100644
index 000000000..be3446c45
--- /dev/null
+++ b/webapp/components/integrations/components/add_oauth_app/index.js
@@ -0,0 +1,25 @@
+// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import {connect} from 'react-redux';
+import {bindActionCreators} from 'redux';
+import {addOAuthApp} from 'mattermost-redux/actions/integrations';
+
+import AddOAuthApp from './add_oauth_app.jsx';
+
+function mapStateToProps(state, ownProps) {
+ return {
+ ...ownProps,
+ addOAuthAppRequest: state.requests.integrations.addOAuthApp
+ };
+}
+
+function mapDispatchToProps(dispatch) {
+ return {
+ actions: bindActionCreators({
+ addOAuthApp
+ }, dispatch)
+ };
+}
+
+export default connect(mapStateToProps, mapDispatchToProps)(AddOAuthApp);