useDeleteDebugIdBundle.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import {
  2. addErrorMessage,
  3. addLoadingMessage,
  4. addSuccessMessage,
  5. } from 'sentry/actionCreators/indicator';
  6. import {t} from 'sentry/locale';
  7. import {useMutation, UseMutationOptions} from 'sentry/utils/queryClient';
  8. import RequestError from 'sentry/utils/requestError/requestError';
  9. import useApi from 'sentry/utils/useApi';
  10. import useOrganization from 'sentry/utils/useOrganization';
  11. interface DeleteDebugIdArtifactsVariables {
  12. bundleId: string;
  13. projectSlug: string;
  14. }
  15. export function useDeleteDebugIdBundle(
  16. options: Omit<
  17. UseMutationOptions<unknown, RequestError, DeleteDebugIdArtifactsVariables>,
  18. 'mutationFn'
  19. > = {}
  20. ) {
  21. const api = useApi();
  22. const organization = useOrganization();
  23. return useMutation<unknown, RequestError, DeleteDebugIdArtifactsVariables>({
  24. ...options,
  25. mutationFn: ({projectSlug, bundleId}: DeleteDebugIdArtifactsVariables) => {
  26. const debugIdBundlesEndpoint = `/projects/${organization.slug}/${projectSlug}/files/artifact-bundles/`;
  27. return api.requestPromise(debugIdBundlesEndpoint, {
  28. method: 'DELETE',
  29. query: {bundleId},
  30. });
  31. },
  32. onMutate: (...args) => {
  33. addLoadingMessage(t('Deleting bundle\u2026'));
  34. options.onMutate?.(...args);
  35. },
  36. onSuccess: (...args) => {
  37. addSuccessMessage(t('Bundle deleted.'));
  38. options.onSuccess?.(...args);
  39. },
  40. onError: (...args) => {
  41. addErrorMessage(t('Unable to delete bundle. Please try again.'));
  42. options.onError?.(...args);
  43. },
  44. });
  45. }