useUpdateOrganization.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. import OrganizationStore from 'sentry/stores/organizationStore';
  2. import type {Organization} from 'sentry/types/organization';
  3. import {useMutation, type UseMutationOptions} from 'sentry/utils/queryClient';
  4. import type RequestError from 'sentry/utils/requestError/requestError';
  5. import useApi from 'sentry/utils/useApi';
  6. import useOrganization from 'sentry/utils/useOrganization';
  7. type Variables = Pick<Partial<Organization>, 'targetSampleRate' | 'samplingMode'>;
  8. export function useUpdateOrganization(
  9. options?: Omit<
  10. UseMutationOptions<Organization, RequestError, Variables, unknown>,
  11. 'mutationFn'
  12. >
  13. ) {
  14. const api = useApi();
  15. const organization = useOrganization();
  16. const endpoint = `/organizations/${organization.slug}/`;
  17. return useMutation<Organization, RequestError, Variables>({
  18. ...options,
  19. mutationFn: variables => {
  20. return api.requestPromise(endpoint, {
  21. method: 'PUT',
  22. data: variables,
  23. });
  24. },
  25. onSuccess: (newOrg, variables, context) => {
  26. options?.onSuccess?.(newOrg, variables, context);
  27. OrganizationStore.onUpdate(newOrg);
  28. },
  29. });
  30. }