create.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import {Fragment} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import Breadcrumbs from 'sentry/components/breadcrumbs';
  4. import FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
  5. import * as Layout from 'sentry/components/layouts/thirds';
  6. import {t} from 'sentry/locale';
  7. import useOrganization from 'sentry/utils/useOrganization';
  8. import usePageFilters from 'sentry/utils/usePageFilters';
  9. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  10. import MonitorForm from './components/monitorForm';
  11. import {Monitor} from './types';
  12. function CreateMonitor() {
  13. const {slug: orgSlug} = useOrganization();
  14. const {selection} = usePageFilters();
  15. function onSubmitSuccess(data: Monitor) {
  16. const endpointOptions = {
  17. query: {
  18. project: selection.projects,
  19. environment: selection.environments,
  20. },
  21. };
  22. browserHistory.push(
  23. normalizeUrl({
  24. pathname: `/organizations/${orgSlug}/crons/${data.slug}/`,
  25. query: endpointOptions.query,
  26. })
  27. );
  28. }
  29. return (
  30. <Fragment>
  31. <Layout.Header>
  32. <Layout.HeaderContent>
  33. <Breadcrumbs
  34. crumbs={[
  35. {
  36. label: t('Crons'),
  37. to: `/organizations/${orgSlug}/crons/`,
  38. },
  39. {
  40. label: t('Add Monitor'),
  41. },
  42. ]}
  43. />
  44. <Layout.Title>{t('Add Monitor')}</Layout.Title>
  45. </Layout.HeaderContent>
  46. <Layout.HeaderActions>
  47. <FeedbackWidgetButton />
  48. </Layout.HeaderActions>
  49. </Layout.Header>
  50. <Layout.Body>
  51. <Layout.Main fullWidth>
  52. <MonitorForm
  53. apiMethod="POST"
  54. apiEndpoint={`/organizations/${orgSlug}/monitors/`}
  55. onSubmitSuccess={onSubmitSuccess}
  56. submitLabel={t('Next')}
  57. />
  58. </Layout.Main>
  59. </Layout.Body>
  60. </Fragment>
  61. );
  62. }
  63. export default CreateMonitor;