organizationContainer.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import styled from '@emotion/styled';
  2. import {Alert} from 'sentry/components/alert';
  3. import LoadingError from 'sentry/components/loadingError';
  4. import LoadingTriangle from 'sentry/components/loadingTriangle';
  5. import {ORGANIZATION_FETCH_ERROR_TYPES} from 'sentry/constants';
  6. import {t} from 'sentry/locale';
  7. import OrganizationStore from 'sentry/stores/organizationStore';
  8. import {useLegacyStore} from 'sentry/stores/useLegacyStore';
  9. import {space} from 'sentry/styles/space';
  10. import {useEnsureOrganization} from './organizationContext';
  11. interface Props {
  12. children: JSX.Element;
  13. }
  14. /**
  15. * Ensures the current organization is loaded. A loading indicator will be
  16. * rendered while loading the organization.
  17. */
  18. function OrganizationContainer({children}: Props) {
  19. const {loading, error, errorType} = useLegacyStore(OrganizationStore);
  20. useEnsureOrganization();
  21. if (loading) {
  22. return <LoadingTriangle>{t('Loading data for your organization.')}</LoadingTriangle>;
  23. }
  24. if (error) {
  25. const errorBody =
  26. errorType === ORGANIZATION_FETCH_ERROR_TYPES.ORG_NO_ACCESS ? (
  27. <Alert type="error" data-test-id="org-access-error">
  28. {t('You do not have access to this organization.')}
  29. </Alert>
  30. ) : errorType === ORGANIZATION_FETCH_ERROR_TYPES.ORG_NOT_FOUND ? (
  31. <Alert type="error" data-test-id="org-loading-error">
  32. {t('The organization you were looking for was not found.')}
  33. </Alert>
  34. ) : (
  35. <LoadingError />
  36. );
  37. return <ErrorWrapper>{errorBody}</ErrorWrapper>;
  38. }
  39. return children;
  40. }
  41. const ErrorWrapper = styled('div')`
  42. padding: ${space(3)};
  43. `;
  44. export default OrganizationContainer;