useSentryAppComponentsData.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import {useEffect} from 'react';
  2. import SentryAppComponentsStore from 'sentry/stores/sentryAppComponentsStore';
  3. import SentryAppInstallationStore from 'sentry/stores/sentryAppInstallationsStore';
  4. import type {SentryAppComponent, SentryAppInstallation} from 'sentry/types';
  5. import {useApiQuery} from 'sentry/utils/queryClient';
  6. import useOrganization from 'sentry/utils/useOrganization';
  7. interface Props {
  8. projectId: string;
  9. }
  10. export default function useSentryAppComponentsData({projectId}: Props) {
  11. const organization = useOrganization();
  12. const {data: installs} = useApiQuery<SentryAppInstallation[]>(
  13. [`/organizations/${organization.slug}/sentry-app-installations/`],
  14. {staleTime: Infinity}
  15. );
  16. useEffect(() => {
  17. if (installs) {
  18. SentryAppInstallationStore.load(installs);
  19. }
  20. }, [installs]);
  21. const {data: components} = useApiQuery<SentryAppComponent[]>(
  22. [`/organizations/${organization.slug}/sentry-app-components/`, {query: {projectId}}],
  23. {enabled: Boolean(projectId), staleTime: Infinity}
  24. );
  25. useEffect(() => {
  26. if (components) {
  27. SentryAppComponentsStore.loadComponents(components);
  28. }
  29. }, [components]);
  30. }