monitors.tsx 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import {
  2. addErrorMessage,
  3. addLoadingMessage,
  4. clearIndicators,
  5. } from 'sentry/actionCreators/indicator';
  6. import {Client} from 'sentry/api';
  7. import {t} from 'sentry/locale';
  8. import {logException} from 'sentry/utils/logging';
  9. import {Monitor} from 'sentry/views/monitors/types';
  10. export async function deleteMonitor(api: Client, orgId: string, monitorId: string) {
  11. addLoadingMessage(t('Deleting Monitor...'));
  12. try {
  13. await api.requestPromise(`/organizations/${orgId}/monitors/${monitorId}/`, {
  14. method: 'DELETE',
  15. });
  16. clearIndicators();
  17. } catch {
  18. addErrorMessage(t('Unable to remove monitor.'));
  19. }
  20. }
  21. export async function updateMonitor(
  22. api: Client,
  23. orgId: string,
  24. monitorId: string,
  25. data: Partial<Monitor>
  26. ) {
  27. addLoadingMessage();
  28. try {
  29. const resp = await api.requestPromise(
  30. `/organizations/${orgId}/monitors/${monitorId}/`,
  31. {method: 'PUT', data}
  32. );
  33. clearIndicators();
  34. return resp;
  35. } catch (err) {
  36. logException(err);
  37. addErrorMessage(t('Unable to update monitor.'));
  38. }
  39. return null;
  40. }