organizationCreate.tsx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import {addErrorMessage} from 'sentry/actionCreators/indicator';
  2. import {ApiForm, CheckboxField, TextField} from 'sentry/components/forms';
  3. import NarrowLayout from 'sentry/components/narrowLayout';
  4. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  5. import {t, tct} from 'sentry/locale';
  6. import ConfigStore from 'sentry/stores/configStore';
  7. import {OrganizationSummary} from 'sentry/types';
  8. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  9. function OrganizationCreate() {
  10. const termsUrl = ConfigStore.get('termsUrl');
  11. const privacyUrl = ConfigStore.get('privacyUrl');
  12. return (
  13. <SentryDocumentTitle title={t('Create Organization')}>
  14. <NarrowLayout showLogout>
  15. <h3>{t('Create a New Organization')}</h3>
  16. <p>
  17. {t(
  18. "Organizations represent the top level in your hierarchy. You'll be able to bundle a collection of teams within an organization as well as give organization-wide permissions to users."
  19. )}
  20. </p>
  21. <ApiForm
  22. initialData={{defaultTeam: true}}
  23. submitLabel={t('Create Organization')}
  24. apiEndpoint="/organizations/"
  25. apiMethod="POST"
  26. onSubmitSuccess={(createdOrg: OrganizationSummary) => {
  27. const hasCustomerDomain = createdOrg?.features.includes('customer-domains');
  28. let nextUrl = normalizeUrl(
  29. `/organizations/${createdOrg.slug}/projects/new/`,
  30. {forceCustomerDomain: hasCustomerDomain}
  31. );
  32. if (hasCustomerDomain) {
  33. nextUrl = `${createdOrg.links.organizationUrl}${nextUrl}`;
  34. }
  35. // redirect to project creation *(BYPASS REACT ROUTER AND FORCE PAGE REFRESH TO GRAB CSRF TOKEN)*
  36. // browserHistory.pushState(null, `/organizations/${data.slug}/projects/new/`);
  37. window.location.assign(nextUrl);
  38. }}
  39. onSubmitError={error => {
  40. addErrorMessage(
  41. error.responseJSON?.detail ?? t('Unable to create organization.')
  42. );
  43. }}
  44. requireChanges
  45. >
  46. <TextField
  47. id="organization-name"
  48. name="name"
  49. label={t('Organization Name')}
  50. placeholder={t('e.g. My Company')}
  51. inline={false}
  52. flexibleControlStateSize
  53. stacked
  54. required
  55. />
  56. {termsUrl && privacyUrl && (
  57. <CheckboxField
  58. name="agreeTerms"
  59. label={tct(
  60. 'I agree to the [termsLink:Terms of Service] and the [privacyLink:Privacy Policy]',
  61. {
  62. termsLink: <a href={termsUrl} />,
  63. privacyLink: <a href={privacyUrl} />,
  64. }
  65. )}
  66. inline={false}
  67. stacked
  68. required
  69. />
  70. )}
  71. </ApiForm>
  72. </NarrowLayout>
  73. </SentryDocumentTitle>
  74. );
  75. }
  76. export default OrganizationCreate;