diff --git a/app/soapbox/actions/oauth.ts b/app/soapbox/actions/oauth.ts index aefef7b6f..55df6f1ae 100644 --- a/app/soapbox/actions/oauth.ts +++ b/app/soapbox/actions/oauth.ts @@ -18,7 +18,7 @@ export const OAUTH_TOKEN_REVOKE_REQUEST = 'OAUTH_TOKEN_REVOKE_REQUEST'; export const OAUTH_TOKEN_REVOKE_SUCCESS = 'OAUTH_TOKEN_REVOKE_SUCCESS'; export const OAUTH_TOKEN_REVOKE_FAIL = 'OAUTH_TOKEN_REVOKE_FAIL'; -export const obtainOAuthToken = (params: Record, baseURL?: string) => +export const obtainOAuthToken = (params: Record, baseURL?: string) => (dispatch: AppDispatch) => { dispatch({ type: OAUTH_TOKEN_CREATE_REQUEST, params }); return baseClient(null, baseURL).post('/oauth/token', params).then(({ data: token }) => { diff --git a/app/soapbox/components/ui/textarea/textarea.tsx b/app/soapbox/components/ui/textarea/textarea.tsx index b181fc848..aef6804f6 100644 --- a/app/soapbox/components/ui/textarea/textarea.tsx +++ b/app/soapbox/components/ui/textarea/textarea.tsx @@ -1,7 +1,7 @@ import classNames from 'classnames'; import React from 'react'; -interface ITextarea extends Pick, 'maxLength' | 'onChange' | 'required' | 'disabled' | 'rows'> { +interface ITextarea extends Pick, 'maxLength' | 'onChange' | 'required' | 'disabled' | 'rows' | 'readOnly'> { /** Put the cursor into the input on mount. */ autoFocus?: boolean, /** The initial text in the input. */ diff --git a/app/soapbox/features/developers/apps/create.js b/app/soapbox/features/developers/apps/create.js deleted file mode 100644 index 01187c34f..000000000 --- a/app/soapbox/features/developers/apps/create.js +++ /dev/null @@ -1,231 +0,0 @@ -import { Map as ImmutableMap } from 'immutable'; -import PropTypes from 'prop-types'; -import React from 'react'; -import ImmutablePropTypes from 'react-immutable-proptypes'; -import ImmutablePureComponent from 'react-immutable-pure-component'; -import { injectIntl, FormattedMessage, defineMessages } from 'react-intl'; -import { connect } from 'react-redux'; - -import { createApp } from 'soapbox/actions/apps'; -import { obtainOAuthToken } from 'soapbox/actions/oauth'; -import { Button, Form, FormActions, FormGroup, Input, Stack, Text, Textarea } from 'soapbox/components/ui'; -import Column from 'soapbox/features/ui/components/column'; -import { getBaseURL } from 'soapbox/utils/accounts'; -import { getFeatures } from 'soapbox/utils/features'; - -const messages = defineMessages({ - heading: { id: 'column.app_create', defaultMessage: 'Create app' }, - namePlaceholder: { id: 'app_create.name_placeholder', defaultMessage: 'e.g. \'Soapbox\'' }, - scopesPlaceholder: { id: 'app_create.scopes_placeholder', defaultMessage: 'e.g. \'read write follow\'' }, -}); - -const mapStateToProps = state => { - const me = state.get('me'); - const account = state.getIn(['accounts', me]); - - const instance = state.get('instance'); - const features = getFeatures(instance); - - return { - account, - defaultScopes: features.scopes, - }; -}; - -export default @connect(mapStateToProps) -@injectIntl -class CreateApp extends ImmutablePureComponent { - - static propTypes = { - intl: PropTypes.object.isRequired, - dispatch: PropTypes.func.isRequired, - account: ImmutablePropTypes.record.isRequired, - defaultScopes: PropTypes.string, - } - - initialState = () => { - return { - params: ImmutableMap({ - client_name: '', - redirect_uris: 'urn:ietf:wg:oauth:2.0:oob', - scopes: '', - website: '', - }), - app: null, - token: null, - isLoading: false, - }; - } - - state = this.initialState() - - handleCreateApp = () => { - const { dispatch, account } = this.props; - const { params } = this.state; - const baseURL = getBaseURL(account); - - return dispatch(createApp(params.toJS(), baseURL)) - .then(app => this.setState({ app })); - } - - handleCreateToken = () => { - const { dispatch, account } = this.props; - const { app, params: appParams } = this.state; - const baseURL = getBaseURL(account); - - const tokenParams = { - client_id: app.client_id, - client_secret: app.client_secret, - redirect_uri: appParams.get('redirect_uri'), - grant_type: 'client_credentials', - scope: appParams.get('scopes'), - }; - - return dispatch(obtainOAuthToken(tokenParams, baseURL)) - .then(token => this.setState({ token })); - } - - handleSubmit = e => { - this.setState({ isLoading: true }); - - this.handleCreateApp() - .then(this.handleCreateToken) - .then(() => { - this.scrollToTop(); - this.setState({ isLoading: false }); - }).catch(error => { - console.error(error); - this.setState({ isLoading: false }); - }); - } - - setParam = (key, value) => { - const { params } = this.state; - const newParams = params.set(key, value); - - this.setState({ params: newParams }); - } - - handleParamChange = key => { - return e => { - this.setParam(key, e.target.value); - }; - } - - resetState = () => { - this.setState(this.initialState()); - } - - handleReset = e => { - this.resetState(); - this.scrollToTop(); - } - - scrollToTop = () => { - window.scrollTo({ top: 0, behavior: 'smooth' }); - } - - renderResults = () => { - const { intl } = this.props; - const { app, token } = this.state; - - return ( - -
- - - - - - - - - - }> -