create.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import {browserHistory, RouteComponentProps} from 'react-router';
  2. import styled from '@emotion/styled';
  3. import * as Layout from 'sentry/components/layouts/thirds';
  4. import {t} from 'sentry/locale';
  5. import {Organization} from 'sentry/types';
  6. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  7. import withOrganization from 'sentry/utils/withOrganization';
  8. import AsyncView from 'sentry/views/asyncView';
  9. import MonitorForm from './monitorForm';
  10. import {Monitor} from './types';
  11. type Props = AsyncView['props'] &
  12. RouteComponentProps<{orgId: string}, {}> & {
  13. organization: Organization;
  14. };
  15. class CreateMonitor extends AsyncView<Props, AsyncView['state']> {
  16. getTitle() {
  17. return `Monitors - ${this.orgSlug}`;
  18. }
  19. get orgSlug() {
  20. return this.props.organization.slug;
  21. }
  22. onSubmitSuccess = (data: Monitor) => {
  23. const url = normalizeUrl(`/organizations/${this.orgSlug}/monitors/${data.id}/`);
  24. browserHistory.push(url);
  25. };
  26. renderBody() {
  27. return (
  28. <Layout.Body>
  29. <Layout.Main fullWidth>
  30. <h1>{t('New Monitor')}</h1>
  31. <HelpText>
  32. {t(
  33. `Creating a monitor will allow you to track the executions of a scheduled
  34. job in your organization. For example, ensure a cron job that is
  35. scheduled to run once a day executes and finishes within a specified
  36. duration.`
  37. )}
  38. </HelpText>
  39. <MonitorForm
  40. apiMethod="POST"
  41. apiEndpoint={`/organizations/${this.orgSlug}/monitors/`}
  42. onSubmitSuccess={this.onSubmitSuccess}
  43. submitLabel={t('Next Steps')}
  44. />
  45. </Layout.Main>
  46. </Layout.Body>
  47. );
  48. }
  49. }
  50. export default withOrganization(CreateMonitor);
  51. const HelpText = styled('p')`
  52. color: ${p => p.theme.subText};
  53. max-width: 760px;
  54. `;