apiNewToken.tsx 2.8 KB

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