apiNewToken.tsx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import React from 'react';
  2. import DocumentTitle from 'react-document-title';
  3. import {browserHistory} from 'react-router';
  4. import {Panel, PanelBody, PanelHeader} from 'app/components/panels';
  5. import {API_ACCESS_SCOPES, DEFAULT_API_ACCESS_SCOPES} from 'app/constants';
  6. import {t, tct} from 'app/locale';
  7. import {Choices} from 'app/types';
  8. import ApiForm from 'app/views/settings/components/forms/apiForm';
  9. import MultipleCheckbox from 'app/views/settings/components/forms/controls/multipleCheckbox';
  10. import FormField from 'app/views/settings/components/forms/formField';
  11. import SettingsPageHeader from 'app/views/settings/components/settingsPageHeader';
  12. import TextBlock from 'app/views/settings/components/text/textBlock';
  13. const SORTED_DEFAULT_API_ACCESS_SCOPES = DEFAULT_API_ACCESS_SCOPES.sort();
  14. const API_CHOICES: Choices = API_ACCESS_SCOPES.map(s => [s, s]);
  15. const API_INDEX_ROUTE = '/settings/account/api/auth-tokens/';
  16. export default class ApiNewToken extends React.Component {
  17. onCancel = () => {
  18. browserHistory.push(API_INDEX_ROUTE);
  19. };
  20. onSubmitSuccess = () => {
  21. browserHistory.push(API_INDEX_ROUTE);
  22. };
  23. render() {
  24. return (
  25. <DocumentTitle title="Create API Token - Sentry">
  26. <div>
  27. <SettingsPageHeader title={t('Create New 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: <a href="https://docs.sentry.io/api/" />,
  38. }
  39. )}
  40. </TextBlock>
  41. <Panel>
  42. <PanelHeader>{t('Create New 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. {({value, onChange}) => (
  58. <MultipleCheckbox
  59. onChange={onChange}
  60. value={value}
  61. choices={API_CHOICES}
  62. />
  63. )}
  64. </FormField>
  65. </PanelBody>
  66. </ApiForm>
  67. </Panel>
  68. </div>
  69. </DocumentTitle>
  70. );
  71. }
  72. }