apiNewToken.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import {Component} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import ApiForm from 'sentry/components/forms/apiForm';
  4. import MultipleCheckbox from 'sentry/components/forms/controls/multipleCheckbox';
  5. import FormField from 'sentry/components/forms/formField';
  6. import ExternalLink from 'sentry/components/links/externalLink';
  7. import Panel from 'sentry/components/panels/panel';
  8. import PanelBody from 'sentry/components/panels/panelBody';
  9. import PanelHeader from 'sentry/components/panels/panelHeader';
  10. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  11. import {API_ACCESS_SCOPES, DEFAULT_API_ACCESS_SCOPES} from 'sentry/constants';
  12. import {t, tct} from 'sentry/locale';
  13. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  14. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  15. import TextBlock from 'sentry/views/settings/components/text/textBlock';
  16. const SORTED_DEFAULT_API_ACCESS_SCOPES = DEFAULT_API_ACCESS_SCOPES.sort();
  17. const API_INDEX_ROUTE = '/settings/account/api/auth-tokens/';
  18. export default class ApiNewToken extends Component {
  19. onCancel = () => {
  20. browserHistory.push(normalizeUrl(API_INDEX_ROUTE));
  21. };
  22. onSubmitSuccess = () => {
  23. browserHistory.push(normalizeUrl(API_INDEX_ROUTE));
  24. };
  25. render() {
  26. return (
  27. <SentryDocumentTitle title={t('Create User Auth Token')}>
  28. <div>
  29. <SettingsPageHeader title={t('Create New User Auth Token')} />
  30. <TextBlock>
  31. {t(
  32. "Authentication tokens allow you to perform actions against the Sentry API on behalf of your account. They're the easiest way to get started using the API."
  33. )}
  34. </TextBlock>
  35. <TextBlock>
  36. {tct(
  37. 'For more information on how to use the web API, see our [link:documentation].',
  38. {
  39. link: <ExternalLink href="https://docs.sentry.io/api/" />,
  40. }
  41. )}
  42. </TextBlock>
  43. <Panel>
  44. <PanelHeader>{t('Create New User Auth Token')}</PanelHeader>
  45. <ApiForm
  46. apiMethod="POST"
  47. apiEndpoint="/api-tokens/"
  48. initialData={{scopes: SORTED_DEFAULT_API_ACCESS_SCOPES}}
  49. onSubmitSuccess={this.onSubmitSuccess}
  50. onCancel={this.onCancel}
  51. footerStyle={{
  52. marginTop: 0,
  53. paddingRight: 20,
  54. }}
  55. submitLabel={t('Create Token')}
  56. >
  57. <PanelBody>
  58. <FormField name="scopes" label={t('Scopes')} inline={false} required>
  59. {({name, value, onChange}) => (
  60. <MultipleCheckbox onChange={onChange} value={value} name={name}>
  61. {API_ACCESS_SCOPES.map(scope => (
  62. <MultipleCheckbox.Item value={scope} key={scope}>
  63. {scope}
  64. </MultipleCheckbox.Item>
  65. ))}
  66. </MultipleCheckbox>
  67. )}
  68. </FormField>
  69. </PanelBody>
  70. </ApiForm>
  71. </Panel>
  72. </div>
  73. </SentryDocumentTitle>
  74. );
  75. }
  76. }