apiNewToken.tsx 3.0 KB

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