import { addErrorMessage, addLoadingMessage, addSuccessMessage, } from 'sentry/actionCreators/indicator'; import {Button} from 'sentry/components/button'; import EmptyMessage from 'sentry/components/emptyMessage'; import LoadingError from 'sentry/components/loadingError'; import LoadingIndicator from 'sentry/components/loadingIndicator'; import Panel from 'sentry/components/panels/panel'; import PanelBody from 'sentry/components/panels/panelBody'; import PanelHeader from 'sentry/components/panels/panelHeader'; import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle'; import {IconAdd} from 'sentry/icons'; import {t} from 'sentry/locale'; import type {RouteComponentProps} from 'sentry/types/legacyReactRouter'; import type {ApiApplication} from 'sentry/types/user'; import {setApiQueryData, useApiQuery, useQueryClient} from 'sentry/utils/queryClient'; import useApi from 'sentry/utils/useApi'; import Row from 'sentry/views/settings/account/apiApplications/row'; import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader'; const ROUTE_PREFIX = '/settings/account/api/'; type Props = RouteComponentProps<{}, {}>; function ApiApplications({router}: Props) { const api = useApi(); const queryClient = useQueryClient(); const ENDPOINT = '/api-applications/'; const { data: appList, isPending, isError, refetch, } = useApiQuery([ENDPOINT], { staleTime: 0, }); if (isPending) { return ; } if (isError) { return ; } const handleCreateApplication = async () => { addLoadingMessage(); try { const app = await api.requestPromise(ENDPOINT, { method: 'POST', }); addSuccessMessage(t('Created a new API Application')); router.push(`${ROUTE_PREFIX}applications/${app.id}/`); } catch { addErrorMessage(t('Unable to remove application. Please try again.')); } }; const handleRemoveApplication = (app: ApiApplication) => { setApiQueryData(queryClient, [ENDPOINT], oldAppList => oldAppList.filter(a => a.id !== app.id) ); }; const isEmpty = appList.length === 0; return ( } > {t('Create New Application')} } /> {t('Application Name')} {!isEmpty ? ( appList.map(app => ( )) ) : ( {t("You haven't created any applications yet.")} )} ); } export default ApiApplications;