Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {Component} from 'react';
import {useState} from 'react';

import {addSuccessMessage} from 'sentry/actionCreators/indicator';
import Form from 'sentry/components/forms/form';
import JsonForm from 'sentry/components/forms/jsonForm';
import type {Field} from 'sentry/components/forms/types';
import {t} from 'sentry/locale';
import type {Integration} from 'sentry/types/integrations';
import type {Organization} from 'sentry/types/organization';
Expand All @@ -14,63 +13,46 @@ type Props = {
organization: Organization;
};

type State = {
integration: Integration;
};

class IntegrationMainSettings extends Component<Props, State> {
state: State = {
integration: this.props.integration,
};

handleSubmitSuccess = (data: Integration) => {
addSuccessMessage(t('Integration updated.'));
this.props.onUpdate();
this.setState({integration: data});
};

get initialData() {
const {integration} = this.props;

return {
name: integration.name,
domain: integration.domainName || '',
};
}

get formFields(): Field[] {
const fields: any[] = [
{
name: 'name',
type: 'string',
required: false,
label: t('Integration Name'),
},
{
name: 'domain',
type: 'string',
required: false,
label: t('Full URL'),
},
];
return fields;
}

render() {
const {integration} = this.state;
const {organization} = this.props;
return (
<Form
initialData={this.initialData}
apiMethod="PUT"
apiEndpoint={`/organizations/${organization.slug}/integrations/${integration.id}/`}
onSubmitSuccess={this.handleSubmitSuccess}
submitLabel={t('Save Settings')}
>
<JsonForm fields={this.formFields} />
</Form>
);
}
function IntegrationMainSettings({
integration: integrationInitial,
organization,
onUpdate,
}: Props) {
const [integration, setIntegration] = useState(integrationInitial);

return (
<Form
initialData={{
name: integration.name,
domain: integration.domainName || '',
}}
apiMethod="PUT"
apiEndpoint={`/organizations/${organization.slug}/integrations/${integration.id}/`}
onSubmitSuccess={data => {
addSuccessMessage(t('Integration updated.'));
onUpdate();
setIntegration(data);
}}
submitLabel={t('Save Settings')}
>
<JsonForm
fields={[
{
name: 'name',
type: 'string',
required: false,
label: t('Integration Name'),
},
{
name: 'domain',
type: 'string',
required: false,
label: t('Full URL'),
},
]}
/>
</Form>
);
}

export default IntegrationMainSettings;
Loading