useDeleteDebugIdBundle.ts 1.5 KB

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