accounts-frontend/packages/app/pages/dev/CreateNewApplicationPage.tsx

69 lines
1.7 KiB
TypeScript
Raw Normal View History

import React, { Component } from 'react';
import { FormModel } from 'app/components/ui/form';
import ApplicationForm from 'app/components/dev/apps/applicationForm/ApplicationForm';
import oauth from 'app/services/api/oauth';
import { browserHistory } from 'app/services/history';
import { OauthAppResponse } from 'app/services/api/oauth';
import { ApplicationType } from 'app/components/dev/apps';
const app: OauthAppResponse = {
2020-05-24 04:38:24 +05:30
clientId: '',
clientSecret: '',
countUsers: 0,
createdAt: 0,
type: 'application',
name: '',
description: '',
websiteUrl: '',
redirectUri: '',
minecraftServerIp: '',
};
2019-12-07 16:58:52 +05:30
interface State {
2020-05-24 04:38:24 +05:30
type: ApplicationType | null;
2019-12-07 16:58:52 +05:30
}
export default class CreateNewApplicationPage extends Component<{}, State> {
2020-05-24 04:38:24 +05:30
state: State = {
type: null,
};
2020-05-24 04:38:24 +05:30
form: FormModel = new FormModel();
2020-05-24 04:38:24 +05:30
render() {
return (
<ApplicationForm
form={this.form}
displayTypeSwitcher
onSubmit={this.onSubmit}
type={this.state.type}
setType={this.setType}
app={app}
/>
);
}
2020-05-24 04:38:24 +05:30
onSubmit = async () => {
const { form } = this;
const { type } = this.state;
2018-05-05 14:31:25 +05:30
2020-05-24 04:38:24 +05:30
if (!type) {
throw new Error('Form was submitted without specified type');
}
2020-05-24 04:38:24 +05:30
form.beginLoading();
const result = await oauth.create(type, form.serialize());
form.endLoading();
2020-05-24 04:38:24 +05:30
this.goToMainPage(result.data.clientId);
};
2020-05-24 04:38:24 +05:30
setType = (type: ApplicationType) => {
this.setState({
type,
});
};
2020-05-24 04:38:24 +05:30
goToMainPage = (hash?: string) => browserHistory.push(`/dev/applications${hash ? `#${hash}` : ''}`);
}