performance.tsx 983 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import {addErrorMessage} from 'app/actionCreators/indicator';
  2. import {Client} from 'app/api';
  3. import {t} from 'app/locale';
  4. export function toggleKeyTransaction(
  5. api: Client,
  6. isKeyTransaction: boolean,
  7. orgId: string,
  8. projects: number[],
  9. transactionName: string
  10. ): Promise<undefined> {
  11. const promise: Promise<undefined> = api.requestPromise(
  12. `/organizations/${orgId}/key-transactions/`,
  13. {
  14. method: isKeyTransaction ? 'DELETE' : 'POST',
  15. query: {
  16. project: projects.map(id => String(id)),
  17. },
  18. data: {transaction: transactionName},
  19. }
  20. );
  21. promise.catch(response => {
  22. const non_field_errors = response?.responseJSON?.non_field_errors;
  23. if (
  24. Array.isArray(non_field_errors) &&
  25. non_field_errors.length &&
  26. non_field_errors[0]
  27. ) {
  28. addErrorMessage(response.responseJSON.non_field_errors[0]);
  29. } else {
  30. addErrorMessage(t('Unable to update key transaction'));
  31. }
  32. });
  33. return promise;
  34. }