import { addErrorMessage, addLoadingMessage, addSuccessMessage, } from 'sentry/actionCreators/indicator'; import FieldGroup from 'sentry/components/forms/fieldGroup'; import TextField from 'sentry/components/forms/fields/textField'; import Form from 'sentry/components/forms/form'; import ExternalLink from 'sentry/components/links/externalLink'; 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 {t, tct} from 'sentry/locale'; import type {InternalAppApiToken} from 'sentry/types/user'; import {browserHistory} from 'sentry/utils/browserHistory'; import {handleXhrErrorResponse} from 'sentry/utils/handleXhrErrorResponse'; import {useApiQuery} from 'sentry/utils/queryClient'; import normalizeUrl from 'sentry/utils/url/normalizeUrl'; import useMutateApiToken from 'sentry/utils/useMutateApiToken'; import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader'; import TextBlock from 'sentry/views/settings/components/text/textBlock'; import {tokenPreview} from 'sentry/views/settings/organizationAuthTokens'; const API_INDEX_ROUTE = '/settings/account/api/auth-tokens/'; type Props = { params: {tokenId: string}; }; type FetchApiTokenParameters = { tokenId: string; }; type FetchApiTokenResponse = InternalAppApiToken; export const makeFetchApiTokenKey = ({tokenId}: FetchApiTokenParameters) => [`/api-tokens/${tokenId}/`] as const; function ApiTokenDetailsForm({token}: {token: InternalAppApiToken}) { const initialData = { name: token.name, tokenPreview: tokenPreview(token.tokenLastCharacters || '****'), }; const handleGoBack = () => { browserHistory.push(normalizeUrl(API_INDEX_ROUTE)); }; const onSuccess = () => { addSuccessMessage(t('Updated user auth token.')); handleGoBack(); }; const onError = error => { const message = t('Failed to update the user auth token.'); handleXhrErrorResponse(message, error); addErrorMessage(message); }; const {mutate: submitToken} = useMutateApiToken({ token: token, onSuccess: onSuccess, onError: onError, }); return (
); } export function ApiTokenDetails({params}: Props) { const {tokenId} = params; const { isLoading, isError, data: token, refetch: refetchToken, } = useApiQuery