useFetchTempestCredentials.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import type {Organization} from 'sentry/types/organization';
  2. import type {Project} from 'sentry/types/project';
  3. import {useApiQuery, useQueryClient} from 'sentry/utils/queryClient';
  4. import type {TempestCredentials} from '../types';
  5. const makeFetchTempestCredentialsQueryKey = ({
  6. orgSlug,
  7. projectSlug,
  8. }: {
  9. orgSlug: string;
  10. projectSlug: string;
  11. }) => [`/projects/${orgSlug}/${projectSlug}/tempest-credentials/`] as const;
  12. export function useFetchTempestCredentials(organization: Organization, project: Project) {
  13. const tempestCredentialsQuery = useApiQuery<TempestCredentials[]>(
  14. makeFetchTempestCredentialsQueryKey({
  15. orgSlug: organization.slug,
  16. projectSlug: project.slug,
  17. }),
  18. {staleTime: Infinity}
  19. );
  20. const queryClient = useQueryClient();
  21. const invalidateCredentialsCache = () => {
  22. queryClient.invalidateQueries({
  23. queryKey: makeFetchTempestCredentialsQueryKey({
  24. orgSlug: organization.slug,
  25. projectSlug: project.slug,
  26. }),
  27. });
  28. };
  29. return {
  30. ...tempestCredentialsQuery,
  31. invalidateCredentialsCache,
  32. };
  33. }