apiNewToken.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import {Component} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import ApiForm from 'sentry/components/forms/apiForm';
  4. import ExternalLink from 'sentry/components/links/externalLink';
  5. import Panel from 'sentry/components/panels/panel';
  6. import PanelBody from 'sentry/components/panels/panelBody';
  7. import PanelHeader from 'sentry/components/panels/panelHeader';
  8. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  9. import {t, tct} from 'sentry/locale';
  10. import {Permissions} from 'sentry/types';
  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. import PermissionSelection from 'sentry/views/settings/organizationDeveloperSettings/permissionSelection';
  15. const API_INDEX_ROUTE = '/settings/account/api/auth-tokens/';
  16. type State = {
  17. permissions: Permissions;
  18. };
  19. export default class ApiNewToken extends Component<{}, State> {
  20. constructor(props: {}) {
  21. super(props);
  22. this.state = {
  23. permissions: {
  24. Event: 'no-access',
  25. Team: 'no-access',
  26. Member: 'no-access',
  27. Project: 'no-access',
  28. Release: 'no-access',
  29. Organization: 'no-access',
  30. },
  31. };
  32. }
  33. onCancel = () => {
  34. browserHistory.push(normalizeUrl(API_INDEX_ROUTE));
  35. };
  36. onSubmitSuccess = () => {
  37. browserHistory.push(normalizeUrl(API_INDEX_ROUTE));
  38. };
  39. render() {
  40. const {permissions} = this.state;
  41. return (
  42. <SentryDocumentTitle title={t('Create User Auth Token')}>
  43. <div>
  44. <SettingsPageHeader title={t('Create New User Auth Token')} />
  45. <TextBlock>
  46. {t(
  47. "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."
  48. )}
  49. </TextBlock>
  50. <TextBlock>
  51. {tct(
  52. 'For more information on how to use the web API, see our [link:documentation].',
  53. {
  54. link: <ExternalLink href="https://docs.sentry.io/api/" />,
  55. }
  56. )}
  57. </TextBlock>
  58. <Panel>
  59. <PanelHeader>{t('Permissions')}</PanelHeader>
  60. <ApiForm
  61. apiMethod="POST"
  62. apiEndpoint="/api-tokens/"
  63. initialData={{scopes: []}}
  64. onSubmitSuccess={this.onSubmitSuccess}
  65. onCancel={this.onCancel}
  66. footerStyle={{
  67. marginTop: 0,
  68. paddingRight: 20,
  69. }}
  70. submitDisabled={Object.values(permissions).every(
  71. value => value === 'no-access'
  72. )}
  73. submitLabel={t('Create Token')}
  74. >
  75. <PanelBody>
  76. <PermissionSelection
  77. appPublished={false}
  78. permissions={permissions}
  79. onChange={value => {
  80. this.setState({permissions: value});
  81. }}
  82. />
  83. </PanelBody>
  84. </ApiForm>
  85. </Panel>
  86. </div>
  87. </SentryDocumentTitle>
  88. );
  89. }
  90. }